Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unnecessary_lazy_evaluations suggests wrong fix #11672

Open
barafael opened this issue Oct 15, 2023 · 1 comment · Fixed by #11673
Open

unnecessary_lazy_evaluations suggests wrong fix #11672

barafael opened this issue Oct 15, 2023 · 1 comment · Fixed by #11673
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@barafael
Copy link

barafael commented Oct 15, 2023

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

@barafael barafael added the C-bug Category: Clippy is not doing the correct thing label Oct 15, 2023
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Oct 15, 2023
@bors bors closed this as completed in 9f27b15 Oct 16, 2023
@Jarcho
Copy link
Contributor

Jarcho commented Oct 16, 2023

This wasn't actually fixed, it just won't be changed by clippy fix.

@Jarcho Jarcho reopened this Oct 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants