@@ -41,14 +41,17 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
41
41
) ;
42
42
43
43
let mut err;
44
- let item_msg;
44
+ let mut item_msg;
45
45
let reason;
46
46
let access_place_desc = self . describe_place ( access_place) ;
47
47
debug ! ( "report_mutability_error: access_place_desc={:?}" , access_place_desc) ;
48
48
49
+ item_msg = match & access_place_desc {
50
+ Some ( desc) => format ! ( "`{}`" , desc) ,
51
+ None => "temporary place" . to_string ( ) ,
52
+ } ;
49
53
match the_place_err {
50
54
Place :: Base ( PlaceBase :: Local ( local) ) => {
51
- item_msg = format ! ( "`{}`" , access_place_desc. unwrap( ) ) ;
52
55
if let Place :: Base ( PlaceBase :: Local ( _) ) = access_place {
53
56
reason = ", as it is not declared as mutable" . to_string ( ) ;
54
57
} else {
@@ -67,7 +70,6 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
67
70
base. ty( self . mir, self . infcx. tcx) . ty
68
71
) ) ;
69
72
70
- item_msg = format ! ( "`{}`" , access_place_desc. unwrap( ) ) ;
71
73
if self . is_upvar_field_projection ( access_place) . is_some ( ) {
72
74
reason = ", as it is not declared as mutable" . to_string ( ) ;
73
75
} else {
@@ -82,7 +84,6 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
82
84
} ) => {
83
85
if * base == Place :: Base ( PlaceBase :: Local ( Local :: new ( 1 ) ) ) &&
84
86
!self . upvars . is_empty ( ) {
85
- item_msg = format ! ( "`{}`" , access_place_desc. unwrap( ) ) ;
86
87
debug_assert ! ( self . mir. local_decls[ Local :: new( 1 ) ] . ty. is_region_ptr( ) ) ;
87
88
debug_assert ! ( is_closure_or_generator(
88
89
the_place_err. ty( self . mir, self . infcx. tcx) . ty
@@ -105,7 +106,6 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
105
106
false
106
107
}
107
108
} {
108
- item_msg = format ! ( "`{}`" , access_place_desc. unwrap( ) ) ;
109
109
reason = ", as it is immutable for the pattern guard" . to_string ( ) ;
110
110
} else {
111
111
let pointer_type =
@@ -114,8 +114,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
114
114
} else {
115
115
"`*const` pointer"
116
116
} ;
117
- if let Some ( desc) = access_place_desc {
118
- item_msg = format ! ( "`{}`" , desc) ;
117
+ if access_place_desc. is_some ( ) {
119
118
reason = match error_access {
120
119
AccessKind :: Move |
121
120
AccessKind :: Mutate => format ! ( " which is behind a {}" , pointer_type) ,
@@ -135,10 +134,9 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
135
134
136
135
Place :: Base ( PlaceBase :: Static ( box Static { kind : StaticKind :: Static ( def_id) , .. } ) ) => {
137
136
if let Place :: Base ( PlaceBase :: Static ( _) ) = access_place {
138
- item_msg = format ! ( "immutable static item `{}` " , access_place_desc . unwrap ( ) ) ;
137
+ item_msg = format ! ( "immutable static item {} " , item_msg ) ;
139
138
reason = String :: new ( ) ;
140
139
} else {
141
- item_msg = format ! ( "`{}`" , access_place_desc. unwrap( ) ) ;
142
140
let static_name = & self . infcx . tcx . item_name ( * def_id) ;
143
141
reason = format ! ( ", as `{}` is an immutable static item" , static_name) ;
144
142
}
0 commit comments