-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing
Description
Summary
It replaces
_ = [f(); 0];
with
f(); let _: [(); 0] = [];
-- notice the added let
.
Detecting this would probably involve checking whether the source
field of LetStmt
is LocalSource::AssignDesugar
.
Note that that by itself won't be enough, i.e. the following wouldn't compile:
f(); _: [(); 0] = [];
That's because type ascriptions are apparently not allowed on LetStmt
s without a let
-- so one would need to suggest f(); _ = [] as [(); 0];
instead.
Reproducer
I tried this code:
#![allow(unused)]
#![warn(clippy::zero_repeat_side_effects)]
fn f() {}
fn foo() {
_ = [f(); 0];
}
I expected to see this happen:
warning: function or method calls as the initial value in zero-sized array initializers may cause side effects
--> src/main.rs:7:5
|
7 | _ = [f(); 0];
| ^^^^^^^^^^^^ help: consider using: `f(); _ = [] as [(); 0];`
|
Instead, this happened:
warning: function or method calls as the initial value in zero-sized array initializers may cause side effects
--> src/main.rs:7:5
|
7 | _ = [f(); 0];
| ^^^^^^^^^^^^ help: consider using: `f(); let _: [(); 0] = [];`
|
Version
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing