Skip to content

Commit

Permalink
use span_lint_and_then
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoto7250 committed Jul 10, 2022
1 parent 945c523 commit cee302a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
13 changes: 11 additions & 2 deletions clippy_lints/src/unnecessary_reserve.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use clippy_utils::diagnostics::span_lint;
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::{match_def_path, meets_msrv, msrvs, paths, visitors::expr_visitor_no_bodies};
use rustc_errors::Applicability;
use rustc_hir::{intravisit::Visitor, Block, ExprKind, QPath, StmtKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty;
Expand Down Expand Up @@ -60,11 +61,19 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryReserve {
&& let Some(next_stmt_span) = check_extend_method(cx, block, idx, struct_calling_on)
&& !next_stmt_span.from_expansion()
{
span_lint(
span_lint_and_then(
cx,
UNNECESSARY_RESERVE,
next_stmt_span,
"this `reserve` no longer makes sense in rustc version >= 1.62",
|diag| {
diag.span_suggestion(
semi_expr.span,
"remove this line",
String::new(),
Applicability::MaybeIncorrect,
);
}
);
}
}
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/unnecessary_reserve.stderr
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
error: this `reserve` no longer makes sense in rustc version >= 1.62
--> $DIR/unnecessary_reserve.rs:20:5
|
LL | vec.reserve(1);
| -------------- help: remove this line
LL | vec.extend([1]);
| ^^^^^^^^^^^^^^^^
|
Expand All @@ -9,30 +11,40 @@ LL | vec.extend([1]);
error: this `reserve` no longer makes sense in rustc version >= 1.62
--> $DIR/unnecessary_reserve.rs:24:5
|
LL | vec.reserve(array.len());
| ------------------------ help: remove this line
LL | vec.extend(array);
| ^^^^^^^^^^^^^^^^^^

error: this `reserve` no longer makes sense in rustc version >= 1.62
--> $DIR/unnecessary_reserve.rs:29:9
|
LL | vec.reserve(1);
| -------------- help: remove this line
LL | vec.extend([1])
| ^^^^^^^^^^^^^^^

error: this `reserve` no longer makes sense in rustc version >= 1.62
--> $DIR/unnecessary_reserve.rs:49:5
|
LL | vec_deque.reserve(1);
| -------------------- help: remove this line
LL | vec_deque.extend([1]);
| ^^^^^^^^^^^^^^^^^^^^^^

error: this `reserve` no longer makes sense in rustc version >= 1.62
--> $DIR/unnecessary_reserve.rs:53:5
|
LL | vec_deque.reserve(array.len());
| ------------------------------ help: remove this line
LL | vec_deque.extend(array);
| ^^^^^^^^^^^^^^^^^^^^^^^^

error: this `reserve` no longer makes sense in rustc version >= 1.62
--> $DIR/unnecessary_reserve.rs:58:9
|
LL | vec_deque.reserve(1);
| -------------------- help: remove this line
LL | vec_deque.extend([1])
| ^^^^^^^^^^^^^^^^^^^^^

Expand Down

0 comments on commit cee302a

Please sign in to comment.