Skip to content

Commit

Permalink
disable let_underscore_must_use in external macros
Browse files Browse the repository at this point in the history
  • Loading branch information
basil-cow committed Jan 23, 2020
1 parent eff3bc5 commit fef3657
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
5 changes: 5 additions & 0 deletions clippy_lints/src/let_underscore.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use if_chain::if_chain;
use rustc::lint::in_external_macro;
use rustc_hir::*;
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
Expand Down Expand Up @@ -33,6 +34,10 @@ declare_lint_pass!(LetUnderscore => [LET_UNDERSCORE_MUST_USE]);

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore {
fn check_stmt(&mut self, cx: &LateContext<'_, '_>, stmt: &Stmt<'_>) {
if in_external_macro(cx.tcx.sess, stmt.span) {
return;
}

if_chain! {
if let StmtKind::Local(ref local) = stmt.kind;
if let PatKind::Wild = local.pat.kind;
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/let_underscore.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#![warn(clippy::let_underscore_must_use)]

// Debug implementations can fire this lint,
// so we shouldn't lint external macros
#[derive(Debug)]
struct Foo {
field: i32,
}

#[must_use]
fn f() -> u32 {
0
Expand Down
24 changes: 12 additions & 12 deletions tests/ui/let_underscore.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: non-binding let on a result of a `#[must_use]` function
--> $DIR/let_underscore.rs:59:5
--> $DIR/let_underscore.rs:66:5
|
LL | let _ = f();
| ^^^^^^^^^^^^
Expand All @@ -8,87 +8,87 @@ LL | let _ = f();
= help: consider explicitly using function result

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

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

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

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

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

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

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

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

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

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

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

0 comments on commit fef3657

Please sign in to comment.