Skip to content
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: 3 additions & 2 deletions clippy_lints/src/no_effect.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clippy_utils::diagnostics::{span_lint_hir, span_lint_hir_and_then};
use clippy_utils::source::snippet_opt;
use clippy_utils::ty::has_drop;
use clippy_utils::{get_parent_node, is_lint_allowed, peel_blocks};
use clippy_utils::{any_parent_is_automatically_derived, get_parent_node, is_lint_allowed, peel_blocks};
use rustc_errors::Applicability;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::{
Expand Down Expand Up @@ -150,12 +150,13 @@ fn check_no_effect(cx: &LateContext<'_>, stmt: &Stmt<'_>) -> bool {
&& has_no_effect(cx, init)
&& let PatKind::Binding(_, _, ident, _) = local.pat.kind
&& ident.name.to_ident_string().starts_with('_')
&& !any_parent_is_automatically_derived(cx.tcx, local.hir_id)
{
span_lint_hir(
cx,
NO_EFFECT_UNDERSCORE_BINDING,
init.hir_id,
stmt.span,
ident.span,
"binding to `_` prefixed variable with no side-effect",
);
return true;
Expand Down
16 changes: 8 additions & 8 deletions tests/ui/no_effect.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -152,31 +152,31 @@ LL | FooString { s: s };
| ^^^^^^^^^^^^^^^^^^^

error: binding to `_` prefixed variable with no side-effect
--> $DIR/no_effect.rs:175:5
--> $DIR/no_effect.rs:175:9
|
LL | let _unused = 1;
| ^^^^^^^^^^^^^^^^
| ^^^^^^^
|
= note: `-D clippy::no-effect-underscore-binding` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::no_effect_underscore_binding)]`

error: binding to `_` prefixed variable with no side-effect
--> $DIR/no_effect.rs:178:5
--> $DIR/no_effect.rs:178:9
|
LL | let _penguin = || println!("Some helpful closure");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^

error: binding to `_` prefixed variable with no side-effect
--> $DIR/no_effect.rs:180:5
--> $DIR/no_effect.rs:180:9
|
LL | let _duck = Struct { field: 0 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^

error: binding to `_` prefixed variable with no side-effect
--> $DIR/no_effect.rs:182:5
--> $DIR/no_effect.rs:182:9
|
LL | let _cat = [2, 4, 6, 8][2];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^

error: aborting due to 29 previous errors