-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
A-lintArea: New lintsArea: New lintsL-correctnessLint: Belongs in the correctness lint groupLint: Belongs in the correctness lint groupT-MIRType: This lint will require working with the MIRType: This lint will require working with the MIR
Description
#[cfg_attr(feature = "cargo-clippy", allow(pedantic))]
fn main() {
let v: Vec<i32> = Vec::new();
println!("{}", do_something(&v));
}
fn do_something(v: &[i32]) -> i32 {
if v.is_empty() {
// v must not be modified in between or be immutable
v[0] // BOOM <- catch this at linttime
} else {
124
}
}
// similar:
// if !v.is_empty() {
// //...
// } else {
// v[0]
// }
There are probably other std::collections where this can also be applied.
The idea of this ticket was inspired by cppcheck :)
llogiq
Metadata
Metadata
Assignees
Labels
A-lintArea: New lintsArea: New lintsL-correctnessLint: Belongs in the correctness lint groupLint: Belongs in the correctness lint groupT-MIRType: This lint will require working with the MIRType: This lint will require working with the MIR