2024-05-31 10:58:19 -05:00
|
|
|
#![allow(unused)]
|
|
|
|
#![allow(clippy::nonminimal_bool)]
|
|
|
|
#![allow(clippy::needless_borrow)]
|
2024-06-03 13:04:07 -05:00
|
|
|
#![warn(clippy::set_contains_or_insert)]
|
2024-05-31 10:58:19 -05:00
|
|
|
|
2024-07-05 12:10:29 -05:00
|
|
|
use std::collections::{BTreeSet, HashSet};
|
2024-05-31 10:58:19 -05:00
|
|
|
|
2024-07-05 12:10:29 -05:00
|
|
|
fn should_warn_hashset() {
|
|
|
|
let mut set = HashSet::new();
|
|
|
|
let value = 5;
|
|
|
|
|
|
|
|
if !set.contains(&value) {
|
|
|
|
set.insert(value);
|
|
|
|
println!("Just a comment");
|
|
|
|
}
|
|
|
|
|
|
|
|
if set.contains(&value) {
|
|
|
|
set.insert(value);
|
|
|
|
println!("Just a comment");
|
|
|
|
}
|
|
|
|
|
|
|
|
if !set.contains(&value) {
|
|
|
|
set.insert(value);
|
|
|
|
}
|
2024-05-31 10:58:19 -05:00
|
|
|
|
2024-07-05 12:10:29 -05:00
|
|
|
if !!set.contains(&value) {
|
|
|
|
set.insert(value);
|
|
|
|
println!("Just a comment");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (&set).contains(&value) {
|
|
|
|
set.insert(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
let borrow_value = &6;
|
|
|
|
if !set.contains(borrow_value) {
|
|
|
|
set.insert(*borrow_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
let borrow_set = &mut set;
|
|
|
|
if !borrow_set.contains(&value) {
|
|
|
|
borrow_set.insert(value);
|
|
|
|
}
|
2024-05-31 10:58:19 -05:00
|
|
|
}
|
|
|
|
|
2024-07-05 12:10:29 -05:00
|
|
|
fn should_not_warn_hashset() {
|
2024-05-31 10:58:19 -05:00
|
|
|
let mut set = HashSet::new();
|
|
|
|
let value = 5;
|
2024-07-05 12:10:29 -05:00
|
|
|
let another_value = 6;
|
|
|
|
|
|
|
|
if !set.contains(&value) {
|
|
|
|
set.insert(another_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if !set.contains(&value) {
|
|
|
|
println!("Just a comment");
|
|
|
|
}
|
|
|
|
|
|
|
|
if simply_true() {
|
|
|
|
set.insert(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if !set.contains(&value) {
|
|
|
|
set.replace(value); //it is not insert
|
|
|
|
println!("Just a comment");
|
|
|
|
}
|
|
|
|
|
|
|
|
if set.contains(&value) {
|
|
|
|
println!("value is already in set");
|
|
|
|
} else {
|
|
|
|
set.insert(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn should_warn_btreeset() {
|
|
|
|
let mut set = BTreeSet::new();
|
|
|
|
let value = 5;
|
2024-05-31 10:58:19 -05:00
|
|
|
|
|
|
|
if !set.contains(&value) {
|
|
|
|
set.insert(value);
|
|
|
|
println!("Just a comment");
|
|
|
|
}
|
|
|
|
|
|
|
|
if set.contains(&value) {
|
|
|
|
set.insert(value);
|
|
|
|
println!("Just a comment");
|
|
|
|
}
|
|
|
|
|
|
|
|
if !set.contains(&value) {
|
|
|
|
set.insert(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if !!set.contains(&value) {
|
|
|
|
set.insert(value);
|
|
|
|
println!("Just a comment");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (&set).contains(&value) {
|
|
|
|
set.insert(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
let borrow_value = &6;
|
|
|
|
if !set.contains(borrow_value) {
|
|
|
|
set.insert(*borrow_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
let borrow_set = &mut set;
|
|
|
|
if !borrow_set.contains(&value) {
|
|
|
|
borrow_set.insert(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-05 12:10:29 -05:00
|
|
|
fn should_not_warn_btreeset() {
|
|
|
|
let mut set = BTreeSet::new();
|
2024-05-31 10:58:19 -05:00
|
|
|
let value = 5;
|
|
|
|
let another_value = 6;
|
|
|
|
|
|
|
|
if !set.contains(&value) {
|
|
|
|
set.insert(another_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if !set.contains(&value) {
|
|
|
|
println!("Just a comment");
|
|
|
|
}
|
|
|
|
|
|
|
|
if simply_true() {
|
|
|
|
set.insert(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if !set.contains(&value) {
|
|
|
|
set.replace(value); //it is not insert
|
|
|
|
println!("Just a comment");
|
|
|
|
}
|
2024-06-03 13:04:07 -05:00
|
|
|
|
|
|
|
if set.contains(&value) {
|
|
|
|
println!("value is already in set");
|
|
|
|
} else {
|
|
|
|
set.insert(value);
|
|
|
|
}
|
2024-05-31 10:58:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn simply_true() -> bool {
|
|
|
|
true
|
|
|
|
}
|
2024-07-05 12:10:29 -05:00
|
|
|
|
|
|
|
// This is placed last in order to be able to add new tests without changing line numbers
|
|
|
|
fn main() {
|
|
|
|
should_warn_hashset();
|
|
|
|
should_warn_btreeset();
|
|
|
|
should_not_warn_hashset();
|
|
|
|
should_not_warn_btreeset();
|
|
|
|
}
|