Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable let_underscore_must_use in external macros #5082

Merged
merged 1 commit into from
Jan 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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