This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +46
-2
lines changed Expand file tree Collapse file tree 4 files changed +46
-2
lines changed Original file line number Diff line number Diff line change @@ -358,7 +358,7 @@ struct InsertSearcher<'cx, 'tcx> {
358
358
can_use_entry : bool ,
359
359
/// Whether this expression is the final expression in this code path. This may be a statement.
360
360
in_tail_pos : bool ,
361
- // Is this expression a single insert. A slightly better suggestion can be made in this case.
361
+ /// Is this expression a single insert. A slightly better suggestion can be made in this case.
362
362
is_single_insert : bool ,
363
363
/// If the visitor has seen the map being used.
364
364
is_map_used : bool ,
@@ -431,6 +431,9 @@ impl<'tcx> Visitor<'tcx> for InsertSearcher<'_, 'tcx> {
431
431
self . is_single_insert = false ;
432
432
self . visit_expr ( e) ;
433
433
}
434
+ if let Some ( els) = & l. els {
435
+ self . visit_block ( els) ;
436
+ }
434
437
} ,
435
438
StmtKind :: Item ( _) => {
436
439
self . allow_insert_closure &= !self . in_tail_pos ;
Original file line number Diff line number Diff line change @@ -176,4 +176,14 @@ pub fn issue_11935() {
176
176
}
177
177
}
178
178
179
+ fn issue12489(map: &mut HashMap<u64, u64>) -> Option<()> {
180
+ if let std::collections::hash_map::Entry::Vacant(e) = map.entry(1) {
181
+ let Some(1) = Some(2) else {
182
+ return None;
183
+ };
184
+ e.insert(42);
185
+ }
186
+ Some(())
187
+ }
188
+
179
189
fn main() {}
Original file line number Diff line number Diff line change @@ -180,4 +180,14 @@ pub fn issue_11935() {
180
180
}
181
181
}
182
182
183
+ fn issue12489 ( map : & mut HashMap < u64 , u64 > ) -> Option < ( ) > {
184
+ if !map. contains_key ( & 1 ) {
185
+ let Some ( 1 ) = Some ( 2 ) else {
186
+ return None ;
187
+ } ;
188
+ map. insert ( 1 , 42 ) ;
189
+ }
190
+ Some ( ( ) )
191
+ }
192
+
183
193
fn main ( ) { }
Original file line number Diff line number Diff line change @@ -214,5 +214,26 @@ LL + v
214
214
LL + });
215
215
|
216
216
217
- error: aborting due to 10 previous errors
217
+ error: usage of `contains_key` followed by `insert` on a `HashMap`
218
+ --> tests/ui/entry.rs:184:5
219
+ |
220
+ LL | / if !map.contains_key(&1) {
221
+ LL | | let Some(1) = Some(2) else {
222
+ LL | | return None;
223
+ LL | | };
224
+ LL | | map.insert(1, 42);
225
+ LL | | }
226
+ | |_____^
227
+ |
228
+ help: try
229
+ |
230
+ LL ~ if let std::collections::hash_map::Entry::Vacant(e) = map.entry(1) {
231
+ LL + let Some(1) = Some(2) else {
232
+ LL + return None;
233
+ LL + };
234
+ LL + e.insert(42);
235
+ LL + }
236
+ |
237
+
238
+ error: aborting due to 11 previous errors
218
239
You can’t perform that action at this time.
0 commit comments