ce5e927713
Fix false positives where the map is used before inserting into the map. Fix false positives where two insertions happen. Suggest using `if let Entry::Vacant(e) = _.entry(_)` when `or_insert` might be a semantic change
172 lines
3.9 KiB
Plaintext
172 lines
3.9 KiB
Plaintext
error: usage of `contains_key` followed by `insert` on a `HashMap`
|
|
--> $DIR/entry.rs:16:5
|
|
|
|
|
LL | / if !m.contains_key(&k) {
|
|
LL | | m.insert(k, v);
|
|
LL | | }
|
|
| |_____^ help: try this: `m.entry(k).or_insert(v);`
|
|
|
|
|
= note: `-D clippy::map-entry` implied by `-D warnings`
|
|
|
|
error: usage of `contains_key` followed by `insert` on a `HashMap`
|
|
--> $DIR/entry.rs:20:5
|
|
|
|
|
LL | / if !m.contains_key(&k) {
|
|
LL | | if true {
|
|
LL | | m.insert(k, v);
|
|
LL | | } else {
|
|
LL | | m.insert(k, v2);
|
|
LL | | }
|
|
LL | | }
|
|
| |_____^
|
|
|
|
|
help: try this
|
|
|
|
|
LL | if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) {
|
|
LL | if true {
|
|
LL | e.insert(v);
|
|
LL | } else {
|
|
LL | e.insert(v2);
|
|
LL | }
|
|
...
|
|
|
|
error: usage of `contains_key` followed by `insert` on a `HashMap`
|
|
--> $DIR/entry.rs:28:5
|
|
|
|
|
LL | / if !m.contains_key(&k) {
|
|
LL | | if true {
|
|
LL | | m.insert(k, v);
|
|
LL | | } else {
|
|
... |
|
|
LL | | }
|
|
LL | | }
|
|
| |_____^
|
|
|
|
|
help: try this
|
|
|
|
|
LL | if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) {
|
|
LL | if true {
|
|
LL | e.insert(v);
|
|
LL | } else {
|
|
LL | e.insert(v2);
|
|
LL | return;
|
|
...
|
|
|
|
error: usage of `contains_key` followed by `insert` on a `HashMap`
|
|
--> $DIR/entry.rs:37:5
|
|
|
|
|
LL | / if !m.contains_key(&k) {
|
|
LL | | foo();
|
|
LL | | m.insert(k, v);
|
|
LL | | }
|
|
| |_____^
|
|
|
|
|
help: try this
|
|
|
|
|
LL | if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) {
|
|
LL | foo();
|
|
LL | e.insert(v);
|
|
LL | }
|
|
|
|
|
|
|
error: usage of `contains_key` followed by `insert` on a `HashMap`
|
|
--> $DIR/entry.rs:42:5
|
|
|
|
|
LL | / if !m.contains_key(&k) {
|
|
LL | | match 0 {
|
|
LL | | 1 if true => {
|
|
LL | | m.insert(k, v);
|
|
... |
|
|
LL | | };
|
|
LL | | }
|
|
| |_____^
|
|
|
|
|
help: try this
|
|
|
|
|
LL | if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) {
|
|
LL | match 0 {
|
|
LL | 1 if true => {
|
|
LL | e.insert(v);
|
|
LL | },
|
|
LL | _ => {
|
|
...
|
|
|
|
error: usage of `contains_key` followed by `insert` on a `HashMap`
|
|
--> $DIR/entry.rs:53:5
|
|
|
|
|
LL | / if !m.contains_key(&k) {
|
|
LL | | match 0 {
|
|
LL | | 0 => {},
|
|
LL | | 1 => {
|
|
... |
|
|
LL | | };
|
|
LL | | }
|
|
| |_____^
|
|
|
|
|
help: try this
|
|
|
|
|
LL | if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) {
|
|
LL | match 0 {
|
|
LL | 0 => {},
|
|
LL | 1 => {
|
|
LL | e.insert(v);
|
|
LL | },
|
|
...
|
|
|
|
error: usage of `contains_key` followed by `insert` on a `HashMap`
|
|
--> $DIR/entry.rs:65:5
|
|
|
|
|
LL | / if !m.contains_key(&k) {
|
|
LL | | foo();
|
|
LL | | match 0 {
|
|
LL | | 0 if false => {
|
|
... |
|
|
LL | | }
|
|
LL | | }
|
|
| |_____^
|
|
|
|
|
help: try this
|
|
|
|
|
LL | if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) {
|
|
LL | foo();
|
|
LL | match 0 {
|
|
LL | 0 if false => {
|
|
LL | e.insert(v);
|
|
LL | },
|
|
...
|
|
|
|
error: usage of `contains_key` followed by `insert` on a `HashMap`
|
|
--> $DIR/entry.rs:91:5
|
|
|
|
|
LL | / if !m.contains_key(&m!(k)) {
|
|
LL | | m.insert(m!(k), m!(v));
|
|
LL | | }
|
|
| |_____^
|
|
|
|
|
help: try this
|
|
|
|
|
LL | if let std::collections::hash_map::Entry::Vacant(e) = m.entry(m!(k)) {
|
|
LL | e.insert(m!(v));
|
|
LL | }
|
|
|
|
|
|
|
error: usage of `contains_key` followed by `insert` on a `BTreeMap`
|
|
--> $DIR/entry.rs:97:5
|
|
|
|
|
LL | / if !m.contains_key(&k) {
|
|
LL | | m.insert(k, v);
|
|
LL | | foo();
|
|
LL | | }
|
|
| |_____^
|
|
|
|
|
help: try this
|
|
|
|
|
LL | if let std::collections::btree_map::Entry::Vacant(e) = m.entry(k) {
|
|
LL | e.insert(v);
|
|
LL | foo();
|
|
LL | }
|
|
|
|
|
|
|
error: aborting due to 9 previous errors
|
|
|