@@ -24,15 +24,12 @@ declare_clippy_lint! {
24
24
///
25
25
/// ### Example
26
26
/// ```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);
32
29
/// ```
33
30
/// Use instead:
34
31
/// ```rust
35
- /// Vec::with_capacity(space_hint)
32
+ /// let mut v: Vec<usize> = Vec ::with_capacity(10);
36
33
/// ```
37
34
#[ clippy:: version = "1.73.0" ]
38
35
pub RESERVE_AFTER_INITIALIZATION ,
@@ -41,37 +38,6 @@ declare_clippy_lint! {
41
38
}
42
39
impl_lint_pass ! ( ReserveAfterInitialization => [ RESERVE_AFTER_INITIALIZATION ] ) ;
43
40
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
-
75
41
#[ derive( Default ) ]
76
42
pub struct ReserveAfterInitialization {
77
43
searcher : Option < VecReserveSearcher > ,
0 commit comments