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