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

redundant_closure makes incorrect suggestion #13895

Open
lapla-cogito opened this issue Dec 29, 2024 · 1 comment · May be fixed by #13896
Open

redundant_closure makes incorrect suggestion #13895

lapla-cogito opened this issue Dec 29, 2024 · 1 comment · May be fixed by #13896
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

@lapla-cogito
Copy link
Contributor

lapla-cogito commented Dec 29, 2024

Summary

redundant_closure lint sometimes makes incorrect suggestion in a no_std environment.

Reproducer

I tried this code:

#![no_std]
extern crate alloc;
use alloc::vec;
use alloc::vec::Vec;

fn main() {
    let _: Option<Vec<u8>>= true.then(|| vec![]);
}

I expected to see this happen:

Suggest code that compiles successfully in a no_std environment, e.g. using alloc::vec::Vec, or not linting.

Instead, this happened:

The following was suggested, which fails to compile:

#![no_std]
extern crate alloc;
use alloc::vec;
use alloc::vec::Vec;

fn main() {
    let _: Option<Vec<u8>>= true.then(std::vec::Vec::new);
}

Version

rustc 1.85.0-nightly (dd84b7d5e 2024-12-27)
binary: rustc
commit-hash: dd84b7d5eec3c20d7fcd13e6450af029d3cece9d
commit-date: 2024-12-27
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.6

Additional Labels

@rustbot label +I-suggestion-causes-error

@lapla-cogito lapla-cogito added the C-bug Category: Clippy is not doing the correct thing label Dec 29, 2024
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Dec 29, 2024
@lapla-cogito
Copy link
Contributor Author

This part is the cause:

span_lint_and_sugg(
cx,
REDUNDANT_CLOSURE,
expr.span,
"redundant closure",
"replace the closure with `Vec::new`",
"std::vec::Vec::new".into(),
Applicability::MachineApplicable,
);

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.

2 participants