Auto merge of #12798 - Alexendoo:no-effect-path-statements, r=y21
Don't lint path statements in no_effect The rustc lint `path_statements` covers this case Fixes #11547 changelog: none
This commit is contained in:
commit
c58b6e66fd
@ -94,7 +94,6 @@ fn check_block(&mut self, _: &LateContext<'tcx>, _: &'tcx rustc_hir::Block<'tcx>
|
|||||||
|
|
||||||
fn check_block_post(&mut self, cx: &LateContext<'tcx>, _: &'tcx rustc_hir::Block<'tcx>) {
|
fn check_block_post(&mut self, cx: &LateContext<'tcx>, _: &'tcx rustc_hir::Block<'tcx>) {
|
||||||
for hir_id in self.local_bindings.pop().unwrap() {
|
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) {
|
if let Some(span) = self.underscore_bindings.swap_remove(&hir_id) {
|
||||||
span_lint_hir(
|
span_lint_hir(
|
||||||
cx,
|
cx,
|
||||||
@ -109,7 +108,6 @@ fn check_block_post(&mut self, cx: &LateContext<'tcx>, _: &'tcx rustc_hir::Block
|
|||||||
|
|
||||||
fn check_expr(&mut self, _: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
|
fn check_expr(&mut self, _: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
|
||||||
if let Some(def_id) = path_to_local(expr) {
|
if let Some(def_id) = path_to_local(expr) {
|
||||||
// FIXME(rust/#120456) - is `swap_remove` correct?
|
|
||||||
self.underscore_bindings.swap_remove(&def_id);
|
self.underscore_bindings.swap_remove(&def_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -118,7 +116,11 @@ fn check_expr(&mut self, _: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
|
|||||||
impl NoEffect {
|
impl NoEffect {
|
||||||
fn check_no_effect(&mut self, cx: &LateContext<'_>, stmt: &Stmt<'_>) -> bool {
|
fn check_no_effect(&mut self, cx: &LateContext<'_>, stmt: &Stmt<'_>) -> bool {
|
||||||
if let StmtKind::Semi(expr) = stmt.kind {
|
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() {
|
if expr.span.from_expansion() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#![feature(fn_traits, unboxed_closures)]
|
#![feature(fn_traits, unboxed_closures)]
|
||||||
#![warn(clippy::no_effect_underscore_binding)]
|
#![warn(clippy::no_effect_underscore_binding)]
|
||||||
#![allow(dead_code, path_statements)]
|
|
||||||
#![allow(
|
#![allow(
|
||||||
clippy::deref_addrof,
|
clippy::deref_addrof,
|
||||||
clippy::redundant_field_names,
|
clippy::redundant_field_names,
|
||||||
@ -33,7 +32,6 @@ fn neg(self) -> Self::Output {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Unit;
|
|
||||||
struct Tuple(i32);
|
struct Tuple(i32);
|
||||||
struct Struct {
|
struct Struct {
|
||||||
field: i32,
|
field: i32,
|
||||||
@ -42,10 +40,6 @@ enum Enum {
|
|||||||
Tuple(i32),
|
Tuple(i32),
|
||||||
Struct { field: i32 },
|
Struct { field: i32 },
|
||||||
}
|
}
|
||||||
struct DropUnit;
|
|
||||||
impl Drop for DropUnit {
|
|
||||||
fn drop(&mut self) {}
|
|
||||||
}
|
|
||||||
struct DropStruct {
|
struct DropStruct {
|
||||||
field: i32,
|
field: i32,
|
||||||
}
|
}
|
||||||
@ -117,15 +111,9 @@ extern "rust-call" fn call_once(self, (who,): (&str,)) -> Self::Output {
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let s = get_struct();
|
let s = get_struct();
|
||||||
let s2 = get_struct();
|
|
||||||
|
|
||||||
0;
|
0;
|
||||||
//~^ ERROR: statement with no effect
|
//~^ 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);
|
Tuple(0);
|
||||||
//~^ ERROR: statement with no effect
|
//~^ ERROR: statement with no effect
|
||||||
Struct { field: 0 };
|
Struct { field: 0 };
|
||||||
@ -192,7 +180,6 @@ fn main() {
|
|||||||
unsafe { unsafe_fn() };
|
unsafe { unsafe_fn() };
|
||||||
let _used = get_struct();
|
let _used = get_struct();
|
||||||
let _x = vec![1];
|
let _x = vec![1];
|
||||||
DropUnit;
|
|
||||||
DropStruct { field: 0 };
|
DropStruct { field: 0 };
|
||||||
DropTuple(0);
|
DropTuple(0);
|
||||||
DropEnum::Tuple(0);
|
DropEnum::Tuple(0);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
error: statement with no effect
|
error: statement with no effect
|
||||||
--> tests/ui/no_effect.rs:122:5
|
--> tests/ui/no_effect.rs:115:5
|
||||||
|
|
|
|
||||||
LL | 0;
|
LL | 0;
|
||||||
| ^^
|
| ^^
|
||||||
@ -8,151 +8,139 @@ LL | 0;
|
|||||||
= help: to override `-D warnings` add `#[allow(clippy::no_effect)]`
|
= help: to override `-D warnings` add `#[allow(clippy::no_effect)]`
|
||||||
|
|
||||||
error: statement with no effect
|
error: statement with no effect
|
||||||
--> tests/ui/no_effect.rs:125:5
|
--> tests/ui/no_effect.rs:117: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
|
|
||||||
|
|
|
|
||||||
LL | Tuple(0);
|
LL | Tuple(0);
|
||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
|
|
||||||
error: statement with no effect
|
error: statement with no effect
|
||||||
--> tests/ui/no_effect.rs:131:5
|
--> tests/ui/no_effect.rs:119:5
|
||||||
|
|
|
|
||||||
LL | Struct { field: 0 };
|
LL | Struct { field: 0 };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: statement with no effect
|
error: statement with no effect
|
||||||
--> tests/ui/no_effect.rs:133:5
|
--> tests/ui/no_effect.rs:121:5
|
||||||
|
|
|
|
||||||
LL | Struct { ..s };
|
LL | Struct { ..s };
|
||||||
| ^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: statement with no effect
|
error: statement with no effect
|
||||||
--> tests/ui/no_effect.rs:135:5
|
--> tests/ui/no_effect.rs:123:5
|
||||||
|
|
|
|
||||||
LL | Union { a: 0 };
|
LL | Union { a: 0 };
|
||||||
| ^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: statement with no effect
|
error: statement with no effect
|
||||||
--> tests/ui/no_effect.rs:137:5
|
--> tests/ui/no_effect.rs:125:5
|
||||||
|
|
|
|
||||||
LL | Enum::Tuple(0);
|
LL | Enum::Tuple(0);
|
||||||
| ^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: statement with no effect
|
error: statement with no effect
|
||||||
--> tests/ui/no_effect.rs:139:5
|
--> tests/ui/no_effect.rs:127:5
|
||||||
|
|
|
|
||||||
LL | Enum::Struct { field: 0 };
|
LL | Enum::Struct { field: 0 };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: statement with no effect
|
error: statement with no effect
|
||||||
--> tests/ui/no_effect.rs:141:5
|
--> tests/ui/no_effect.rs:129:5
|
||||||
|
|
|
|
||||||
LL | 5 + 6;
|
LL | 5 + 6;
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
||||||
error: statement with no effect
|
error: statement with no effect
|
||||||
--> tests/ui/no_effect.rs:143:5
|
--> tests/ui/no_effect.rs:131:5
|
||||||
|
|
|
|
||||||
LL | *&42;
|
LL | *&42;
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
|
|
||||||
error: statement with no effect
|
error: statement with no effect
|
||||||
--> tests/ui/no_effect.rs:145:5
|
--> tests/ui/no_effect.rs:133:5
|
||||||
|
|
|
|
||||||
LL | &6;
|
LL | &6;
|
||||||
| ^^^
|
| ^^^
|
||||||
|
|
||||||
error: statement with no effect
|
error: statement with no effect
|
||||||
--> tests/ui/no_effect.rs:147:5
|
--> tests/ui/no_effect.rs:135:5
|
||||||
|
|
|
|
||||||
LL | (5, 6, 7);
|
LL | (5, 6, 7);
|
||||||
| ^^^^^^^^^^
|
| ^^^^^^^^^^
|
||||||
|
|
||||||
error: statement with no effect
|
error: statement with no effect
|
||||||
--> tests/ui/no_effect.rs:149:5
|
--> tests/ui/no_effect.rs:137:5
|
||||||
|
|
|
|
||||||
LL | ..;
|
LL | ..;
|
||||||
| ^^^
|
| ^^^
|
||||||
|
|
||||||
error: statement with no effect
|
error: statement with no effect
|
||||||
--> tests/ui/no_effect.rs:151:5
|
--> tests/ui/no_effect.rs:139:5
|
||||||
|
|
|
|
||||||
LL | 5..;
|
LL | 5..;
|
||||||
| ^^^^
|
| ^^^^
|
||||||
|
|
||||||
error: statement with no effect
|
error: statement with no effect
|
||||||
--> tests/ui/no_effect.rs:153:5
|
--> tests/ui/no_effect.rs:141:5
|
||||||
|
|
|
|
||||||
LL | ..5;
|
LL | ..5;
|
||||||
| ^^^^
|
| ^^^^
|
||||||
|
|
||||||
error: statement with no effect
|
error: statement with no effect
|
||||||
--> tests/ui/no_effect.rs:155:5
|
--> tests/ui/no_effect.rs:143:5
|
||||||
|
|
|
|
||||||
LL | 5..6;
|
LL | 5..6;
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
|
|
||||||
error: statement with no effect
|
error: statement with no effect
|
||||||
--> tests/ui/no_effect.rs:157:5
|
--> tests/ui/no_effect.rs:145:5
|
||||||
|
|
|
|
||||||
LL | 5..=6;
|
LL | 5..=6;
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
||||||
error: statement with no effect
|
error: statement with no effect
|
||||||
--> tests/ui/no_effect.rs:159:5
|
--> tests/ui/no_effect.rs:147:5
|
||||||
|
|
|
|
||||||
LL | [42, 55];
|
LL | [42, 55];
|
||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
|
|
||||||
error: statement with no effect
|
error: statement with no effect
|
||||||
--> tests/ui/no_effect.rs:161:5
|
--> tests/ui/no_effect.rs:149:5
|
||||||
|
|
|
|
||||||
LL | [42, 55][1];
|
LL | [42, 55][1];
|
||||||
| ^^^^^^^^^^^^
|
| ^^^^^^^^^^^^
|
||||||
|
|
||||||
error: statement with no effect
|
error: statement with no effect
|
||||||
--> tests/ui/no_effect.rs:163:5
|
--> tests/ui/no_effect.rs:151:5
|
||||||
|
|
|
|
||||||
LL | (42, 55).1;
|
LL | (42, 55).1;
|
||||||
| ^^^^^^^^^^^
|
| ^^^^^^^^^^^
|
||||||
|
|
||||||
error: statement with no effect
|
error: statement with no effect
|
||||||
--> tests/ui/no_effect.rs:165:5
|
--> tests/ui/no_effect.rs:153:5
|
||||||
|
|
|
|
||||||
LL | [42; 55];
|
LL | [42; 55];
|
||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
|
|
||||||
error: statement with no effect
|
error: statement with no effect
|
||||||
--> tests/ui/no_effect.rs:167:5
|
--> tests/ui/no_effect.rs:155:5
|
||||||
|
|
|
|
||||||
LL | [42; 55][13];
|
LL | [42; 55][13];
|
||||||
| ^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: statement with no effect
|
error: statement with no effect
|
||||||
--> tests/ui/no_effect.rs:170:5
|
--> tests/ui/no_effect.rs:158:5
|
||||||
|
|
|
|
||||||
LL | || x += 5;
|
LL | || x += 5;
|
||||||
| ^^^^^^^^^^
|
| ^^^^^^^^^^
|
||||||
|
|
||||||
error: statement with no effect
|
error: statement with no effect
|
||||||
--> tests/ui/no_effect.rs:173:5
|
--> tests/ui/no_effect.rs:161:5
|
||||||
|
|
|
|
||||||
LL | FooString { s: s };
|
LL | FooString { s: s };
|
||||||
| ^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: binding to `_` prefixed variable with no side-effect
|
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;
|
LL | let _unused = 1;
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
@ -161,22 +149,22 @@ LL | let _unused = 1;
|
|||||||
= help: to override `-D warnings` add `#[allow(clippy::no_effect_underscore_binding)]`
|
= help: to override `-D warnings` add `#[allow(clippy::no_effect_underscore_binding)]`
|
||||||
|
|
||||||
error: binding to `_` prefixed variable with no side-effect
|
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");
|
LL | let _penguin = || println!("Some helpful closure");
|
||||||
| ^^^^^^^^
|
| ^^^^^^^^
|
||||||
|
|
||||||
error: binding to `_` prefixed variable with no side-effect
|
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 };
|
LL | let _duck = Struct { field: 0 };
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
|
|
||||||
error: binding to `_` prefixed variable with no side-effect
|
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];
|
LL | let _cat = [2, 4, 6, 8][2];
|
||||||
| ^^^^
|
| ^^^^
|
||||||
|
|
||||||
error: aborting due to 29 previous errors
|
error: aborting due to 27 previous errors
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user