mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 09:14:20 +00:00
Add ui test for unnecessary_get_then_check
This commit is contained in:
parent
ad319484f1
commit
40cff2d99f
26
tests/ui/unnecessary_get_then_check.fixed
Normal file
26
tests/ui/unnecessary_get_then_check.fixed
Normal file
@ -0,0 +1,26 @@
|
||||
#![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()`
|
||||
}
|
26
tests/ui/unnecessary_get_then_check.rs
Normal file
26
tests/ui/unnecessary_get_then_check.rs
Normal file
@ -0,0 +1,26 @@
|
||||
#![warn(clippy::unnecessary_get_then_check)]
|
||||
|
||||
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
|
||||
|
||||
fn main() {
|
||||
let s: HashSet<String> = HashSet::new();
|
||||
let _ = s.get("a").is_some(); //~ ERROR: unnecessary use of `get("a").is_some()`
|
||||
let _ = s.get("a").is_none(); //~ ERROR: unnecessary use of `get("a").is_none()`
|
||||
|
||||
let s: HashMap<String, ()> = HashMap::new();
|
||||
let _ = s.get("a").is_some(); //~ ERROR: unnecessary use of `get("a").is_some()`
|
||||
let _ = s.get("a").is_none(); //~ ERROR: unnecessary use of `get("a").is_none()`
|
||||
|
||||
let s: BTreeSet<String> = BTreeSet::new();
|
||||
let _ = s.get("a").is_some(); //~ ERROR: unnecessary use of `get("a").is_some()`
|
||||
let _ = s.get("a").is_none(); //~ ERROR: unnecessary use of `get("a").is_none()`
|
||||
|
||||
let s: BTreeMap<String, ()> = BTreeMap::new();
|
||||
let _ = s.get("a").is_some(); //~ ERROR: unnecessary use of `get("a").is_some()`
|
||||
let _ = s.get("a").is_none(); //~ 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.get::<str>("a").is_some(); //~ ERROR: unnecessary use of `get::<str>("a").is_some()`
|
||||
let _ = s.get::<str>("a").is_none(); //~ ERROR: unnecessary use of `get::<str>("a").is_none()`
|
||||
}
|
75
tests/ui/unnecessary_get_then_check.stderr
Normal file
75
tests/ui/unnecessary_get_then_check.stderr
Normal file
@ -0,0 +1,75 @@
|
||||
error: unnecessary use of `get("a").is_some()`
|
||||
--> tests/ui/unnecessary_get_then_check.rs:7:15
|
||||
|
|
||||
LL | let _ = s.get("a").is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^ help: replace it with: `contains("a")`
|
||||
|
|
||||
= note: `-D clippy::unnecessary-get-then-check` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_get_then_check)]`
|
||||
|
||||
error: unnecessary use of `get("a").is_none()`
|
||||
--> tests/ui/unnecessary_get_then_check.rs:8:15
|
||||
|
|
||||
LL | let _ = s.get("a").is_none();
|
||||
| --^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| help: replace it with: `!s.contains("a")`
|
||||
|
||||
error: unnecessary use of `get("a").is_some()`
|
||||
--> tests/ui/unnecessary_get_then_check.rs:11:15
|
||||
|
|
||||
LL | let _ = s.get("a").is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^ help: replace it with: `contains_key("a")`
|
||||
|
||||
error: unnecessary use of `get("a").is_none()`
|
||||
--> tests/ui/unnecessary_get_then_check.rs:12:15
|
||||
|
|
||||
LL | let _ = s.get("a").is_none();
|
||||
| --^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| help: replace it with: `!s.contains_key("a")`
|
||||
|
||||
error: unnecessary use of `get("a").is_some()`
|
||||
--> tests/ui/unnecessary_get_then_check.rs:15:15
|
||||
|
|
||||
LL | let _ = s.get("a").is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^ help: replace it with: `contains("a")`
|
||||
|
||||
error: unnecessary use of `get("a").is_none()`
|
||||
--> tests/ui/unnecessary_get_then_check.rs:16:15
|
||||
|
|
||||
LL | let _ = s.get("a").is_none();
|
||||
| --^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| help: replace it with: `!s.contains("a")`
|
||||
|
||||
error: unnecessary use of `get("a").is_some()`
|
||||
--> tests/ui/unnecessary_get_then_check.rs:19:15
|
||||
|
|
||||
LL | let _ = s.get("a").is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^ help: replace it with: `contains_key("a")`
|
||||
|
||||
error: unnecessary use of `get("a").is_none()`
|
||||
--> tests/ui/unnecessary_get_then_check.rs:20:15
|
||||
|
|
||||
LL | let _ = s.get("a").is_none();
|
||||
| --^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| help: replace it with: `!s.contains_key("a")`
|
||||
|
||||
error: unnecessary use of `get::<str>("a").is_some()`
|
||||
--> tests/ui/unnecessary_get_then_check.rs:24:15
|
||||
|
|
||||
LL | let _ = s.get::<str>("a").is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `contains::<str>("a")`
|
||||
|
||||
error: unnecessary use of `get::<str>("a").is_none()`
|
||||
--> tests/ui/unnecessary_get_then_check.rs:25:15
|
||||
|
|
||||
LL | let _ = s.get::<str>("a").is_none();
|
||||
| --^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| help: replace it with: `!s.contains::<str>("a")`
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
|
Loading…
Reference in New Issue
Block a user