-
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 thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied
Description
Summary
The lint has a suggestion template for when the array/vec initializer is a part of a LetStmt
, but in this particular case:
match 0 {
0 => _ = [f(); 0],
_ => {},
}
its suggestion:
warning: function or method calls as the initial value in zero-sized array initializers may cause side effects
--> src/lib.rs:9:14
|
9 | _ => _ = [f(); 0],
| ^^^^^^^^^^^^ help: consider using: `f(); let _: [(); 0] = [];`
|
doesn't work for multiple reasons:
- Despite this being a
Stmt
in aBlock
, it has no surrounding braces, sof(); _: [(); 0] = [];
, which introduces a second statement, is invalid The_: [(); 0] = [];
part won't compile anyway -- theLetStmt
is lacking alet
, and so a type ascription is not allowedThe following would work though:_ = [] as [(); 0];
Lastly, it adds alet
that wasn't there to begin with
(EDIT: the last two happen on regular _ = [f(); 0];
s as well, opened a separate issue for that: #15825)
Reproducer
I tried this code:
#![allow(unused)]
#![warn(clippy::zero_repeat_side_effects)]
fn f() {}
fn foo() {
match 0 {
0 => _ = [f(); 0],
_ => {},
}
}
This happened:
warning: function or method calls as the initial value in zero-sized array initializers may cause side effects
--> src/lib.rs:9:14
|
9 | _ => _ = [f(); 0],
| ^^^^^^^^^^^^ help: consider using: `f(); let _: [(); 0] = [];`
|
I expected this to happen:
No suggestion
Version
rustc 1.90.0 (1159e78c4 2025-09-14)
binary: rustc
commit-hash: 1159e78c4747b02ef996e55082b704c09b970588
commit-date: 2025-09-14
host: x86_64-unknown-linux-gnu
release: 1.90.0
LLVM version: 20.1.8
Additional Labels
@rustbot label I-suggestion-causes-error
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied