@@ -708,24 +708,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
708
708
// For now, don't suggest casting with `as`.
709
709
let can_cast = false ;
710
710
711
- let mut prefix = String :: new ( ) ;
712
- if let Some ( hir:: Node :: Expr ( hir :: Expr {
713
- kind : hir :: ExprKind :: Struct ( _ , fields , _ ) , ..
711
+ let prefix = if let Some ( hir :: Node :: Expr ( hir :: Expr {
712
+ kind : hir:: ExprKind :: Struct ( _ , fields , _ ) ,
713
+ ..
714
714
} ) ) = self . tcx . hir ( ) . find ( self . tcx . hir ( ) . get_parent_node ( expr. hir_id ) )
715
715
{
716
716
// `expr` is a literal field for a struct, only suggest if appropriate
717
- for field in * fields {
718
- if field. expr . hir_id == expr. hir_id && field. is_shorthand {
719
- // This is a field literal
720
- prefix = format ! ( "{}: " , field. ident) ;
721
- break ;
722
- }
723
- }
724
- if & prefix == "" {
717
+ match ( * fields)
718
+ . iter ( )
719
+ . find ( |field| field. expr . hir_id == expr. hir_id && field. is_shorthand )
720
+ {
721
+ // This is a field literal
722
+ Some ( field) => format ! ( "{}: " , field. ident) ,
725
723
// Likely a field was meant, but this field wasn't found. Do not suggest anything.
726
- return false ;
724
+ None => return false ,
727
725
}
728
- }
726
+ } else {
727
+ String :: new ( )
728
+ } ;
729
729
if let hir:: ExprKind :: Call ( path, args) = & expr. kind {
730
730
if let ( hir:: ExprKind :: Path ( hir:: QPath :: TypeRelative ( base_ty, path_segment) ) , 1 ) =
731
731
( & path. kind , args. len ( ) )
@@ -817,7 +817,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
817
817
818
818
let suggest_to_change_suffix_or_into =
819
819
|err : & mut DiagnosticBuilder < ' _ > , is_fallible : bool | {
820
- let into_sugg = into_suggestion. clone ( ) ;
821
820
err. span_suggestion (
822
821
expr. span ,
823
822
if literal_is_ty_suffixed ( expr) {
@@ -832,7 +831,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
832
831
} else if is_fallible {
833
832
try_into_suggestion
834
833
} else {
835
- into_sugg
834
+ into_suggestion . clone ( )
836
835
} ,
837
836
Applicability :: MachineApplicable ,
838
837
) ;
0 commit comments