2021-04-22 04:31:13 -05:00
|
|
|
error: usage of `contains_key` followed by `insert` on a `HashMap`
|
2024-02-17 06:16:29 -06:00
|
|
|
--> tests/ui/entry.rs:24:5
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
|
|
|
LL | / if !m.contains_key(&k) {
|
|
|
|
LL | | m.insert(k, v);
|
|
|
|
LL | | }
|
2023-07-17 03:19:29 -05:00
|
|
|
| |_____^ help: try: `m.entry(k).or_insert(v);`
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
|
|
|
= note: `-D clippy::map-entry` implied by `-D warnings`
|
2023-08-01 07:02:21 -05:00
|
|
|
= help: to override `-D warnings` add `#[allow(clippy::map_entry)]`
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
|
|
error: usage of `contains_key` followed by `insert` on a `HashMap`
|
2024-02-17 06:16:29 -06:00
|
|
|
--> tests/ui/entry.rs:29:5
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
|
|
|
LL | / if !m.contains_key(&k) {
|
|
|
|
LL | | if true {
|
|
|
|
LL | | m.insert(k, v);
|
|
|
|
LL | | } else {
|
|
|
|
LL | | m.insert(k, v2);
|
|
|
|
LL | | }
|
|
|
|
LL | | }
|
|
|
|
| |_____^
|
|
|
|
|
|
2023-07-17 03:19:29 -05:00
|
|
|
help: try
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
2021-08-11 09:21:33 -05:00
|
|
|
LL ~ m.entry(k).or_insert_with(|| {
|
|
|
|
LL + if true {
|
|
|
|
LL + v
|
|
|
|
LL + } else {
|
|
|
|
LL + v2
|
|
|
|
LL + }
|
2022-06-16 09:00:32 -05:00
|
|
|
LL + });
|
|
|
|
|
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
|
|
error: usage of `contains_key` followed by `insert` on a `HashMap`
|
2024-02-17 06:16:29 -06:00
|
|
|
--> tests/ui/entry.rs:38:5
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
|
|
|
LL | / if !m.contains_key(&k) {
|
|
|
|
LL | | if true {
|
|
|
|
LL | | m.insert(k, v)
|
|
|
|
LL | | } else {
|
|
|
|
LL | | m.insert(k, v2)
|
|
|
|
LL | | };
|
|
|
|
LL | | }
|
|
|
|
| |_____^
|
|
|
|
|
|
2023-07-17 03:19:29 -05:00
|
|
|
help: try
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
2021-08-11 09:21:33 -05:00
|
|
|
LL ~ m.entry(k).or_insert_with(|| {
|
|
|
|
LL + if true {
|
|
|
|
LL + v
|
|
|
|
LL + } else {
|
|
|
|
LL + v2
|
|
|
|
LL + }
|
2022-06-16 09:00:32 -05:00
|
|
|
LL + });
|
|
|
|
|
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
|
|
error: usage of `contains_key` followed by `insert` on a `HashMap`
|
2024-02-17 06:16:29 -06:00
|
|
|
--> tests/ui/entry.rs:47:5
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
|
|
|
LL | / if !m.contains_key(&k) {
|
|
|
|
LL | | if true {
|
|
|
|
LL | | m.insert(k, v);
|
|
|
|
LL | | } else {
|
|
|
|
... |
|
|
|
|
LL | | }
|
|
|
|
LL | | }
|
|
|
|
| |_____^
|
|
|
|
|
|
2023-07-17 03:19:29 -05:00
|
|
|
help: try
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
2021-08-11 09:21:33 -05:00
|
|
|
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;
|
2022-06-16 09:00:32 -05:00
|
|
|
LL + }
|
|
|
|
LL + }
|
|
|
|
|
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
|
|
error: usage of `contains_key` followed by `insert` on a `HashMap`
|
2024-02-17 06:16:29 -06:00
|
|
|
--> tests/ui/entry.rs:57:5
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
|
|
|
LL | / if !m.contains_key(&k) {
|
|
|
|
LL | | foo();
|
|
|
|
LL | | m.insert(k, v);
|
|
|
|
LL | | }
|
|
|
|
| |_____^
|
|
|
|
|
|
2023-07-17 03:19:29 -05:00
|
|
|
help: try
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
2021-08-11 09:21:33 -05:00
|
|
|
LL ~ m.entry(k).or_insert_with(|| {
|
|
|
|
LL + foo();
|
|
|
|
LL + v
|
|
|
|
LL + });
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
error: usage of `contains_key` followed by `insert` on a `HashMap`
|
2024-02-17 06:16:29 -06:00
|
|
|
--> tests/ui/entry.rs:63:5
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
|
|
|
LL | / if !m.contains_key(&k) {
|
|
|
|
LL | | match 0 {
|
|
|
|
LL | | 1 if true => {
|
|
|
|
LL | | m.insert(k, v);
|
|
|
|
... |
|
|
|
|
LL | | };
|
|
|
|
LL | | }
|
|
|
|
| |_____^
|
|
|
|
|
|
2023-07-17 03:19:29 -05:00
|
|
|
help: try
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
2021-08-11 09:21:33 -05:00
|
|
|
LL ~ m.entry(k).or_insert_with(|| {
|
|
|
|
LL + match 0 {
|
|
|
|
LL + 1 if true => {
|
|
|
|
LL + v
|
|
|
|
LL + },
|
|
|
|
LL + _ => {
|
2022-06-16 09:00:32 -05:00
|
|
|
LL + v2
|
|
|
|
LL + },
|
|
|
|
LL + }
|
|
|
|
LL + });
|
|
|
|
|
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
|
|
error: usage of `contains_key` followed by `insert` on a `HashMap`
|
2024-02-17 06:16:29 -06:00
|
|
|
--> tests/ui/entry.rs:75:5
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
|
|
|
LL | / if !m.contains_key(&k) {
|
|
|
|
LL | | match 0 {
|
|
|
|
LL | | 0 => foo(),
|
|
|
|
LL | | _ => {
|
|
|
|
... |
|
|
|
|
LL | | };
|
|
|
|
LL | | }
|
|
|
|
| |_____^
|
|
|
|
|
|
2023-07-17 03:19:29 -05:00
|
|
|
help: try
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
2021-08-11 09:21:33 -05:00
|
|
|
LL ~ if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) {
|
|
|
|
LL + match 0 {
|
|
|
|
LL + 0 => foo(),
|
|
|
|
LL + _ => {
|
|
|
|
LL + e.insert(v2);
|
|
|
|
LL + },
|
2022-06-16 09:00:32 -05:00
|
|
|
LL + };
|
|
|
|
LL + }
|
|
|
|
|
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
|
|
error: usage of `contains_key` followed by `insert` on a `HashMap`
|
2024-02-17 06:16:29 -06:00
|
|
|
--> tests/ui/entry.rs:85:5
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
|
|
|
LL | / if !m.contains_key(&k) {
|
|
|
|
LL | | foo();
|
|
|
|
LL | | match 0 {
|
|
|
|
LL | | 0 if false => {
|
|
|
|
... |
|
|
|
|
LL | | }
|
|
|
|
LL | | }
|
|
|
|
| |_____^
|
|
|
|
|
|
2023-07-17 03:19:29 -05:00
|
|
|
help: try
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
2021-08-11 09:21:33 -05:00
|
|
|
LL ~ m.entry(k).or_insert_with(|| {
|
|
|
|
LL + foo();
|
|
|
|
LL + match 0 {
|
|
|
|
LL + 0 if false => {
|
|
|
|
LL + v
|
|
|
|
LL + },
|
2022-06-16 09:00:32 -05:00
|
|
|
LL + 1 => {
|
|
|
|
LL + foo();
|
|
|
|
LL + v
|
|
|
|
LL + },
|
|
|
|
LL + 2 | 3 => {
|
|
|
|
LL + for _ in 0..2 {
|
|
|
|
LL + foo();
|
|
|
|
LL + }
|
|
|
|
LL + if true {
|
|
|
|
LL + v
|
|
|
|
LL + } else {
|
|
|
|
LL + v2
|
|
|
|
LL + }
|
|
|
|
LL + },
|
|
|
|
LL + _ => {
|
|
|
|
LL + v2
|
|
|
|
LL + },
|
|
|
|
LL + }
|
|
|
|
LL + });
|
|
|
|
|
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
|
|
error: usage of `contains_key` followed by `insert` on a `HashMap`
|
2024-02-17 06:16:29 -06:00
|
|
|
--> tests/ui/entry.rs:119:5
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
|
|
|
LL | / if !m.contains_key(&m!(k)) {
|
|
|
|
LL | | m.insert(m!(k), m!(v));
|
|
|
|
LL | | }
|
2023-07-17 03:19:29 -05:00
|
|
|
| |_____^ help: try: `m.entry(m!(k)).or_insert_with(|| m!(v));`
|
2021-04-22 04:31:13 -05:00
|
|
|
|
2021-09-08 09:31:47 -05:00
|
|
|
error: usage of `contains_key` followed by `insert` on a `HashMap`
|
2024-02-17 06:16:29 -06:00
|
|
|
--> tests/ui/entry.rs:151:5
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
|
|
|
LL | / if !m.contains_key(&k) {
|
2021-09-08 09:31:47 -05:00
|
|
|
LL | | let x = (String::new(), String::new());
|
|
|
|
LL | | let _ = x.0;
|
2021-04-22 04:31:13 -05:00
|
|
|
LL | | m.insert(k, v);
|
|
|
|
LL | | }
|
|
|
|
| |_____^
|
|
|
|
|
|
2023-07-17 03:19:29 -05:00
|
|
|
help: try
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
2021-09-08 09:31:47 -05:00
|
|
|
LL ~ m.entry(k).or_insert_with(|| {
|
|
|
|
LL + let x = (String::new(), String::new());
|
|
|
|
LL + let _ = x.0;
|
|
|
|
LL + v
|
|
|
|
LL + });
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
|
|
|
|
2024-03-16 08:15:45 -05:00
|
|
|
error: usage of `contains_key` followed by `insert` on a `HashMap`
|
|
|
|
--> tests/ui/entry.rs:184:5
|
|
|
|
|
|
|
|
|
LL | / if !map.contains_key(&1) {
|
|
|
|
LL | | let Some(1) = Some(2) else {
|
|
|
|
LL | | return None;
|
|
|
|
LL | | };
|
|
|
|
LL | | map.insert(1, 42);
|
|
|
|
LL | | }
|
|
|
|
| |_____^
|
|
|
|
|
|
|
|
|
help: try
|
|
|
|
|
|
|
|
|
LL ~ if let std::collections::hash_map::Entry::Vacant(e) = map.entry(1) {
|
|
|
|
LL + let Some(1) = Some(2) else {
|
|
|
|
LL + return None;
|
|
|
|
LL + };
|
|
|
|
LL + e.insert(42);
|
|
|
|
LL + }
|
|
|
|
|
|
|
|
|
|
|
|
|
error: aborting due to 11 previous errors
|
2021-04-22 04:31:13 -05:00
|
|
|
|