2023-04-20 09:37:15 -05:00
|
|
|
//@run-rustfix
|
2020-10-25 18:31:25 -05:00
|
|
|
|
|
|
|
#![warn(clippy::comparison_to_empty)]
|
2023-06-26 00:20:31 -05:00
|
|
|
#![allow(clippy::borrow_deref_ref, clippy::needless_if, clippy::useless_vec)]
|
|
|
|
#![feature(let_chains)]
|
2020-10-25 18:31:25 -05:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// Disallow comparisons to empty
|
|
|
|
let s = String::new();
|
|
|
|
let _ = s.is_empty();
|
|
|
|
let _ = !s.is_empty();
|
|
|
|
|
|
|
|
let v = vec![0];
|
|
|
|
let _ = v.is_empty();
|
|
|
|
let _ = !v.is_empty();
|
2023-06-26 00:20:31 -05:00
|
|
|
if (*v).is_empty() {}
|
|
|
|
let s = [0].as_slice();
|
|
|
|
if s.is_empty() {}
|
|
|
|
if s.is_empty() {}
|
|
|
|
if s.is_empty() && s.is_empty() {}
|
2020-10-25 18:31:25 -05:00
|
|
|
|
|
|
|
// Allow comparisons to non-empty
|
|
|
|
let s = String::new();
|
|
|
|
let _ = s == " ";
|
|
|
|
let _ = s != " ";
|
|
|
|
|
|
|
|
let v = vec![0];
|
|
|
|
let _ = v == [0];
|
|
|
|
let _ = v != [0];
|
2023-06-26 00:20:31 -05:00
|
|
|
if let [0] = &*v {}
|
|
|
|
let s = [0].as_slice();
|
|
|
|
if let [0] = s {}
|
|
|
|
if let [0] = &*s && s == [0] {}
|
2020-10-25 18:31:25 -05:00
|
|
|
}
|