@@ -55,7 +55,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
5555 reason = ", as it is not declared as mutable" . to_string ( ) ;
5656 } else {
5757 let name = self . local_names [ local] . expect ( "immutable unnamed local" ) ;
58- reason = format ! ( ", as `{}` is not declared as mutable" , name ) ;
58+ reason = format ! ( ", as `{name }` is not declared as mutable" ) ;
5959 }
6060 }
6161
@@ -88,7 +88,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
8888 reason = ", as it is not declared as mutable" . to_string ( ) ;
8989 } else {
9090 let name = self . upvars [ upvar_index. index ( ) ] . place . to_string ( self . infcx . tcx ) ;
91- reason = format ! ( ", as `{}` is not declared as mutable" , name ) ;
91+ reason = format ! ( ", as `{name }` is not declared as mutable" ) ;
9292 }
9393 }
9494 }
@@ -103,14 +103,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
103103 if self . body . local_decls [ local] . is_ref_to_static ( ) =>
104104 {
105105 if access_place. projection . len ( ) == 1 {
106- item_msg = format ! ( "immutable static item {}" , access_place_desc ) ;
106+ item_msg = format ! ( "immutable static item {access_place_desc}" ) ;
107107 reason = String :: new ( ) ;
108108 } else {
109109 item_msg = access_place_desc;
110110 let local_info = & self . body . local_decls [ local] . local_info ;
111111 if let Some ( box LocalInfo :: StaticRef { def_id, .. } ) = * local_info {
112112 let static_name = & self . infcx . tcx . item_name ( def_id) ;
113- reason = format ! ( ", as `{}` is an immutable static item" , static_name ) ;
113+ reason = format ! ( ", as `{static_name }` is an immutable static item" ) ;
114114 } else {
115115 bug ! ( "is_ref_to_static return true, but not ref to static?" ) ;
116116 }
@@ -148,15 +148,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
148148 let pointer_type = source. describe_for_immutable_place ( self . infcx . tcx ) ;
149149 opt_source = Some ( source) ;
150150 if let Some ( desc) = self . describe_place ( access_place. as_ref ( ) ) {
151- item_msg = format ! ( "`{}`" , desc ) ;
151+ item_msg = format ! ( "`{desc }`" ) ;
152152 reason = match error_access {
153- AccessKind :: Mutate => format ! ( ", which is behind {}" , pointer_type ) ,
153+ AccessKind :: Mutate => format ! ( ", which is behind {pointer_type}" ) ,
154154 AccessKind :: MutableBorrow => {
155- format ! ( ", as it is behind {}" , pointer_type )
155+ format ! ( ", as it is behind {pointer_type}" )
156156 }
157157 }
158158 } else {
159- item_msg = format ! ( "data in {}" , pointer_type ) ;
159+ item_msg = format ! ( "data in {pointer_type}" ) ;
160160 reason = String :: new ( ) ;
161161 }
162162 }
@@ -362,29 +362,27 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
362362
363363 let upvar_hir_id = captured_place. get_root_variable ( ) ;
364364
365- if let Some ( Node :: Binding ( pat) ) = self . infcx . tcx . hir ( ) . find ( upvar_hir_id) {
366- if let hir:: PatKind :: Binding (
365+ if let Some ( Node :: Binding ( pat) ) = self . infcx . tcx . hir ( ) . find ( upvar_hir_id)
366+ && let hir:: PatKind :: Binding (
367367 hir:: BindingAnnotation :: Unannotated ,
368368 _,
369369 upvar_ident,
370370 _,
371371 ) = pat. kind
372- {
373- err. span_suggestion (
374- upvar_ident. span ,
375- "consider changing this to be mutable" ,
376- format ! ( "mut {}" , upvar_ident. name) ,
377- Applicability :: MachineApplicable ,
378- ) ;
379- }
372+ {
373+ err. span_suggestion (
374+ upvar_ident. span ,
375+ "consider changing this to be mutable" ,
376+ format ! ( "mut {}" , upvar_ident. name) ,
377+ Applicability :: MachineApplicable ,
378+ ) ;
380379 }
381380
382381 let tcx = self . infcx . tcx ;
383382 if let ty:: Ref ( _, ty, Mutability :: Mut ) = the_place_err. ty ( self . body , tcx) . ty . kind ( )
383+ && let ty:: Closure ( id, _) = * ty. kind ( )
384384 {
385- if let ty:: Closure ( id, _) = * ty. kind ( ) {
386- self . show_mutating_upvar ( tcx, id, the_place_err, & mut err) ;
387- }
385+ self . show_mutating_upvar ( tcx, id, the_place_err, & mut err) ;
388386 }
389387 }
390388
@@ -544,8 +542,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
544542 err. span_suggestion (
545543 err_help_span,
546544 & format ! (
547- "consider changing this to be a mutable {}" ,
548- pointer_desc
545+ "consider changing this to be a mutable {pointer_desc}"
549546 ) ,
550547 suggested_code,
551548 Applicability :: MachineApplicable ,
@@ -554,8 +551,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
554551 err. span_suggestion (
555552 x,
556553 & format ! (
557- "consider changing that to be a mutable {}" ,
558- pointer_desc
554+ "consider changing that to be a mutable {pointer_desc}"
559555 ) ,
560556 suggested_code,
561557 Applicability :: MachineApplicable ,
@@ -606,15 +602,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
606602 Some ( BorrowedContentSource :: OverloadedDeref ( ty) ) => {
607603 err. help ( & format ! (
608604 "trait `DerefMut` is required to modify through a dereference, \
609- but it is not implemented for `{}`",
610- ty,
605+ but it is not implemented for `{ty}`",
611606 ) ) ;
612607 }
613608 Some ( BorrowedContentSource :: OverloadedIndex ( ty) ) => {
614609 err. help ( & format ! (
615610 "trait `IndexMut` is required to modify indexed content, \
616- but it is not implemented for `{}`",
617- ty,
611+ but it is not implemented for `{ty}`",
618612 ) ) ;
619613 }
620614 _ => ( ) ,
@@ -724,18 +718,18 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
724718 ty:: UpvarCapture :: ByRef (
725719 ty:: BorrowKind :: MutBorrow | ty:: BorrowKind :: UniqueImmBorrow ,
726720 ) => {
727- capture_reason = format ! ( "mutable borrow of `{}`" , upvar ) ;
721+ capture_reason = format ! ( "mutable borrow of `{upvar }`" ) ;
728722 }
729723 ty:: UpvarCapture :: ByValue => {
730- capture_reason = format ! ( "possible mutation of `{}`" , upvar ) ;
724+ capture_reason = format ! ( "possible mutation of `{upvar }`" ) ;
731725 }
732- _ => bug ! ( "upvar `{}` borrowed, but not mutably" , upvar ) ,
726+ _ => bug ! ( "upvar `{upvar }` borrowed, but not mutably" ) ,
733727 }
734728 break ;
735729 }
736730 }
737731 if capture_reason. is_empty ( ) {
738- bug ! ( "upvar `{}` borrowed, but cannot find reason" , upvar ) ;
732+ bug ! ( "upvar `{upvar }` borrowed, but cannot find reason" ) ;
739733 }
740734 capture_reason
741735 } else {
@@ -829,27 +823,27 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
829823 . as_str ( )
830824 . starts_with ( & original_method_ident. name . to_string ( ) )
831825 } )
832- . map ( |ident| format ! ( "{}()" , ident ) )
826+ . map ( |ident| format ! ( "{ident }()" ) )
833827 . peekable ( )
834828 } ) ;
835829
836- if let Some ( mut suggestions) = opt_suggestions {
837- if suggestions. peek ( ) . is_some ( ) {
838- err . span_suggestions (
839- * span ,
840- "use mutable method" ,
841- suggestions ,
842- Applicability :: MaybeIncorrect ,
843- ) ;
844- }
830+ if let Some ( mut suggestions) = opt_suggestions
831+ && suggestions. peek ( ) . is_some ( )
832+ {
833+ err . span_suggestions (
834+ * span ,
835+ "use mutable method" ,
836+ suggestions ,
837+ Applicability :: MaybeIncorrect ,
838+ ) ;
845839 }
846840 }
847841 } ;
848842 }
849843
850844 /// Targeted error when encountering an `FnMut` closure where an `Fn` closure was expected.
851845 fn expected_fn_found_fn_mut_call ( & self , err : & mut Diagnostic , sp : Span , act : & str ) {
852- err. span_label ( sp, format ! ( "cannot {}" , act ) ) ;
846+ err. span_label ( sp, format ! ( "cannot {act}" ) ) ;
853847
854848 let hir = self . infcx . tcx . hir ( ) ;
855849 let closure_id = self . mir_hir_id ( ) ;
@@ -1011,35 +1005,35 @@ fn suggest_ampmut<'tcx>(
10111005 opt_assignment_rhs_span : Option < Span > ,
10121006 opt_ty_info : Option < Span > ,
10131007) -> ( Span , String ) {
1014- if let Some ( assignment_rhs_span) = opt_assignment_rhs_span {
1015- if let Ok ( src) = tcx. sess . source_map ( ) . span_to_snippet ( assignment_rhs_span) {
1016- let is_mutbl = |ty : & str | -> bool {
1017- if let Some ( rest) = ty. strip_prefix ( "mut" ) {
1018- match rest. chars ( ) . next ( ) {
1019- // e.g. `&mut x`
1020- Some ( c) if c. is_whitespace ( ) => true ,
1021- // e.g. `&mut(x)`
1022- Some ( '(' ) => true ,
1023- // e.g. `&mut{x}`
1024- Some ( '{' ) => true ,
1025- // e.g. `&mutablevar`
1026- _ => false ,
1027- }
1028- } else {
1029- false
1030- }
1031- } ;
1032- if let ( true , Some ( ws_pos) ) = ( src. starts_with ( "&'" ) , src. find ( char:: is_whitespace) ) {
1033- let lt_name = & src[ 1 ..ws_pos] ;
1034- let ty = src[ ws_pos..] . trim_start ( ) ;
1035- if !is_mutbl ( ty) {
1036- return ( assignment_rhs_span, format ! ( "&{} mut {}" , lt_name, ty) ) ;
1037- }
1038- } else if let Some ( stripped) = src. strip_prefix ( '&' ) {
1039- let stripped = stripped. trim_start ( ) ;
1040- if !is_mutbl ( stripped) {
1041- return ( assignment_rhs_span, format ! ( "&mut {}" , stripped) ) ;
1008+ if let Some ( assignment_rhs_span) = opt_assignment_rhs_span
1009+ && let Ok ( src) = tcx. sess . source_map ( ) . span_to_snippet ( assignment_rhs_span)
1010+ {
1011+ let is_mutbl = |ty : & str | -> bool {
1012+ if let Some ( rest) = ty. strip_prefix ( "mut" ) {
1013+ match rest. chars ( ) . next ( ) {
1014+ // e.g. `&mut x`
1015+ Some ( c) if c. is_whitespace ( ) => true ,
1016+ // e.g. `&mut(x)`
1017+ Some ( '(' ) => true ,
1018+ // e.g. `&mut{x}`
1019+ Some ( '{' ) => true ,
1020+ // e.g. `&mutablevar`
1021+ _ => false ,
10421022 }
1023+ } else {
1024+ false
1025+ }
1026+ } ;
1027+ if let ( true , Some ( ws_pos) ) = ( src. starts_with ( "&'" ) , src. find ( char:: is_whitespace) ) {
1028+ let lt_name = & src[ 1 ..ws_pos] ;
1029+ let ty = src[ ws_pos..] . trim_start ( ) ;
1030+ if !is_mutbl ( ty) {
1031+ return ( assignment_rhs_span, format ! ( "&{lt_name} mut {ty}" ) ) ;
1032+ }
1033+ } else if let Some ( stripped) = src. strip_prefix ( '&' ) {
1034+ let stripped = stripped. trim_start ( ) ;
1035+ if !is_mutbl ( stripped) {
1036+ return ( assignment_rhs_span, format ! ( "&mut {stripped}" ) ) ;
10431037 }
10441038 }
10451039 }
@@ -1054,12 +1048,12 @@ fn suggest_ampmut<'tcx>(
10541048 None => local_decl. source_info . span ,
10551049 } ;
10561050
1057- if let Ok ( src) = tcx. sess . source_map ( ) . span_to_snippet ( highlight_span) {
1058- if let ( true , Some ( ws_pos) ) = ( src. starts_with ( "&'" ) , src. find ( char:: is_whitespace) ) {
1059- let lt_name = & src [ 1 ..ws_pos ] ;
1060- let ty = & src[ ws_pos.. ] ;
1061- return ( highlight_span , format ! ( "&{} mut{}" , lt_name , ty ) ) ;
1062- }
1051+ if let Ok ( src) = tcx. sess . source_map ( ) . span_to_snippet ( highlight_span)
1052+ && let ( true , Some ( ws_pos) ) = ( src. starts_with ( "&'" ) , src. find ( char:: is_whitespace) )
1053+ {
1054+ let lt_name = & src[ 1 ..ws_pos ] ;
1055+ let ty = & src [ ws_pos.. ] ;
1056+ return ( highlight_span , format ! ( "&{} mut{}" , lt_name , ty ) ) ;
10631057 }
10641058
10651059 let ty_mut = local_decl. ty . builtin_deref ( true ) . unwrap ( ) ;
0 commit comments