Skip to content

Commit c58b6e6

Browse files
committed
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
2 parents a863780 + 9d790d6 commit c58b6e6

File tree

3 files changed

+33
-56
lines changed

3 files changed

+33
-56
lines changed

clippy_lints/src/no_effect.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ impl<'tcx> LateLintPass<'tcx> for NoEffect {
9494

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

110109
fn check_expr(&mut self, _: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
111110
if let Some(def_id) = path_to_local(expr) {
112-
// FIXME(rust/#120456) - is `swap_remove` correct?
113111
self.underscore_bindings.swap_remove(&def_id);
114112
}
115113
}
@@ -118,7 +116,11 @@ impl<'tcx> LateLintPass<'tcx> for NoEffect {
118116
impl NoEffect {
119117
fn check_no_effect(&mut self, cx: &LateContext<'_>, stmt: &Stmt<'_>) -> bool {
120118
if let StmtKind::Semi(expr) = stmt.kind {
121-
// move `expr.span.from_expansion()` ahead
119+
// Covered by rustc `path_statements` lint
120+
if matches!(expr.kind, ExprKind::Path(_)) {
121+
return true;
122+
}
123+
122124
if expr.span.from_expansion() {
123125
return false;
124126
}

tests/ui/no_effect.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![feature(fn_traits, unboxed_closures)]
22
#![warn(clippy::no_effect_underscore_binding)]
3-
#![allow(dead_code, path_statements)]
43
#![allow(
54
clippy::deref_addrof,
65
clippy::redundant_field_names,
@@ -33,7 +32,6 @@ impl Neg for Cout {
3332
}
3433
}
3534

36-
struct Unit;
3735
struct Tuple(i32);
3836
struct Struct {
3937
field: i32,
@@ -42,10 +40,6 @@ enum Enum {
4240
Tuple(i32),
4341
Struct { field: i32 },
4442
}
45-
struct DropUnit;
46-
impl Drop for DropUnit {
47-
fn drop(&mut self) {}
48-
}
4943
struct DropStruct {
5044
field: i32,
5145
}
@@ -117,15 +111,9 @@ impl FnOnce<(&str,)> for GreetStruct3 {
117111

118112
fn main() {
119113
let s = get_struct();
120-
let s2 = get_struct();
121114

122115
0;
123116
//~^ ERROR: statement with no effect
124-
//~| NOTE: `-D clippy::no-effect` implied by `-D warnings`
125-
s2;
126-
//~^ ERROR: statement with no effect
127-
Unit;
128-
//~^ ERROR: statement with no effect
129117
Tuple(0);
130118
//~^ ERROR: statement with no effect
131119
Struct { field: 0 };
@@ -192,7 +180,6 @@ fn main() {
192180
unsafe { unsafe_fn() };
193181
let _used = get_struct();
194182
let _x = vec![1];
195-
DropUnit;
196183
DropStruct { field: 0 };
197184
DropTuple(0);
198185
DropEnum::Tuple(0);

tests/ui/no_effect.stderr

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: statement with no effect
2-
--> tests/ui/no_effect.rs:122:5
2+
--> tests/ui/no_effect.rs:115:5
33
|
44
LL | 0;
55
| ^^
@@ -8,151 +8,139 @@ LL | 0;
88
= help: to override `-D warnings` add `#[allow(clippy::no_effect)]`
99

1010
error: statement with no effect
11-
--> tests/ui/no_effect.rs:125:5
12-
|
13-
LL | s2;
14-
| ^^^
15-
16-
error: statement with no effect
17-
--> tests/ui/no_effect.rs:127:5
18-
|
19-
LL | Unit;
20-
| ^^^^^
21-
22-
error: statement with no effect
23-
--> tests/ui/no_effect.rs:129:5
11+
--> tests/ui/no_effect.rs:117:5
2412
|
2513
LL | Tuple(0);
2614
| ^^^^^^^^^
2715

2816
error: statement with no effect
29-
--> tests/ui/no_effect.rs:131:5
17+
--> tests/ui/no_effect.rs:119:5
3018
|
3119
LL | Struct { field: 0 };
3220
| ^^^^^^^^^^^^^^^^^^^^
3321

3422
error: statement with no effect
35-
--> tests/ui/no_effect.rs:133:5
23+
--> tests/ui/no_effect.rs:121:5
3624
|
3725
LL | Struct { ..s };
3826
| ^^^^^^^^^^^^^^^
3927

4028
error: statement with no effect
41-
--> tests/ui/no_effect.rs:135:5
29+
--> tests/ui/no_effect.rs:123:5
4230
|
4331
LL | Union { a: 0 };
4432
| ^^^^^^^^^^^^^^^
4533

4634
error: statement with no effect
47-
--> tests/ui/no_effect.rs:137:5
35+
--> tests/ui/no_effect.rs:125:5
4836
|
4937
LL | Enum::Tuple(0);
5038
| ^^^^^^^^^^^^^^^
5139

5240
error: statement with no effect
53-
--> tests/ui/no_effect.rs:139:5
41+
--> tests/ui/no_effect.rs:127:5
5442
|
5543
LL | Enum::Struct { field: 0 };
5644
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
5745

5846
error: statement with no effect
59-
--> tests/ui/no_effect.rs:141:5
47+
--> tests/ui/no_effect.rs:129:5
6048
|
6149
LL | 5 + 6;
6250
| ^^^^^^
6351

6452
error: statement with no effect
65-
--> tests/ui/no_effect.rs:143:5
53+
--> tests/ui/no_effect.rs:131:5
6654
|
6755
LL | *&42;
6856
| ^^^^^
6957

7058
error: statement with no effect
71-
--> tests/ui/no_effect.rs:145:5
59+
--> tests/ui/no_effect.rs:133:5
7260
|
7361
LL | &6;
7462
| ^^^
7563

7664
error: statement with no effect
77-
--> tests/ui/no_effect.rs:147:5
65+
--> tests/ui/no_effect.rs:135:5
7866
|
7967
LL | (5, 6, 7);
8068
| ^^^^^^^^^^
8169

8270
error: statement with no effect
83-
--> tests/ui/no_effect.rs:149:5
71+
--> tests/ui/no_effect.rs:137:5
8472
|
8573
LL | ..;
8674
| ^^^
8775

8876
error: statement with no effect
89-
--> tests/ui/no_effect.rs:151:5
77+
--> tests/ui/no_effect.rs:139:5
9078
|
9179
LL | 5..;
9280
| ^^^^
9381

9482
error: statement with no effect
95-
--> tests/ui/no_effect.rs:153:5
83+
--> tests/ui/no_effect.rs:141:5
9684
|
9785
LL | ..5;
9886
| ^^^^
9987

10088
error: statement with no effect
101-
--> tests/ui/no_effect.rs:155:5
89+
--> tests/ui/no_effect.rs:143:5
10290
|
10391
LL | 5..6;
10492
| ^^^^^
10593

10694
error: statement with no effect
107-
--> tests/ui/no_effect.rs:157:5
95+
--> tests/ui/no_effect.rs:145:5
10896
|
10997
LL | 5..=6;
11098
| ^^^^^^
11199

112100
error: statement with no effect
113-
--> tests/ui/no_effect.rs:159:5
101+
--> tests/ui/no_effect.rs:147:5
114102
|
115103
LL | [42, 55];
116104
| ^^^^^^^^^
117105

118106
error: statement with no effect
119-
--> tests/ui/no_effect.rs:161:5
107+
--> tests/ui/no_effect.rs:149:5
120108
|
121109
LL | [42, 55][1];
122110
| ^^^^^^^^^^^^
123111

124112
error: statement with no effect
125-
--> tests/ui/no_effect.rs:163:5
113+
--> tests/ui/no_effect.rs:151:5
126114
|
127115
LL | (42, 55).1;
128116
| ^^^^^^^^^^^
129117

130118
error: statement with no effect
131-
--> tests/ui/no_effect.rs:165:5
119+
--> tests/ui/no_effect.rs:153:5
132120
|
133121
LL | [42; 55];
134122
| ^^^^^^^^^
135123

136124
error: statement with no effect
137-
--> tests/ui/no_effect.rs:167:5
125+
--> tests/ui/no_effect.rs:155:5
138126
|
139127
LL | [42; 55][13];
140128
| ^^^^^^^^^^^^^
141129

142130
error: statement with no effect
143-
--> tests/ui/no_effect.rs:170:5
131+
--> tests/ui/no_effect.rs:158:5
144132
|
145133
LL | || x += 5;
146134
| ^^^^^^^^^^
147135

148136
error: statement with no effect
149-
--> tests/ui/no_effect.rs:173:5
137+
--> tests/ui/no_effect.rs:161:5
150138
|
151139
LL | FooString { s: s };
152140
| ^^^^^^^^^^^^^^^^^^^
153141

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

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

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

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

181-
error: aborting due to 29 previous errors
169+
error: aborting due to 27 previous errors
182170

0 commit comments

Comments
 (0)