mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-12-18 00:53:31 +00:00
27 lines
1.2 KiB
Rust
27 lines
1.2 KiB
Rust
|
#![warn(clippy::unnecessary_get_then_check)]
|
||
|
|
||
|
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
|
||
|
|
||
|
fn main() {
|
||
|
let s: HashSet<String> = HashSet::new();
|
||
|
let _ = s.contains("a"); //~ ERROR: unnecessary use of `get("a").is_some()`
|
||
|
let _ = !s.contains("a"); //~ ERROR: unnecessary use of `get("a").is_none()`
|
||
|
|
||
|
let s: HashMap<String, ()> = HashMap::new();
|
||
|
let _ = s.contains_key("a"); //~ ERROR: unnecessary use of `get("a").is_some()`
|
||
|
let _ = !s.contains_key("a"); //~ ERROR: unnecessary use of `get("a").is_none()`
|
||
|
|
||
|
let s: BTreeSet<String> = BTreeSet::new();
|
||
|
let _ = s.contains("a"); //~ ERROR: unnecessary use of `get("a").is_some()`
|
||
|
let _ = !s.contains("a"); //~ ERROR: unnecessary use of `get("a").is_none()`
|
||
|
|
||
|
let s: BTreeMap<String, ()> = BTreeMap::new();
|
||
|
let _ = s.contains_key("a"); //~ ERROR: unnecessary use of `get("a").is_some()`
|
||
|
let _ = !s.contains_key("a"); //~ ERROR: unnecessary use of `get("a").is_none()`
|
||
|
|
||
|
// Import to check that the generic annotations are kept!
|
||
|
let s: HashSet<String> = HashSet::new();
|
||
|
let _ = s.contains::<str>("a"); //~ ERROR: unnecessary use of `get::<str>("a").is_some()`
|
||
|
let _ = !s.contains::<str>("a"); //~ ERROR: unnecessary use of `get::<str>("a").is_none()`
|
||
|
}
|