@@ -6,7 +6,7 @@ use clippy_utils::{
6
6
SpanlessEq , can_move_expr_to_closure_no_visit, higher, is_expr_final_block_expr, is_expr_used_or_unified,
7
7
peel_hir_expr_while,
8
8
} ;
9
- use core:: fmt:: { self , Write } ;
9
+ use core:: fmt:: Write ;
10
10
use rustc_errors:: Applicability ;
11
11
use rustc_hir:: hir_id:: HirIdSet ;
12
12
use rustc_hir:: intravisit:: { Visitor , walk_body, walk_expr} ;
@@ -628,11 +628,8 @@ impl<'tcx> InsertSearchResults<'tcx> {
628
628
if is_expr_used_or_unified ( cx. tcx , insertion. call ) {
629
629
write_wrapped ( & mut res, insertion, ctxt, app) ;
630
630
} else {
631
- let _: fmt:: Result = write ! (
632
- res,
633
- "e.insert({})" ,
634
- snippet_with_context( cx, insertion. value. span, ctxt, ".." , app) . 0
635
- ) ;
631
+ let value_str = snippet_with_context ( cx, insertion. value . span , ctxt, ".." , app) . 0 ;
632
+ let _ = write ! ( res, "e.insert({value_str})" ) ;
636
633
}
637
634
span = span. trim_start ( insertion. call . span ) . unwrap_or ( DUMMY_SP ) ;
638
635
}
@@ -644,11 +641,8 @@ impl<'tcx> InsertSearchResults<'tcx> {
644
641
(
645
642
self . snippet ( cx, span, app, |res, insertion, ctxt, app| {
646
643
// Insertion into a map would return `Some(&mut value)`, but the entry returns `&mut value`
647
- let _: fmt:: Result = write ! (
648
- res,
649
- "Some(e.insert({}))" ,
650
- snippet_with_context( cx, insertion. value. span, ctxt, ".." , app) . 0
651
- ) ;
644
+ let value_str = snippet_with_context ( cx, insertion. value . span , ctxt, ".." , app) . 0 ;
645
+ let _ = write ! ( res, "Some(e.insert({value_str}))" ) ;
652
646
} ) ,
653
647
"Occupied(mut e)" ,
654
648
)
@@ -658,19 +652,15 @@ impl<'tcx> InsertSearchResults<'tcx> {
658
652
(
659
653
self . snippet ( cx, span, app, |res, insertion, ctxt, app| {
660
654
// Insertion into a map would return `None`, but the entry returns a mutable reference.
661
- let _: fmt:: Result = if is_expr_final_block_expr ( cx. tcx , insertion. call ) {
655
+ let value_str = snippet_with_context ( cx, insertion. value . span , ctxt, ".." , app) . 0 ;
656
+ let _ = if is_expr_final_block_expr ( cx. tcx , insertion. call ) {
662
657
write ! (
663
658
res,
664
- "e.insert({});\n {}None" ,
665
- snippet_with_context( cx, insertion. value. span, ctxt, ".." , app) . 0 ,
666
- snippet_indent( cx, insertion. call. span) . as_deref( ) . unwrap_or( "" ) ,
659
+ "e.insert({value_str});\n {indent}None" ,
660
+ indent = snippet_indent( cx, insertion. call. span) . as_deref( ) . unwrap_or( "" ) ,
667
661
)
668
662
} else {
669
- write ! (
670
- res,
671
- "{{ e.insert({}); None }}" ,
672
- snippet_with_context( cx, insertion. value. span, ctxt, ".." , app) . 0 ,
673
- )
663
+ write ! ( res, "{{ e.insert({value_str}); None }}" )
674
664
} ;
675
665
} ) ,
676
666
"Vacant(e)" ,
@@ -690,7 +680,8 @@ impl<'tcx> InsertSearchResults<'tcx> {
690
680
".." ,
691
681
app,
692
682
) ) ;
693
- res. push_str ( & snippet_with_context ( cx, insertion. value . span , ctxt, ".." , app) . 0 ) ;
683
+ let value_str = snippet_with_context ( cx, insertion. value . span , ctxt, ".." , app) . 0 ;
684
+ _ = write ! ( res, "{value_str}" ) ;
694
685
span = span. trim_start ( insertion. call . span ) . unwrap_or ( DUMMY_SP ) ;
695
686
} ,
696
687
Edit :: RemoveSemi ( semi_span) => {
0 commit comments