From 073149a7ef483b8feddacc865e935d6019272e14 Mon Sep 17 00:00:00 2001 From: Red Rapious Date: Mon, 21 Aug 2023 19:21:02 +0200 Subject: [PATCH] Changed documentation example and removed comments --- .../src/reserve_after_initialization.rs | 40 ++----------------- 1 file changed, 3 insertions(+), 37 deletions(-) diff --git a/clippy_lints/src/reserve_after_initialization.rs b/clippy_lints/src/reserve_after_initialization.rs index 073f810048c1..6a2bbd0af852 100644 --- a/clippy_lints/src/reserve_after_initialization.rs +++ b/clippy_lints/src/reserve_after_initialization.rs @@ -24,15 +24,12 @@ declare_clippy_lint! { /// /// ### Example /// ```rust - /// { - /// let mut v = vec![]; - /// v.reserve(space_hint); - /// v - /// } + /// let mut v: Vec = vec![]; + /// v.reserve(10); /// ``` /// Use instead: /// ```rust - /// Vec::with_capacity(space_hint) + /// let mut v: Vec = Vec::with_capacity(10); /// ``` #[clippy::version = "1.73.0"] pub RESERVE_AFTER_INITIALIZATION, @@ -41,37 +38,6 @@ declare_clippy_lint! { } impl_lint_pass!(ReserveAfterInitialization => [RESERVE_AFTER_INITIALIZATION]); -/*impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx rustc_hir::Expr<'_>) { - if let ExprKind::Assign(left, right, _) = expr.kind - && let ExprKind::Path(QPath::Resolved(None, path)) = left.kind - && let [name] = &path.segments - && let Res::Local(id) = path.res - && let Some(init) = get_vec_init_kind(cx, right) - && !matches!(init, VecInitKind::WithExprCapacity(_)) { - span_lint_and_help( - cx, - RESERVE_AFTER_INITIALIZATION, - expr.span, - "`reserve` called just after the initialisation of the vector", - None, - "use `Vec::with_capacity(space_hint)` instead" - ); - } - } - - /*fn check_block(&mut self, cx: &LateContext<'_>, block: &'_ rustc_hir::Block<'_>) { - span_lint_and_help( - cx, - RESERVE_AFTER_INITIALIZATION, - block.span, - "`reserve` called just after the initialisation of the vector", - None, - "use `Vec::with_capacity(space_hint)` instead" - ); - }*/ -}*/ - #[derive(Default)] pub struct ReserveAfterInitialization { searcher: Option,