retrieve ty info from place_ty
describe index with _
This commit is contained in:
parent
39bc8f5899
commit
8d77c7c037
5 changed files with 33 additions and 51 deletions
|
|
@ -181,38 +181,36 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
);
|
||||
}
|
||||
|
||||
if let Some(ty) = self.retrieve_type_for_place(used_place) {
|
||||
let needs_note = match ty.sty {
|
||||
ty::Closure(id, _) => {
|
||||
let tables = self.infcx.tcx.typeck_tables_of(id);
|
||||
let node_id = self.infcx.tcx.hir().as_local_node_id(id).unwrap();
|
||||
let hir_id = self.infcx.tcx.hir().node_to_hir_id(node_id);
|
||||
let ty = used_place.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx);
|
||||
let needs_note = match ty.sty {
|
||||
ty::Closure(id, _) => {
|
||||
let tables = self.infcx.tcx.typeck_tables_of(id);
|
||||
let node_id = self.infcx.tcx.hir().as_local_node_id(id).unwrap();
|
||||
let hir_id = self.infcx.tcx.hir().node_to_hir_id(node_id);
|
||||
|
||||
tables.closure_kind_origins().get(hir_id).is_none()
|
||||
}
|
||||
_ => true,
|
||||
tables.closure_kind_origins().get(hir_id).is_none()
|
||||
}
|
||||
_ => true,
|
||||
};
|
||||
|
||||
if needs_note {
|
||||
let mpi = self.move_data.moves[move_out_indices[0]].path;
|
||||
let place = &self.move_data.move_paths[mpi].place;
|
||||
|
||||
let ty = place.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx);
|
||||
let note_msg = match self.describe_place_with_options(
|
||||
place,
|
||||
IncludingDowncast(true),
|
||||
) {
|
||||
Some(name) => format!("`{}`", name),
|
||||
None => "value".to_owned(),
|
||||
};
|
||||
|
||||
if needs_note {
|
||||
let mpi = self.move_data.moves[move_out_indices[0]].path;
|
||||
let place = &self.move_data.move_paths[mpi].place;
|
||||
|
||||
if let Some(ty) = self.retrieve_type_for_place(place) {
|
||||
let note_msg = match self.describe_place_with_options(
|
||||
place,
|
||||
IncludingDowncast(true),
|
||||
) {
|
||||
Some(name) => format!("`{}`", name),
|
||||
None => "value".to_owned(),
|
||||
};
|
||||
|
||||
err.note(&format!(
|
||||
"move occurs because {} has type `{}`, \
|
||||
which does not implement the `Copy` trait",
|
||||
note_msg, ty
|
||||
));
|
||||
}
|
||||
}
|
||||
err.note(&format!(
|
||||
"move occurs because {} has type `{}`, \
|
||||
which does not implement the `Copy` trait",
|
||||
note_msg, ty
|
||||
));
|
||||
}
|
||||
|
||||
if let Some((_, mut old_err)) = self.move_error_reported
|
||||
|
|
@ -1558,7 +1556,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
)?;
|
||||
buf.push_str("[");
|
||||
if self.append_local_to_string(index, buf).is_err() {
|
||||
buf.push_str("..");
|
||||
buf.push_str("_");
|
||||
}
|
||||
buf.push_str("]");
|
||||
}
|
||||
|
|
@ -1663,22 +1661,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Retrieve type of a place for the current MIR representation
|
||||
fn retrieve_type_for_place(&self, place: &Place<'tcx>) -> Option<ty::Ty> {
|
||||
match place {
|
||||
Place::Local(local) => {
|
||||
let local = &self.mir.local_decls[*local];
|
||||
Some(local.ty)
|
||||
}
|
||||
Place::Promoted(ref prom) => Some(prom.1),
|
||||
Place::Static(ref st) => Some(st.ty),
|
||||
Place::Projection(ref proj) => match proj.elem {
|
||||
ProjectionElem::Field(_, ty) => Some(ty),
|
||||
_ => None,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if a place is a thread-local static.
|
||||
pub fn is_place_thread_local(&self, place: &Place<'tcx>) -> bool {
|
||||
if let Place::Static(statik) = place {
|
||||
|
|
|
|||
|
|
@ -260,7 +260,7 @@ fn main() {
|
|||
let x = &mut v;
|
||||
v[0].y;
|
||||
//[ast]~^ ERROR cannot use `v[..].y` because it was mutably borrowed
|
||||
//[mir]~^^ ERROR cannot use `v[..].y` because it was mutably borrowed
|
||||
//[mir]~^^ ERROR cannot use `v[_].y` because it was mutably borrowed
|
||||
//[mir]~| ERROR cannot use `*v` because it was mutably borrowed
|
||||
drop(x);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ fn main() {
|
|||
println!("t[0]: {}", t[0]);
|
||||
a[2] = 0; //[ast]~ ERROR cannot assign to `a[..]` because it is borrowed
|
||||
//[cmp]~^ ERROR cannot assign to `a[..]` because it is borrowed (Ast)
|
||||
//[cmp]~| ERROR cannot assign to `a[..]` because it is borrowed (Mir)
|
||||
//[cmp]~| ERROR cannot assign to `a[_]` because it is borrowed (Mir)
|
||||
println!("t[0]: {}", t[0]);
|
||||
t[0];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,10 +17,10 @@ fn main() {
|
|||
use_x(*p.value);
|
||||
} else {
|
||||
use_x(22);
|
||||
v[0] += 1; //~ ERROR cannot assign to `v[..]` because it is borrowed
|
||||
v[0] += 1; //~ ERROR cannot assign to `v[_]` because it is borrowed
|
||||
}
|
||||
|
||||
v[0] += 1; //~ ERROR cannot assign to `v[..]` because it is borrowed
|
||||
v[0] += 1; //~ ERROR cannot assign to `v[_]` because it is borrowed
|
||||
}
|
||||
|
||||
struct WrapMayNotDangle<T> {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ struct S {
|
|||
impl S {
|
||||
pub fn foo(self) -> isize {
|
||||
self.bar();
|
||||
return *self.x; //~ ERROR use of moved value: `*self.x`
|
||||
return *self.x; //~ ERROR use of moved value: `self`
|
||||
}
|
||||
|
||||
pub fn bar(self) {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue