2020-11-05 07:29:48 -06:00
|
|
|
#![warn(clippy::comparison_to_empty)]
|
2023-07-31 16:53:53 -05:00
|
|
|
#![allow(clippy::borrow_deref_ref, clippy::needless_if, clippy::useless_vec)]
|
|
|
|
#![feature(let_chains)]
|
2020-11-05 07:29:48 -06:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// Disallow comparisons to empty
|
|
|
|
let s = String::new();
|
|
|
|
let _ = s == "";
|
|
|
|
let _ = s != "";
|
|
|
|
|
|
|
|
let v = vec![0];
|
|
|
|
let _ = v == [];
|
|
|
|
let _ = v != [];
|
2023-07-31 16:53:53 -05:00
|
|
|
if let [] = &*v {}
|
|
|
|
let s = [0].as_slice();
|
|
|
|
if let [] = s {}
|
|
|
|
if let [] = &*s {}
|
2023-11-02 11:12:25 -05:00
|
|
|
if let [] = &*s
|
|
|
|
&& s == []
|
|
|
|
{}
|
2020-11-05 07:29:48 -06: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-07-31 16:53:53 -05:00
|
|
|
if let [0] = &*v {}
|
|
|
|
let s = [0].as_slice();
|
|
|
|
if let [0] = s {}
|
2023-11-02 11:12:25 -05:00
|
|
|
if let [0] = &*s
|
|
|
|
&& s == [0]
|
|
|
|
{}
|
2024-09-21 12:13:37 -05:00
|
|
|
|
|
|
|
// Also lint the `PartialEq` methods
|
|
|
|
let s = String::new();
|
|
|
|
let _ = s.eq("");
|
|
|
|
let _ = s.ne("");
|
|
|
|
let v = vec![0];
|
|
|
|
let _ = v.eq(&[]);
|
|
|
|
let _ = v.ne(&[]);
|
2020-11-05 07:29:48 -06:00
|
|
|
}
|