Skip to content

Commit

Permalink
Auto merge of #12798 - Alexendoo:no-effect-path-statements, r=y21
Browse files Browse the repository at this point in the history
Don't lint path statements in no_effect

The rustc lint `path_statements` covers this case

Fixes #11547

changelog: none
  • Loading branch information
bors committed May 14, 2024
2 parents a863780 + 9d790d6 commit c58b6e6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 56 deletions.
8 changes: 5 additions & 3 deletions clippy_lints/src/no_effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ impl<'tcx> LateLintPass<'tcx> for NoEffect {

fn check_block_post(&mut self, cx: &LateContext<'tcx>, _: &'tcx rustc_hir::Block<'tcx>) {
for hir_id in self.local_bindings.pop().unwrap() {
// FIXME(rust/#120456) - is `swap_remove` correct?
if let Some(span) = self.underscore_bindings.swap_remove(&hir_id) {
span_lint_hir(
cx,
Expand All @@ -109,7 +108,6 @@ impl<'tcx> LateLintPass<'tcx> for NoEffect {

fn check_expr(&mut self, _: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
if let Some(def_id) = path_to_local(expr) {
// FIXME(rust/#120456) - is `swap_remove` correct?
self.underscore_bindings.swap_remove(&def_id);
}
}
Expand All @@ -118,7 +116,11 @@ impl<'tcx> LateLintPass<'tcx> for NoEffect {
impl NoEffect {
fn check_no_effect(&mut self, cx: &LateContext<'_>, stmt: &Stmt<'_>) -> bool {
if let StmtKind::Semi(expr) = stmt.kind {
// move `expr.span.from_expansion()` ahead
// Covered by rustc `path_statements` lint
if matches!(expr.kind, ExprKind::Path(_)) {
return true;
}

if expr.span.from_expansion() {
return false;
}
Expand Down
13 changes: 0 additions & 13 deletions tests/ui/no_effect.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![feature(fn_traits, unboxed_closures)]
#![warn(clippy::no_effect_underscore_binding)]
#![allow(dead_code, path_statements)]
#![allow(
clippy::deref_addrof,
clippy::redundant_field_names,
Expand Down Expand Up @@ -33,7 +32,6 @@ impl Neg for Cout {
}
}

struct Unit;
struct Tuple(i32);
struct Struct {
field: i32,
Expand All @@ -42,10 +40,6 @@ enum Enum {
Tuple(i32),
Struct { field: i32 },
}
struct DropUnit;
impl Drop for DropUnit {
fn drop(&mut self) {}
}
struct DropStruct {
field: i32,
}
Expand Down Expand Up @@ -117,15 +111,9 @@ impl FnOnce<(&str,)> for GreetStruct3 {

fn main() {
let s = get_struct();
let s2 = get_struct();

0;
//~^ ERROR: statement with no effect
//~| NOTE: `-D clippy::no-effect` implied by `-D warnings`
s2;
//~^ ERROR: statement with no effect
Unit;
//~^ ERROR: statement with no effect
Tuple(0);
//~^ ERROR: statement with no effect
Struct { field: 0 };
Expand Down Expand Up @@ -192,7 +180,6 @@ fn main() {
unsafe { unsafe_fn() };
let _used = get_struct();
let _x = vec![1];
DropUnit;
DropStruct { field: 0 };
DropTuple(0);
DropEnum::Tuple(0);
Expand Down
68 changes: 28 additions & 40 deletions tests/ui/no_effect.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: statement with no effect
--> tests/ui/no_effect.rs:122:5
--> tests/ui/no_effect.rs:115:5
|
LL | 0;
| ^^
Expand All @@ -8,151 +8,139 @@ LL | 0;
= help: to override `-D warnings` add `#[allow(clippy::no_effect)]`

error: statement with no effect
--> tests/ui/no_effect.rs:125:5
|
LL | s2;
| ^^^

error: statement with no effect
--> tests/ui/no_effect.rs:127:5
|
LL | Unit;
| ^^^^^

error: statement with no effect
--> tests/ui/no_effect.rs:129:5
--> tests/ui/no_effect.rs:117:5
|
LL | Tuple(0);
| ^^^^^^^^^

error: statement with no effect
--> tests/ui/no_effect.rs:131:5
--> tests/ui/no_effect.rs:119:5
|
LL | Struct { field: 0 };
| ^^^^^^^^^^^^^^^^^^^^

error: statement with no effect
--> tests/ui/no_effect.rs:133:5
--> tests/ui/no_effect.rs:121:5
|
LL | Struct { ..s };
| ^^^^^^^^^^^^^^^

error: statement with no effect
--> tests/ui/no_effect.rs:135:5
--> tests/ui/no_effect.rs:123:5
|
LL | Union { a: 0 };
| ^^^^^^^^^^^^^^^

error: statement with no effect
--> tests/ui/no_effect.rs:137:5
--> tests/ui/no_effect.rs:125:5
|
LL | Enum::Tuple(0);
| ^^^^^^^^^^^^^^^

error: statement with no effect
--> tests/ui/no_effect.rs:139:5
--> tests/ui/no_effect.rs:127:5
|
LL | Enum::Struct { field: 0 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: statement with no effect
--> tests/ui/no_effect.rs:141:5
--> tests/ui/no_effect.rs:129:5
|
LL | 5 + 6;
| ^^^^^^

error: statement with no effect
--> tests/ui/no_effect.rs:143:5
--> tests/ui/no_effect.rs:131:5
|
LL | *&42;
| ^^^^^

error: statement with no effect
--> tests/ui/no_effect.rs:145:5
--> tests/ui/no_effect.rs:133:5
|
LL | &6;
| ^^^

error: statement with no effect
--> tests/ui/no_effect.rs:147:5
--> tests/ui/no_effect.rs:135:5
|
LL | (5, 6, 7);
| ^^^^^^^^^^

error: statement with no effect
--> tests/ui/no_effect.rs:149:5
--> tests/ui/no_effect.rs:137:5
|
LL | ..;
| ^^^

error: statement with no effect
--> tests/ui/no_effect.rs:151:5
--> tests/ui/no_effect.rs:139:5
|
LL | 5..;
| ^^^^

error: statement with no effect
--> tests/ui/no_effect.rs:153:5
--> tests/ui/no_effect.rs:141:5
|
LL | ..5;
| ^^^^

error: statement with no effect
--> tests/ui/no_effect.rs:155:5
--> tests/ui/no_effect.rs:143:5
|
LL | 5..6;
| ^^^^^

error: statement with no effect
--> tests/ui/no_effect.rs:157:5
--> tests/ui/no_effect.rs:145:5
|
LL | 5..=6;
| ^^^^^^

error: statement with no effect
--> tests/ui/no_effect.rs:159:5
--> tests/ui/no_effect.rs:147:5
|
LL | [42, 55];
| ^^^^^^^^^

error: statement with no effect
--> tests/ui/no_effect.rs:161:5
--> tests/ui/no_effect.rs:149:5
|
LL | [42, 55][1];
| ^^^^^^^^^^^^

error: statement with no effect
--> tests/ui/no_effect.rs:163:5
--> tests/ui/no_effect.rs:151:5
|
LL | (42, 55).1;
| ^^^^^^^^^^^

error: statement with no effect
--> tests/ui/no_effect.rs:165:5
--> tests/ui/no_effect.rs:153:5
|
LL | [42; 55];
| ^^^^^^^^^

error: statement with no effect
--> tests/ui/no_effect.rs:167:5
--> tests/ui/no_effect.rs:155:5
|
LL | [42; 55][13];
| ^^^^^^^^^^^^^

error: statement with no effect
--> tests/ui/no_effect.rs:170:5
--> tests/ui/no_effect.rs:158:5
|
LL | || x += 5;
| ^^^^^^^^^^

error: statement with no effect
--> tests/ui/no_effect.rs:173:5
--> tests/ui/no_effect.rs:161:5
|
LL | FooString { s: s };
| ^^^^^^^^^^^^^^^^^^^

error: binding to `_` prefixed variable with no side-effect
--> tests/ui/no_effect.rs:175:9
--> tests/ui/no_effect.rs:163:9
|
LL | let _unused = 1;
| ^^^^^^^
Expand All @@ -161,22 +149,22 @@ LL | let _unused = 1;
= help: to override `-D warnings` add `#[allow(clippy::no_effect_underscore_binding)]`

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

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

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

error: aborting due to 29 previous errors
error: aborting due to 27 previous errors

0 comments on commit c58b6e6

Please sign in to comment.