Closed
Description
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