Skip to content

Commit 3430c6f

Browse files
authored
Rollup merge of rust-lang#61192 - estebank:issue-61187, r=oli-obk
Do not ICE on missing access place description during mutability error reporting Fix rust-lang#61187.
2 parents 4b9d803 + d72f97d commit 3430c6f

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

src/librustc_mir/borrow_check/mutability_errors.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc::mir::{
77
use rustc::mir::{Terminator, TerminatorKind};
88
use rustc::ty::{self, Const, DefIdTree, Ty, TyS, TyCtxt};
99
use rustc_data_structures::indexed_vec::Idx;
10-
use syntax_pos::Span;
10+
use syntax_pos::{Span, CompilerDesugaringKind};
1111
use syntax_pos::symbol::kw;
1212

1313
use 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
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// edition:2018
2+
#![feature(async_await)]
3+
4+
fn main() {
5+
}
6+
7+
async fn response(data: Vec<u8>) {
8+
data.reverse(); //~ ERROR E0596
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0596]: cannot borrow `async fn` parameter as mutable, as it is not declared as mutable
2+
--> $DIR/issue-61187.rs:8:5
3+
|
4+
LL | async fn response(data: Vec<u8>) {
5+
| ---- help: consider changing this to be mutable: `mut data`
6+
LL | data.reverse();
7+
| ^^^^ cannot borrow as mutable
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0596`.

0 commit comments

Comments
 (0)