Skip to content

Commit

Permalink
Auto merge of rust-lang#10702 - blyxyas:fix-let_underscore_untyped_he…
Browse files Browse the repository at this point in the history
…lp_message, r=Manishearth

Improve the help message + add a help span

This would close rust-lang#10410, because it applies the general consensus achieved in that issue (that replacing `let _ = ...` to `_ = ...` doesn't present any benefits).

I also added a little help message span.

changelog:[`let_underscore_untyped`]: Fix the help message confusion + add a help message span.
  • Loading branch information
bors committed Apr 24, 2023
2 parents 30db6ed + acf50a7 commit c4f2c48
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
10 changes: 8 additions & 2 deletions clippy_lints/src/let_underscore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::subst::GenericArgKind;
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::{BytePos, Span};

declare_clippy_lint! {
/// ### What it does
Expand Down Expand Up @@ -205,8 +206,13 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
LET_UNDERSCORE_UNTYPED,
local.span,
"non-binding `let` without a type annotation",
None,
"consider adding a type annotation or removing the `let` keyword",
Some(
Span::new(local.pat.span.hi(),
local.pat.span.hi() + BytePos(1),
local.pat.span.ctxt(),
local.pat.span.parent()
)),
"consider adding a type annotation",
);
}
}
Expand Down
30 changes: 25 additions & 5 deletions tests/ui/let_underscore_untyped.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ error: non-binding `let` without a type annotation
LL | let _ = a();
| ^^^^^^^^^^^^
|
= help: consider adding a type annotation or removing the `let` keyword
help: consider adding a type annotation
--> $DIR/let_underscore_untyped.rs:36:10
|
LL | let _ = a();
| ^
= note: `-D clippy::let-underscore-untyped` implied by `-D warnings`

error: non-binding `let` without a type annotation
Expand All @@ -13,31 +17,47 @@ error: non-binding `let` without a type annotation
LL | let _ = b(1);
| ^^^^^^^^^^^^^
|
= help: consider adding a type annotation or removing the `let` keyword
help: consider adding a type annotation
--> $DIR/let_underscore_untyped.rs:37:10
|
LL | let _ = b(1);
| ^

error: non-binding `let` without a type annotation
--> $DIR/let_underscore_untyped.rs:39:5
|
LL | let _ = d(&1);
| ^^^^^^^^^^^^^^
|
= help: consider adding a type annotation or removing the `let` keyword
help: consider adding a type annotation
--> $DIR/let_underscore_untyped.rs:39:10
|
LL | let _ = d(&1);
| ^

error: non-binding `let` without a type annotation
--> $DIR/let_underscore_untyped.rs:40:5
|
LL | let _ = e();
| ^^^^^^^^^^^^
|
= help: consider adding a type annotation or removing the `let` keyword
help: consider adding a type annotation
--> $DIR/let_underscore_untyped.rs:40:10
|
LL | let _ = e();
| ^

error: non-binding `let` without a type annotation
--> $DIR/let_underscore_untyped.rs:41:5
|
LL | let _ = f();
| ^^^^^^^^^^^^
|
= help: consider adding a type annotation or removing the `let` keyword
help: consider adding a type annotation
--> $DIR/let_underscore_untyped.rs:41:10
|
LL | let _ = f();
| ^

error: aborting due to 5 previous errors

0 comments on commit c4f2c48

Please sign in to comment.