Skip to content

Commit 073149a

Browse files
committed
Changed documentation example and removed comments
1 parent e33a17e commit 073149a

File tree

1 file changed

+3
-37
lines changed

1 file changed

+3
-37
lines changed

clippy_lints/src/reserve_after_initialization.rs

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,12 @@ declare_clippy_lint! {
2424
///
2525
/// ### Example
2626
/// ```rust
27-
/// {
28-
/// let mut v = vec![];
29-
/// v.reserve(space_hint);
30-
/// v
31-
/// }
27+
/// let mut v: Vec<usize> = vec![];
28+
/// v.reserve(10);
3229
/// ```
3330
/// Use instead:
3431
/// ```rust
35-
/// Vec::with_capacity(space_hint)
32+
/// let mut v: Vec<usize> = Vec::with_capacity(10);
3633
/// ```
3734
#[clippy::version = "1.73.0"]
3835
pub RESERVE_AFTER_INITIALIZATION,
@@ -41,37 +38,6 @@ declare_clippy_lint! {
4138
}
4239
impl_lint_pass!(ReserveAfterInitialization => [RESERVE_AFTER_INITIALIZATION]);
4340

44-
/*impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization {
45-
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx rustc_hir::Expr<'_>) {
46-
if let ExprKind::Assign(left, right, _) = expr.kind
47-
&& let ExprKind::Path(QPath::Resolved(None, path)) = left.kind
48-
&& let [name] = &path.segments
49-
&& let Res::Local(id) = path.res
50-
&& let Some(init) = get_vec_init_kind(cx, right)
51-
&& !matches!(init, VecInitKind::WithExprCapacity(_)) {
52-
span_lint_and_help(
53-
cx,
54-
RESERVE_AFTER_INITIALIZATION,
55-
expr.span,
56-
"`reserve` called just after the initialisation of the vector",
57-
None,
58-
"use `Vec::with_capacity(space_hint)` instead"
59-
);
60-
}
61-
}
62-
63-
/*fn check_block(&mut self, cx: &LateContext<'_>, block: &'_ rustc_hir::Block<'_>) {
64-
span_lint_and_help(
65-
cx,
66-
RESERVE_AFTER_INITIALIZATION,
67-
block.span,
68-
"`reserve` called just after the initialisation of the vector",
69-
None,
70-
"use `Vec::with_capacity(space_hint)` instead"
71-
);
72-
}*/
73-
}*/
74-
7541
#[derive(Default)]
7642
pub struct ReserveAfterInitialization {
7743
searcher: Option<VecReserveSearcher>,

0 commit comments

Comments
 (0)