@@ -7,7 +7,7 @@ use rustc::mir::{
77use rustc:: mir:: { Terminator , TerminatorKind } ;
88use rustc:: ty:: { self , Const , DefIdTree , Ty , TyS , TyCtxt } ;
99use rustc_data_structures:: indexed_vec:: Idx ;
10- use syntax_pos:: Span ;
10+ use syntax_pos:: { Span , CompilerDesugaringKind } ;
1111use syntax_pos:: symbol:: kw;
1212
1313use crate :: dataflow:: move_paths:: InitLocation ;
@@ -41,14 +41,19 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
4141 ) ;
4242
4343 let mut err;
44- let item_msg;
4544 let reason;
4645 let access_place_desc = self . describe_place ( access_place) ;
4746 debug ! ( "report_mutability_error: access_place_desc={:?}" , access_place_desc) ;
4847
48+ let mut item_msg = match ( & access_place_desc, & the_place_err) {
49+ ( Some ( desc) , _) => format ! ( "`{}`" , desc) ,
50+ ( None , Place :: Base ( PlaceBase :: Local ( local) ) ) if self . mir . local_decls [ * local]
51+ . source_info . span . is_compiler_desugaring ( CompilerDesugaringKind :: Async )
52+ => "`async fn` parameter" . to_string ( ) ,
53+ ( None , _) => "temporary place" . to_string ( ) ,
54+ } ;
4955 match the_place_err {
5056 Place :: Base ( PlaceBase :: Local ( local) ) => {
51- item_msg = format ! ( "`{}`" , access_place_desc. unwrap( ) ) ;
5257 if let Place :: Base ( PlaceBase :: Local ( _) ) = access_place {
5358 reason = ", as it is not declared as mutable" . to_string ( ) ;
5459 } else {
@@ -67,7 +72,6 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
6772 base. ty( self . mir, self . infcx. tcx) . ty
6873 ) ) ;
6974
70- item_msg = format ! ( "`{}`" , access_place_desc. unwrap( ) ) ;
7175 if self . is_upvar_field_projection ( access_place) . is_some ( ) {
7276 reason = ", as it is not declared as mutable" . to_string ( ) ;
7377 } else {
@@ -82,7 +86,6 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
8286 } ) => {
8387 if * base == Place :: Base ( PlaceBase :: Local ( Local :: new ( 1 ) ) ) &&
8488 !self . upvars . is_empty ( ) {
85- item_msg = format ! ( "`{}`" , access_place_desc. unwrap( ) ) ;
8689 debug_assert ! ( self . mir. local_decls[ Local :: new( 1 ) ] . ty. is_region_ptr( ) ) ;
8790 debug_assert ! ( is_closure_or_generator(
8891 the_place_err. ty( self . mir, self . infcx. tcx) . ty
@@ -105,7 +108,6 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
105108 false
106109 }
107110 } {
108- item_msg = format ! ( "`{}`" , access_place_desc. unwrap( ) ) ;
109111 reason = ", as it is immutable for the pattern guard" . to_string ( ) ;
110112 } else {
111113 let pointer_type =
@@ -114,8 +116,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
114116 } else {
115117 "`*const` pointer"
116118 } ;
117- if let Some ( desc) = access_place_desc {
118- item_msg = format ! ( "`{}`" , desc) ;
119+ if access_place_desc. is_some ( ) {
119120 reason = match error_access {
120121 AccessKind :: Move |
121122 AccessKind :: Mutate => format ! ( " which is behind a {}" , pointer_type) ,
@@ -135,10 +136,9 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
135136
136137 Place :: Base ( PlaceBase :: Static ( box Static { kind : StaticKind :: Static ( def_id) , .. } ) ) => {
137138 if let Place :: Base ( PlaceBase :: Static ( _) ) = access_place {
138- item_msg = format ! ( "immutable static item `{}` " , access_place_desc . unwrap ( ) ) ;
139+ item_msg = format ! ( "immutable static item {} " , item_msg ) ;
139140 reason = String :: new ( ) ;
140141 } else {
141- item_msg = format ! ( "`{}`" , access_place_desc. unwrap( ) ) ;
142142 let static_name = & self . infcx . tcx . item_name ( * def_id) ;
143143 reason = format ! ( ", as `{}` is an immutable static item" , static_name) ;
144144 }
0 commit comments