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_with_else.rs:14:5
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
|
|
|
LL | / if !m.contains_key(&k) {
|
|
|
|
LL | | m.insert(k, v);
|
|
|
|
LL | | } else {
|
|
|
|
LL | | m.insert(k, v2);
|
|
|
|
LL | | }
|
|
|
|
| |_____^
|
|
|
|
|
|
|
|
|
= 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)]`
|
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 ~ match m.entry(k) {
|
|
|
|
LL + std::collections::hash_map::Entry::Vacant(e) => {
|
|
|
|
LL + e.insert(v);
|
|
|
|
LL + }
|
|
|
|
LL + std::collections::hash_map::Entry::Occupied(mut e) => {
|
|
|
|
LL + e.insert(v2);
|
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_with_else.rs:20:5
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
|
|
|
LL | / if m.contains_key(&k) {
|
|
|
|
LL | | m.insert(k, v);
|
|
|
|
LL | | } else {
|
|
|
|
LL | | m.insert(k, v2);
|
|
|
|
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 ~ match m.entry(k) {
|
|
|
|
LL + std::collections::hash_map::Entry::Occupied(mut e) => {
|
|
|
|
LL + e.insert(v);
|
|
|
|
LL + }
|
|
|
|
LL + std::collections::hash_map::Entry::Vacant(e) => {
|
|
|
|
LL + e.insert(v2);
|
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_with_else.rs:26:5
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
|
|
|
LL | / if !m.contains_key(&k) {
|
|
|
|
LL | | m.insert(k, v);
|
|
|
|
LL | | } else {
|
|
|
|
LL | | foo();
|
|
|
|
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 + e.insert(v);
|
|
|
|
LL + } else {
|
|
|
|
LL + foo();
|
|
|
|
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_with_else.rs:32:5
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
|
|
|
LL | / if !m.contains_key(&k) {
|
|
|
|
LL | | foo();
|
|
|
|
LL | | } else {
|
|
|
|
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 ~ if let std::collections::hash_map::Entry::Occupied(mut e) = m.entry(k) {
|
|
|
|
LL + e.insert(v);
|
|
|
|
LL + } else {
|
|
|
|
LL + foo();
|
|
|
|
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_with_else.rs:38:5
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
|
|
|
LL | / if !m.contains_key(&k) {
|
|
|
|
LL | | m.insert(k, v);
|
|
|
|
LL | | } else {
|
|
|
|
LL | | m.insert(k, v2);
|
|
|
|
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 ~ match m.entry(k) {
|
|
|
|
LL + std::collections::hash_map::Entry::Vacant(e) => {
|
|
|
|
LL + e.insert(v);
|
|
|
|
LL + }
|
|
|
|
LL + std::collections::hash_map::Entry::Occupied(mut e) => {
|
|
|
|
LL + e.insert(v2);
|
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_with_else.rs:44:5
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
|
|
|
LL | / if m.contains_key(&k) {
|
|
|
|
LL | | if true { m.insert(k, v) } else { m.insert(k, v2) }
|
|
|
|
LL | | } else {
|
|
|
|
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 ~ match m.entry(k) {
|
|
|
|
LL + std::collections::hash_map::Entry::Occupied(mut e) => {
|
|
|
|
LL + if true { Some(e.insert(v)) } else { Some(e.insert(v2)) }
|
|
|
|
LL + }
|
|
|
|
LL + std::collections::hash_map::Entry::Vacant(e) => {
|
|
|
|
LL + e.insert(v);
|
2022-06-16 09:00:32 -05:00
|
|
|
LL + None
|
|
|
|
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_with_else.rs:50:5
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
|
|
|
LL | / if m.contains_key(&k) {
|
|
|
|
LL | | foo();
|
|
|
|
LL | | m.insert(k, v)
|
|
|
|
LL | | } else {
|
|
|
|
LL | | None
|
|
|
|
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::Occupied(mut e) = m.entry(k) {
|
|
|
|
LL + foo();
|
|
|
|
LL + Some(e.insert(v))
|
|
|
|
LL + } else {
|
|
|
|
LL + None
|
|
|
|
LL ~ };
|
2021-04-22 04:31:13 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
error: aborting due to 7 previous errors
|
|
|
|
|