@@ -41,14 +41,17 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
4141 ) ;
4242
4343 let mut err;
44- let item_msg;
44+ let mut item_msg;
4545 let reason;
4646 let access_place_desc = self . describe_place ( access_place) ;
4747 debug ! ( "report_mutability_error: access_place_desc={:?}" , access_place_desc) ;
4848
49+ item_msg = match & access_place_desc {
50+ Some ( desc) => format ! ( "`{}`" , desc) ,
51+ None => "temporary place" . to_string ( ) ,
52+ } ;
4953 match the_place_err {
5054 Place :: Base ( PlaceBase :: Local ( local) ) => {
51- item_msg = format ! ( "`{}`" , access_place_desc. unwrap( ) ) ;
5255 if let Place :: Base ( PlaceBase :: Local ( _) ) = access_place {
5356 reason = ", as it is not declared as mutable" . to_string ( ) ;
5457 } else {
@@ -67,7 +70,6 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
6770 base. ty( self . mir, self . infcx. tcx) . ty
6871 ) ) ;
6972
70- item_msg = format ! ( "`{}`" , access_place_desc. unwrap( ) ) ;
7173 if self . is_upvar_field_projection ( access_place) . is_some ( ) {
7274 reason = ", as it is not declared as mutable" . to_string ( ) ;
7375 } else {
@@ -82,7 +84,6 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
8284 } ) => {
8385 if * base == Place :: Base ( PlaceBase :: Local ( Local :: new ( 1 ) ) ) &&
8486 !self . upvars . is_empty ( ) {
85- item_msg = format ! ( "`{}`" , access_place_desc. unwrap( ) ) ;
8687 debug_assert ! ( self . mir. local_decls[ Local :: new( 1 ) ] . ty. is_region_ptr( ) ) ;
8788 debug_assert ! ( is_closure_or_generator(
8889 the_place_err. ty( self . mir, self . infcx. tcx) . ty
@@ -105,7 +106,6 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
105106 false
106107 }
107108 } {
108- item_msg = format ! ( "`{}`" , access_place_desc. unwrap( ) ) ;
109109 reason = ", as it is immutable for the pattern guard" . to_string ( ) ;
110110 } else {
111111 let pointer_type =
@@ -114,8 +114,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
114114 } else {
115115 "`*const` pointer"
116116 } ;
117- if let Some ( desc) = access_place_desc {
118- item_msg = format ! ( "`{}`" , desc) ;
117+ if access_place_desc. is_some ( ) {
119118 reason = match error_access {
120119 AccessKind :: Move |
121120 AccessKind :: Mutate => format ! ( " which is behind a {}" , pointer_type) ,
@@ -135,10 +134,9 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
135134
136135 Place :: Base ( PlaceBase :: Static ( box Static { kind : StaticKind :: Static ( def_id) , .. } ) ) => {
137136 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 ) ;
139138 reason = String :: new ( ) ;
140139 } else {
141- item_msg = format ! ( "`{}`" , access_place_desc. unwrap( ) ) ;
142140 let static_name = & self . infcx . tcx . item_name ( * def_id) ;
143141 reason = format ! ( ", as `{}` is an immutable static item" , static_name) ;
144142 }
0 commit comments