-
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
unnecessary_lazy_evaluations
is normally a great lint, but in this example it produces a fix that does not compile.
The realistic example comes from embassy/embassy-usb.
Reproducer
I tried this code (see playground):
fn main() {
let data = vec![1, 2, 3];
let len = 3;
let max_packet_size = 2;
let need_zlp = true;
let chunks = data[0..len]
.chunks(max_packet_size)
.chain(need_zlp.then(|| -> &[u8] { &[] }));
//.chain(need_zlp.then_some({ &[] }));
dbg!(chunks);
}
I expected to see this happen: No lint or a valid correction
Instead, this happened:
warning: unnecessary closure used with `bool::then`
--> src/main.rs:8:16
|
8 | .chain(need_zlp.then(|| -> &[u8] { &[] }));
| ^^^^^^^^^-------------------------
| |
| help: use `then_some(..)` instead: `then_some({ &[] })`
Version
rustc 1.75.0-nightly (e0d7ed1f4 2023-10-01)
binary: rustc
commit-hash: e0d7ed1f453fb54578cc96dfea859b0e7be15016
commit-date: 2023-10-01
host: x86_64-unknown-linux-gnu
release: 1.75.0-nightly
LLVM version: 17.0.2
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