@@ -614,24 +614,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
614
614
// For now, don't suggest casting with `as`.
615
615
let can_cast = false ;
616
616
617
- let mut prefix = String :: new ( ) ;
618
- if let Some ( hir:: Node :: Expr ( hir :: Expr {
619
- kind : hir :: ExprKind :: Struct ( _ , fields , _ ) , ..
617
+ let prefix = if let Some ( hir :: Node :: Expr ( hir :: Expr {
618
+ kind : hir:: ExprKind :: Struct ( _ , fields , _ ) ,
619
+ ..
620
620
} ) ) = self . tcx . hir ( ) . find ( self . tcx . hir ( ) . get_parent_node ( expr. hir_id ) )
621
621
{
622
622
// `expr` is a literal field for a struct, only suggest if appropriate
623
- for field in * fields {
624
- if field. expr . hir_id == expr. hir_id && field. is_shorthand {
625
- // This is a field literal
626
- prefix = format ! ( "{}: " , field. ident) ;
627
- break ;
628
- }
629
- }
630
- if & prefix == "" {
623
+ match ( * fields)
624
+ . iter ( )
625
+ . find ( |field| field. expr . hir_id == expr. hir_id && field. is_shorthand )
626
+ {
627
+ // This is a field literal
628
+ Some ( field) => format ! ( "{}: " , field. ident) ,
631
629
// Likely a field was meant, but this field wasn't found. Do not suggest anything.
632
- return false ;
630
+ None => return false ,
633
631
}
634
- }
632
+ } else {
633
+ String :: new ( )
634
+ } ;
635
635
if let hir:: ExprKind :: Call ( path, args) = & expr. kind {
636
636
if let ( hir:: ExprKind :: Path ( hir:: QPath :: TypeRelative ( base_ty, path_segment) ) , 1 ) =
637
637
( & path. kind , args. len ( ) )
@@ -723,7 +723,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
723
723
724
724
let suggest_to_change_suffix_or_into =
725
725
|err : & mut DiagnosticBuilder < ' _ > , is_fallible : bool | {
726
- let into_sugg = into_suggestion. clone ( ) ;
727
726
err. span_suggestion (
728
727
expr. span ,
729
728
if literal_is_ty_suffixed ( expr) {
@@ -738,7 +737,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
738
737
} else if is_fallible {
739
738
try_into_suggestion
740
739
} else {
741
- into_sugg
740
+ into_suggestion . clone ( )
742
741
} ,
743
742
Applicability :: MachineApplicable ,
744
743
) ;
0 commit comments