Skip to content

Commit 3237b7a

Browse files
committed
Auto merge of #5082 - Areredify:issue-4980, r=flip1995
disable let_underscore_must_use in external macros changelog: disable let_underscore_must_use in external macros Closes #4980
2 parents 6763447 + fef3657 commit 3237b7a

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

clippy_lints/src/let_underscore.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use if_chain::if_chain;
2+
use rustc::lint::in_external_macro;
23
use rustc_hir::*;
34
use rustc_lint::{LateContext, LateLintPass};
45
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -33,6 +34,10 @@ declare_lint_pass!(LetUnderscore => [LET_UNDERSCORE_MUST_USE]);
3334

3435
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore {
3536
fn check_stmt(&mut self, cx: &LateContext<'_, '_>, stmt: &Stmt<'_>) {
37+
if in_external_macro(cx.tcx.sess, stmt.span) {
38+
return;
39+
}
40+
3641
if_chain! {
3742
if let StmtKind::Local(ref local) = stmt.kind;
3843
if let PatKind::Wild = local.pat.kind;

tests/ui/let_underscore.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#![warn(clippy::let_underscore_must_use)]
22

3+
// Debug implementations can fire this lint,
4+
// so we shouldn't lint external macros
5+
#[derive(Debug)]
6+
struct Foo {
7+
field: i32,
8+
}
9+
310
#[must_use]
411
fn f() -> u32 {
512
0

tests/ui/let_underscore.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: non-binding let on a result of a `#[must_use]` function
2-
--> $DIR/let_underscore.rs:59:5
2+
--> $DIR/let_underscore.rs:66:5
33
|
44
LL | let _ = f();
55
| ^^^^^^^^^^^^
@@ -8,87 +8,87 @@ LL | let _ = f();
88
= help: consider explicitly using function result
99

1010
error: non-binding let on an expression with `#[must_use]` type
11-
--> $DIR/let_underscore.rs:60:5
11+
--> $DIR/let_underscore.rs:67:5
1212
|
1313
LL | let _ = g();
1414
| ^^^^^^^^^^^^
1515
|
1616
= help: consider explicitly using expression value
1717

1818
error: non-binding let on a result of a `#[must_use]` function
19-
--> $DIR/let_underscore.rs:62:5
19+
--> $DIR/let_underscore.rs:69:5
2020
|
2121
LL | let _ = l(0_u32);
2222
| ^^^^^^^^^^^^^^^^^
2323
|
2424
= help: consider explicitly using function result
2525

2626
error: non-binding let on a result of a `#[must_use]` function
27-
--> $DIR/let_underscore.rs:66:5
27+
--> $DIR/let_underscore.rs:73:5
2828
|
2929
LL | let _ = s.f();
3030
| ^^^^^^^^^^^^^^
3131
|
3232
= help: consider explicitly using function result
3333

3434
error: non-binding let on an expression with `#[must_use]` type
35-
--> $DIR/let_underscore.rs:67:5
35+
--> $DIR/let_underscore.rs:74:5
3636
|
3737
LL | let _ = s.g();
3838
| ^^^^^^^^^^^^^^
3939
|
4040
= help: consider explicitly using expression value
4141

4242
error: non-binding let on a result of a `#[must_use]` function
43-
--> $DIR/let_underscore.rs:70:5
43+
--> $DIR/let_underscore.rs:77:5
4444
|
4545
LL | let _ = S::h();
4646
| ^^^^^^^^^^^^^^^
4747
|
4848
= help: consider explicitly using function result
4949

5050
error: non-binding let on an expression with `#[must_use]` type
51-
--> $DIR/let_underscore.rs:71:5
51+
--> $DIR/let_underscore.rs:78:5
5252
|
5353
LL | let _ = S::p();
5454
| ^^^^^^^^^^^^^^^
5555
|
5656
= help: consider explicitly using expression value
5757

5858
error: non-binding let on a result of a `#[must_use]` function
59-
--> $DIR/let_underscore.rs:73:5
59+
--> $DIR/let_underscore.rs:80:5
6060
|
6161
LL | let _ = S::a();
6262
| ^^^^^^^^^^^^^^^
6363
|
6464
= help: consider explicitly using function result
6565

6666
error: non-binding let on an expression with `#[must_use]` type
67-
--> $DIR/let_underscore.rs:75:5
67+
--> $DIR/let_underscore.rs:82:5
6868
|
6969
LL | let _ = if true { Ok(()) } else { Err(()) };
7070
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7171
|
7272
= help: consider explicitly using expression value
7373

7474
error: non-binding let on a result of a `#[must_use]` function
75-
--> $DIR/let_underscore.rs:79:5
75+
--> $DIR/let_underscore.rs:86:5
7676
|
7777
LL | let _ = a.is_ok();
7878
| ^^^^^^^^^^^^^^^^^^
7979
|
8080
= help: consider explicitly using function result
8181

8282
error: non-binding let on an expression with `#[must_use]` type
83-
--> $DIR/let_underscore.rs:81:5
83+
--> $DIR/let_underscore.rs:88:5
8484
|
8585
LL | let _ = a.map(|_| ());
8686
| ^^^^^^^^^^^^^^^^^^^^^^
8787
|
8888
= help: consider explicitly using expression value
8989

9090
error: non-binding let on an expression with `#[must_use]` type
91-
--> $DIR/let_underscore.rs:83:5
91+
--> $DIR/let_underscore.rs:90:5
9292
|
9393
LL | let _ = a;
9494
| ^^^^^^^^^^

0 commit comments

Comments
 (0)