@@ -55,7 +55,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
55
55
reason = ", as it is not declared as mutable" . to_string ( ) ;
56
56
} else {
57
57
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" ) ;
59
59
}
60
60
}
61
61
@@ -88,7 +88,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
88
88
reason = ", as it is not declared as mutable" . to_string ( ) ;
89
89
} else {
90
90
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" ) ;
92
92
}
93
93
}
94
94
}
@@ -103,14 +103,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
103
103
if self . body . local_decls [ local] . is_ref_to_static ( ) =>
104
104
{
105
105
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}" ) ;
107
107
reason = String :: new ( ) ;
108
108
} else {
109
109
item_msg = access_place_desc;
110
110
let local_info = & self . body . local_decls [ local] . local_info ;
111
111
if let Some ( box LocalInfo :: StaticRef { def_id, .. } ) = * local_info {
112
112
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" ) ;
114
114
} else {
115
115
bug ! ( "is_ref_to_static return true, but not ref to static?" ) ;
116
116
}
@@ -148,15 +148,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
148
148
let pointer_type = source. describe_for_immutable_place ( self . infcx . tcx ) ;
149
149
opt_source = Some ( source) ;
150
150
if let Some ( desc) = self . describe_place ( access_place. as_ref ( ) ) {
151
- item_msg = format ! ( "`{}`" , desc ) ;
151
+ item_msg = format ! ( "`{desc }`" ) ;
152
152
reason = match error_access {
153
- AccessKind :: Mutate => format ! ( ", which is behind {}" , pointer_type ) ,
153
+ AccessKind :: Mutate => format ! ( ", which is behind {pointer_type}" ) ,
154
154
AccessKind :: MutableBorrow => {
155
- format ! ( ", as it is behind {}" , pointer_type )
155
+ format ! ( ", as it is behind {pointer_type}" )
156
156
}
157
157
}
158
158
} else {
159
- item_msg = format ! ( "data in {}" , pointer_type ) ;
159
+ item_msg = format ! ( "data in {pointer_type}" ) ;
160
160
reason = String :: new ( ) ;
161
161
}
162
162
}
@@ -362,29 +362,27 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
362
362
363
363
let upvar_hir_id = captured_place. get_root_variable ( ) ;
364
364
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 (
367
367
hir:: BindingAnnotation :: Unannotated ,
368
368
_,
369
369
upvar_ident,
370
370
_,
371
371
) = 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
+ ) ;
380
379
}
381
380
382
381
let tcx = self . infcx . tcx ;
383
382
if let ty:: Ref ( _, ty, Mutability :: Mut ) = the_place_err. ty ( self . body , tcx) . ty . kind ( )
383
+ && let ty:: Closure ( id, _) = * ty. kind ( )
384
384
{
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) ;
388
386
}
389
387
}
390
388
@@ -544,8 +542,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
544
542
err. span_suggestion (
545
543
err_help_span,
546
544
& format ! (
547
- "consider changing this to be a mutable {}" ,
548
- pointer_desc
545
+ "consider changing this to be a mutable {pointer_desc}"
549
546
) ,
550
547
suggested_code,
551
548
Applicability :: MachineApplicable ,
@@ -554,8 +551,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
554
551
err. span_suggestion (
555
552
x,
556
553
& format ! (
557
- "consider changing that to be a mutable {}" ,
558
- pointer_desc
554
+ "consider changing that to be a mutable {pointer_desc}"
559
555
) ,
560
556
suggested_code,
561
557
Applicability :: MachineApplicable ,
@@ -606,15 +602,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
606
602
Some ( BorrowedContentSource :: OverloadedDeref ( ty) ) => {
607
603
err. help ( & format ! (
608
604
"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}`",
611
606
) ) ;
612
607
}
613
608
Some ( BorrowedContentSource :: OverloadedIndex ( ty) ) => {
614
609
err. help ( & format ! (
615
610
"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}`",
618
612
) ) ;
619
613
}
620
614
_ => ( ) ,
@@ -724,18 +718,18 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
724
718
ty:: UpvarCapture :: ByRef (
725
719
ty:: BorrowKind :: MutBorrow | ty:: BorrowKind :: UniqueImmBorrow ,
726
720
) => {
727
- capture_reason = format ! ( "mutable borrow of `{}`" , upvar ) ;
721
+ capture_reason = format ! ( "mutable borrow of `{upvar }`" ) ;
728
722
}
729
723
ty:: UpvarCapture :: ByValue => {
730
- capture_reason = format ! ( "possible mutation of `{}`" , upvar ) ;
724
+ capture_reason = format ! ( "possible mutation of `{upvar }`" ) ;
731
725
}
732
- _ => bug ! ( "upvar `{}` borrowed, but not mutably" , upvar ) ,
726
+ _ => bug ! ( "upvar `{upvar }` borrowed, but not mutably" ) ,
733
727
}
734
728
break ;
735
729
}
736
730
}
737
731
if capture_reason. is_empty ( ) {
738
- bug ! ( "upvar `{}` borrowed, but cannot find reason" , upvar ) ;
732
+ bug ! ( "upvar `{upvar }` borrowed, but cannot find reason" ) ;
739
733
}
740
734
capture_reason
741
735
} else {
@@ -829,27 +823,27 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
829
823
. as_str ( )
830
824
. starts_with ( & original_method_ident. name . to_string ( ) )
831
825
} )
832
- . map ( |ident| format ! ( "{}()" , ident ) )
826
+ . map ( |ident| format ! ( "{ident }()" ) )
833
827
. peekable ( )
834
828
} ) ;
835
829
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
+ ) ;
845
839
}
846
840
}
847
841
} ;
848
842
}
849
843
850
844
/// Targeted error when encountering an `FnMut` closure where an `Fn` closure was expected.
851
845
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}" ) ) ;
853
847
854
848
let hir = self . infcx . tcx . hir ( ) ;
855
849
let closure_id = self . mir_hir_id ( ) ;
@@ -1011,35 +1005,35 @@ fn suggest_ampmut<'tcx>(
1011
1005
opt_assignment_rhs_span : Option < Span > ,
1012
1006
opt_ty_info : Option < Span > ,
1013
1007
) -> ( 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 ,
1042
1022
}
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}" ) ) ;
1043
1037
}
1044
1038
}
1045
1039
}
@@ -1054,12 +1048,12 @@ fn suggest_ampmut<'tcx>(
1054
1048
None => local_decl. source_info . span ,
1055
1049
} ;
1056
1050
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 ) ) ;
1063
1057
}
1064
1058
1065
1059
let ty_mut = local_decl. ty . builtin_deref ( true ) . unwrap ( ) ;
0 commit comments