rust-clippy/tests/ui/comparison_to_empty.rs

25 lines
446 B
Rust
Raw Normal View History

//@run-rustfix
#![warn(clippy::comparison_to_empty)]
2023-06-06 20:56:57 +00:00
#![allow(clippy::useless_vec)]
fn main() {
// Disallow comparisons to empty
let s = String::new();
let _ = s == "";
let _ = s != "";
let v = vec![0];
let _ = v == [];
let _ = v != [];
// Allow comparisons to non-empty
let s = String::new();
let _ = s == " ";
let _ = s != " ";
let v = vec![0];
let _ = v == [0];
let _ = v != [0];
}