Skip to content

Commit c4f2c48

Browse files
committed
Auto merge of #10702 - blyxyas:fix-let_underscore_untyped_help_message, r=Manishearth
Improve the help message + add a help span This would close #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.
2 parents 30db6ed + acf50a7 commit c4f2c48

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

clippy_lints/src/let_underscore.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_lint::{LateContext, LateLintPass};
66
use rustc_middle::lint::in_external_macro;
77
use rustc_middle::ty::subst::GenericArgKind;
88
use rustc_session::{declare_lint_pass, declare_tool_lint};
9+
use rustc_span::{BytePos, Span};
910

1011
declare_clippy_lint! {
1112
/// ### What it does
@@ -205,8 +206,13 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
205206
LET_UNDERSCORE_UNTYPED,
206207
local.span,
207208
"non-binding `let` without a type annotation",
208-
None,
209-
"consider adding a type annotation or removing the `let` keyword",
209+
Some(
210+
Span::new(local.pat.span.hi(),
211+
local.pat.span.hi() + BytePos(1),
212+
local.pat.span.ctxt(),
213+
local.pat.span.parent()
214+
)),
215+
"consider adding a type annotation",
210216
);
211217
}
212218
}

tests/ui/let_underscore_untyped.stderr

+25-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ error: non-binding `let` without a type annotation
44
LL | let _ = a();
55
| ^^^^^^^^^^^^
66
|
7-
= help: consider adding a type annotation or removing the `let` keyword
7+
help: consider adding a type annotation
8+
--> $DIR/let_underscore_untyped.rs:36:10
9+
|
10+
LL | let _ = a();
11+
| ^
812
= note: `-D clippy::let-underscore-untyped` implied by `-D warnings`
913

1014
error: non-binding `let` without a type annotation
@@ -13,31 +17,47 @@ error: non-binding `let` without a type annotation
1317
LL | let _ = b(1);
1418
| ^^^^^^^^^^^^^
1519
|
16-
= help: consider adding a type annotation or removing the `let` keyword
20+
help: consider adding a type annotation
21+
--> $DIR/let_underscore_untyped.rs:37:10
22+
|
23+
LL | let _ = b(1);
24+
| ^
1725

1826
error: non-binding `let` without a type annotation
1927
--> $DIR/let_underscore_untyped.rs:39:5
2028
|
2129
LL | let _ = d(&1);
2230
| ^^^^^^^^^^^^^^
2331
|
24-
= help: consider adding a type annotation or removing the `let` keyword
32+
help: consider adding a type annotation
33+
--> $DIR/let_underscore_untyped.rs:39:10
34+
|
35+
LL | let _ = d(&1);
36+
| ^
2537

2638
error: non-binding `let` without a type annotation
2739
--> $DIR/let_underscore_untyped.rs:40:5
2840
|
2941
LL | let _ = e();
3042
| ^^^^^^^^^^^^
3143
|
32-
= help: consider adding a type annotation or removing the `let` keyword
44+
help: consider adding a type annotation
45+
--> $DIR/let_underscore_untyped.rs:40:10
46+
|
47+
LL | let _ = e();
48+
| ^
3349

3450
error: non-binding `let` without a type annotation
3551
--> $DIR/let_underscore_untyped.rs:41:5
3652
|
3753
LL | let _ = f();
3854
| ^^^^^^^^^^^^
3955
|
40-
= help: consider adding a type annotation or removing the `let` keyword
56+
help: consider adding a type annotation
57+
--> $DIR/let_underscore_untyped.rs:41:10
58+
|
59+
LL | let _ = f();
60+
| ^
4161

4262
error: aborting due to 5 previous errors
4363

0 commit comments

Comments
 (0)