borrowck: prefer "value" over "_".
This commit is contained in:
parent
02046a5d40
commit
c70aa344e4
13 changed files with 113 additions and 134 deletions
|
|
@ -256,14 +256,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
"report_move_out_while_borrowed: location={:?} place={:?} span={:?} borrow={:?}",
|
||||
location, place, span, borrow
|
||||
);
|
||||
let value_msg = match self.describe_place(place.as_ref()) {
|
||||
Some(name) => format!("`{}`", name),
|
||||
None => "value".to_owned(),
|
||||
};
|
||||
let borrow_msg = match self.describe_place(borrow.borrowed_place.as_ref()) {
|
||||
Some(name) => format!("`{}`", name),
|
||||
None => "value".to_owned(),
|
||||
};
|
||||
let value_msg = self.describe_place_str(place.as_ref());
|
||||
let borrow_msg = self.describe_place_str(borrow.borrowed_place.as_ref());
|
||||
|
||||
let borrow_spans = self.retrieve_borrow_spans(borrow);
|
||||
let borrow_span = borrow_spans.args_or_use();
|
||||
|
|
@ -271,10 +265,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
let move_spans = self.move_spans(place.as_ref(), location);
|
||||
let span = move_spans.args_or_use();
|
||||
|
||||
let mut err = self.cannot_move_when_borrowed(
|
||||
span,
|
||||
&self.describe_place(place.as_ref()).unwrap_or_else(|| "_".to_owned()),
|
||||
);
|
||||
let mut err =
|
||||
self.cannot_move_when_borrowed(span, &self.describe_place_str(place.as_ref()));
|
||||
err.span_label(borrow_span, format!("borrow of {} occurs here", borrow_msg));
|
||||
err.span_label(span, format!("move out of {} occurs here", value_msg));
|
||||
|
||||
|
|
@ -314,16 +306,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
|
||||
let mut err = self.cannot_use_when_mutably_borrowed(
|
||||
span,
|
||||
&self.describe_place(place.as_ref()).unwrap_or_else(|| "_".to_owned()),
|
||||
&self.describe_place_str(place.as_ref()),
|
||||
borrow_span,
|
||||
&self.describe_place(borrow.borrowed_place.as_ref()).unwrap_or_else(|| "_".to_owned()),
|
||||
&self.describe_place_str(borrow.borrowed_place.as_ref()),
|
||||
);
|
||||
|
||||
borrow_spans.var_span_label(&mut err, {
|
||||
let place = &borrow.borrowed_place;
|
||||
let desc_place = self.describe_place(place.as_ref()).unwrap_or_else(|| "_".to_owned());
|
||||
|
||||
format!("borrow occurs due to use of `{}`{}", desc_place, borrow_spans.describe())
|
||||
let desc_place = self.describe_place_str(place.as_ref());
|
||||
format!("borrow occurs due to use of {}{}", desc_place, borrow_spans.describe())
|
||||
});
|
||||
|
||||
self.explain_why_borrow_contains_point(location, borrow, None)
|
||||
|
|
@ -433,7 +424,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
borrow_spans.var_span_label(
|
||||
&mut err,
|
||||
format!(
|
||||
"borrow occurs due to use of `{}`{}",
|
||||
"borrow occurs due to use of {}{}",
|
||||
desc_place,
|
||||
borrow_spans.describe(),
|
||||
),
|
||||
|
|
@ -511,16 +502,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
if issued_spans == borrow_spans {
|
||||
borrow_spans.var_span_label(
|
||||
&mut err,
|
||||
format!("borrows occur due to use of `{}`{}", desc_place, borrow_spans.describe()),
|
||||
format!("borrows occur due to use of {}{}", desc_place, borrow_spans.describe()),
|
||||
);
|
||||
} else {
|
||||
let borrow_place = &issued_borrow.borrowed_place;
|
||||
let borrow_place_desc =
|
||||
self.describe_place(borrow_place.as_ref()).unwrap_or_else(|| "_".to_owned());
|
||||
let borrow_place_desc = self.describe_place_str(borrow_place.as_ref());
|
||||
issued_spans.var_span_label(
|
||||
&mut err,
|
||||
format!(
|
||||
"first borrow occurs due to use of `{}`{}",
|
||||
"first borrow occurs due to use of {}{}",
|
||||
borrow_place_desc,
|
||||
issued_spans.describe(),
|
||||
),
|
||||
|
|
@ -529,7 +519,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
borrow_spans.var_span_label(
|
||||
&mut err,
|
||||
format!(
|
||||
"second borrow occurs due to use of `{}`{}",
|
||||
"second borrow occurs due to use of {}{}",
|
||||
desc_place,
|
||||
borrow_spans.describe(),
|
||||
),
|
||||
|
|
@ -538,7 +528,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
|
||||
if union_type_name != "" {
|
||||
err.note(&format!(
|
||||
"`{}` is a field of the union `{}`, so it overlaps the field `{}`",
|
||||
"{} is a field of the union `{}`, so it overlaps the field {}",
|
||||
msg_place, union_type_name, msg_borrow,
|
||||
));
|
||||
}
|
||||
|
|
@ -606,7 +596,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
let ty = Place::ty_from(place_base, place_projection, *self.body, self.infcx.tcx).ty;
|
||||
ty.ty_adt_def().filter(|adt| adt.is_union()).map(|_| ty)
|
||||
};
|
||||
let describe_place = |place| self.describe_place(place).unwrap_or_else(|| "_".to_owned());
|
||||
|
||||
// Start with an empty tuple, so we can use the functions on `Option` to reduce some
|
||||
// code duplication (particularly around returning an empty description in the failure
|
||||
|
|
@ -645,30 +634,25 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
.and_then(|(target_base, target_field)| {
|
||||
// With the place of a union and a field access into it, we traverse the second
|
||||
// borrowed place and look for a access to a different field of the same union.
|
||||
let Place { local, projection } = second_borrowed_place;
|
||||
let Place { local, ref projection } = *second_borrowed_place;
|
||||
|
||||
let mut cursor = &projection[..];
|
||||
while let [proj_base @ .., elem] = cursor {
|
||||
cursor = proj_base;
|
||||
|
||||
if let ProjectionElem::Field(field, _) = elem {
|
||||
if let Some(union_ty) = union_ty(*local, proj_base) {
|
||||
if let Some(union_ty) = union_ty(local, proj_base) {
|
||||
if field != target_field
|
||||
&& *local == target_base.local
|
||||
&& local == target_base.local
|
||||
&& proj_base == target_base.projection
|
||||
{
|
||||
// FIXME when we avoid clone reuse describe_place closure
|
||||
let describe_base_place = self
|
||||
.describe_place(PlaceRef {
|
||||
local: *local,
|
||||
projection: proj_base,
|
||||
})
|
||||
.unwrap_or_else(|| "_".to_owned());
|
||||
|
||||
return Some((
|
||||
describe_base_place,
|
||||
describe_place(first_borrowed_place.as_ref()),
|
||||
describe_place(second_borrowed_place.as_ref()),
|
||||
self.describe_place_str(PlaceRef {
|
||||
local,
|
||||
projection: proj_base,
|
||||
}),
|
||||
self.describe_place_str(first_borrowed_place.as_ref()),
|
||||
self.describe_place_str(second_borrowed_place.as_ref()),
|
||||
union_ty.to_string(),
|
||||
));
|
||||
}
|
||||
|
|
@ -681,7 +665,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
// If we didn't find a field access into a union, or both places match, then
|
||||
// only return the description of the first place.
|
||||
(
|
||||
describe_place(first_borrowed_place.as_ref()),
|
||||
self.describe_place_str(first_borrowed_place.as_ref()),
|
||||
"".to_string(),
|
||||
"".to_string(),
|
||||
"".to_string(),
|
||||
|
|
@ -1404,12 +1388,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
let loan_spans = self.retrieve_borrow_spans(loan);
|
||||
let loan_span = loan_spans.args_or_use();
|
||||
|
||||
let descr_place = self.describe_place_str(place.as_ref());
|
||||
if loan.kind == BorrowKind::Shallow {
|
||||
if let Some(section) = self.classify_immutable_section(&loan.assigned_place) {
|
||||
let mut err = self.cannot_mutate_in_immutable_section(
|
||||
span,
|
||||
loan_span,
|
||||
&self.describe_place(place.as_ref()).unwrap_or_else(|| "_".to_owned()),
|
||||
&descr_place,
|
||||
section,
|
||||
"assign",
|
||||
);
|
||||
|
|
@ -1424,11 +1409,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
let mut err = self.cannot_assign_to_borrowed(
|
||||
span,
|
||||
loan_span,
|
||||
&self.describe_place(place.as_ref()).unwrap_or_else(|| "_".to_owned()),
|
||||
);
|
||||
let mut err = self.cannot_assign_to_borrowed(span, loan_span, &descr_place);
|
||||
|
||||
loan_spans
|
||||
.var_span_label(&mut err, format!("borrow occurs due to use{}", loan_spans.describe()));
|
||||
|
|
@ -1482,15 +1463,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
})
|
||||
| Some(LocalDecl { local_info: LocalInfo::StaticRef { .. }, .. })
|
||||
| Some(LocalDecl { local_info: LocalInfo::Other, .. })
|
||||
| None => (self.describe_place(place.as_ref()), assigned_span),
|
||||
Some(decl) => (self.describe_place(err_place.as_ref()), decl.source_info.span),
|
||||
| None => (self.describe_place_str(place.as_ref()), assigned_span),
|
||||
Some(decl) => (self.describe_place_str(err_place.as_ref()), decl.source_info.span),
|
||||
};
|
||||
|
||||
let mut err = self.cannot_reassign_immutable(
|
||||
span,
|
||||
place_description.as_ref().map(AsRef::as_ref).unwrap_or("_"),
|
||||
from_arg,
|
||||
);
|
||||
let mut err = self.cannot_reassign_immutable(span, &place_description, from_arg);
|
||||
let msg = if from_arg {
|
||||
"cannot assign to immutable argument"
|
||||
} else {
|
||||
|
|
@ -1498,11 +1475,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
};
|
||||
if span != assigned_span {
|
||||
if !from_arg {
|
||||
let value_msg = match place_description {
|
||||
Some(name) => format!("`{}`", name),
|
||||
None => "value".to_owned(),
|
||||
};
|
||||
err.span_label(assigned_span, format!("first assignment to {}", value_msg));
|
||||
err.span_label(assigned_span, format!("first assignment to {}", place_description));
|
||||
}
|
||||
}
|
||||
if let Some(decl) = local_decl {
|
||||
|
|
|
|||
|
|
@ -137,8 +137,17 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
/// End-user visible description of `place` if one can be found. If the
|
||||
/// place is a temporary for instance, None will be returned.
|
||||
/// End-user visible description of `place` if one can be found.
|
||||
/// If the place is a temporary for instance, `value` will be returned.
|
||||
pub(super) fn describe_place_str(&self, place_ref: PlaceRef<'tcx>) -> String {
|
||||
match self.describe_place(place_ref) {
|
||||
Some(descr) => format!("`{}`", descr),
|
||||
None => "value".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// End-user visible description of `place` if one can be found.
|
||||
/// If the place is a temporary for instance, None will be returned.
|
||||
pub(super) fn describe_place(&self, place_ref: PlaceRef<'tcx>) -> Option<String> {
|
||||
self.describe_place_with_options(place_ref, IncludingDowncast(false))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -272,14 +272,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||
span: Span,
|
||||
) -> DiagnosticBuilder<'a> {
|
||||
let description = if place.projection.len() == 1 {
|
||||
format!("static item `{}`", self.describe_place(place.as_ref()).unwrap())
|
||||
format!("static item {}", self.describe_place_str(place.as_ref()))
|
||||
} else {
|
||||
let base_static = PlaceRef { local: place.local, projection: &[ProjectionElem::Deref] };
|
||||
|
||||
format!(
|
||||
"`{:?}` as `{:?}` is a static item",
|
||||
self.describe_place(place.as_ref()).unwrap(),
|
||||
self.describe_place(base_static).unwrap(),
|
||||
"{} as {} is a static item",
|
||||
self.describe_place_str(place.as_ref()),
|
||||
self.describe_place_str(base_static),
|
||||
)
|
||||
};
|
||||
|
||||
|
|
@ -349,16 +349,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||
let upvar_name = upvar.name;
|
||||
let upvar_span = self.infcx.tcx.hir().span(upvar_hir_id);
|
||||
|
||||
let place_name = self.describe_place(move_place.as_ref()).unwrap();
|
||||
let place_name = self.describe_place_str(move_place.as_ref());
|
||||
|
||||
let place_description = if self
|
||||
.is_upvar_field_projection(move_place.as_ref())
|
||||
.is_some()
|
||||
{
|
||||
format!("`{}`, a {}", place_name, capture_description)
|
||||
} else {
|
||||
format!("`{}`, as `{}` is a {}", place_name, upvar_name, capture_description,)
|
||||
};
|
||||
let place_description =
|
||||
if self.is_upvar_field_projection(move_place.as_ref()).is_some() {
|
||||
format!("{}, a {}", place_name, capture_description)
|
||||
} else {
|
||||
format!("{}, as `{}` is a {}", place_name, upvar_name, capture_description)
|
||||
};
|
||||
|
||||
debug!(
|
||||
"report: closure_kind_ty={:?} closure_kind={:?} place_description={:?}",
|
||||
|
|
|
|||
|
|
@ -169,9 +169,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||
borrow_spans.var_span_label(
|
||||
&mut err,
|
||||
format!(
|
||||
"mutable borrow occurs due to use of `{}` in closure",
|
||||
// always Some() if the message is printed.
|
||||
self.describe_place(access_place.as_ref()).unwrap_or_default(),
|
||||
"mutable borrow occurs due to use of {} in closure",
|
||||
self.describe_place_str(access_place.as_ref()),
|
||||
),
|
||||
);
|
||||
borrow_span
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use rustc_span::{MultiSpan, Span};
|
|||
|
||||
impl<'cx, 'tcx> crate::borrow_check::MirBorrowckCtxt<'cx, 'tcx> {
|
||||
crate fn cannot_move_when_borrowed(&self, span: Span, desc: &str) -> DiagnosticBuilder<'cx> {
|
||||
struct_span_err!(self, span, E0505, "cannot move out of `{}` because it is borrowed", desc,)
|
||||
struct_span_err!(self, span, E0505, "cannot move out of {} because it is borrowed", desc,)
|
||||
}
|
||||
|
||||
crate fn cannot_use_when_mutably_borrowed(
|
||||
|
|
@ -18,12 +18,12 @@ impl<'cx, 'tcx> crate::borrow_check::MirBorrowckCtxt<'cx, 'tcx> {
|
|||
self,
|
||||
span,
|
||||
E0503,
|
||||
"cannot use `{}` because it was mutably borrowed",
|
||||
"cannot use {} because it was mutably borrowed",
|
||||
desc,
|
||||
);
|
||||
|
||||
err.span_label(borrow_span, format!("borrow of `{}` occurs here", borrow_desc));
|
||||
err.span_label(span, format!("use of borrowed `{}`", borrow_desc));
|
||||
err.span_label(borrow_span, format!("borrow of {} occurs here", borrow_desc));
|
||||
err.span_label(span, format!("use of borrowed {}", borrow_desc));
|
||||
err
|
||||
}
|
||||
|
||||
|
|
@ -53,12 +53,12 @@ impl<'cx, 'tcx> crate::borrow_check::MirBorrowckCtxt<'cx, 'tcx> {
|
|||
old_load_end_span: Option<Span>,
|
||||
) -> DiagnosticBuilder<'cx> {
|
||||
let via =
|
||||
|msg: &str| if msg.is_empty() { msg.to_string() } else { format!(" (via `{}`)", msg) };
|
||||
|msg: &str| if msg.is_empty() { msg.to_string() } else { format!(" (via {})", msg) };
|
||||
let mut err = struct_span_err!(
|
||||
self,
|
||||
new_loan_span,
|
||||
E0499,
|
||||
"cannot borrow `{}`{} as mutable more than once at a time",
|
||||
"cannot borrow {}{} as mutable more than once at a time",
|
||||
desc,
|
||||
via(opt_via),
|
||||
);
|
||||
|
|
@ -103,7 +103,7 @@ impl<'cx, 'tcx> crate::borrow_check::MirBorrowckCtxt<'cx, 'tcx> {
|
|||
self,
|
||||
new_loan_span,
|
||||
E0524,
|
||||
"two closures require unique access to `{}` at the same time",
|
||||
"two closures require unique access to {} at the same time",
|
||||
desc,
|
||||
);
|
||||
if old_loan_span == new_loan_span {
|
||||
|
|
@ -136,7 +136,7 @@ impl<'cx, 'tcx> crate::borrow_check::MirBorrowckCtxt<'cx, 'tcx> {
|
|||
self,
|
||||
new_loan_span,
|
||||
E0500,
|
||||
"closure requires unique access to `{}` but {} is already borrowed{}",
|
||||
"closure requires unique access to {} but {} is already borrowed{}",
|
||||
desc_new,
|
||||
noun_old,
|
||||
old_opt_via,
|
||||
|
|
@ -168,7 +168,7 @@ impl<'cx, 'tcx> crate::borrow_check::MirBorrowckCtxt<'cx, 'tcx> {
|
|||
self,
|
||||
new_loan_span,
|
||||
E0501,
|
||||
"cannot borrow `{}`{} as {} because previous closure \
|
||||
"cannot borrow {}{} as {} because previous closure \
|
||||
requires unique access",
|
||||
desc_new,
|
||||
opt_via,
|
||||
|
|
@ -201,12 +201,12 @@ impl<'cx, 'tcx> crate::borrow_check::MirBorrowckCtxt<'cx, 'tcx> {
|
|||
old_load_end_span: Option<Span>,
|
||||
) -> DiagnosticBuilder<'cx> {
|
||||
let via =
|
||||
|msg: &str| if msg.is_empty() { msg.to_string() } else { format!(" (via `{}`)", msg) };
|
||||
|msg: &str| if msg.is_empty() { msg.to_string() } else { format!(" (via {})", msg) };
|
||||
let mut err = struct_span_err!(
|
||||
self,
|
||||
span,
|
||||
E0502,
|
||||
"cannot borrow `{}`{} as {} because {} is also borrowed \
|
||||
"cannot borrow {}{} as {} because {} is also borrowed \
|
||||
as {}{}",
|
||||
desc_new,
|
||||
via(msg_new),
|
||||
|
|
@ -225,7 +225,7 @@ impl<'cx, 'tcx> crate::borrow_check::MirBorrowckCtxt<'cx, 'tcx> {
|
|||
err.span_label(
|
||||
span,
|
||||
format!(
|
||||
"{} borrow of `{}` -- which overlaps with `{}` -- occurs here",
|
||||
"{} borrow of {} -- which overlaps with {} -- occurs here",
|
||||
kind_new, msg_new, msg_old,
|
||||
),
|
||||
);
|
||||
|
|
@ -248,12 +248,12 @@ impl<'cx, 'tcx> crate::borrow_check::MirBorrowckCtxt<'cx, 'tcx> {
|
|||
self,
|
||||
span,
|
||||
E0506,
|
||||
"cannot assign to `{}` because it is borrowed",
|
||||
"cannot assign to {} because it is borrowed",
|
||||
desc,
|
||||
);
|
||||
|
||||
err.span_label(borrow_span, format!("borrow of `{}` occurs here", desc));
|
||||
err.span_label(span, format!("assignment to borrowed `{}` occurs here", desc));
|
||||
err.span_label(borrow_span, format!("borrow of {} occurs here", desc));
|
||||
err.span_label(span, format!("assignment to borrowed {} occurs here", desc));
|
||||
err
|
||||
}
|
||||
|
||||
|
|
@ -264,7 +264,7 @@ impl<'cx, 'tcx> crate::borrow_check::MirBorrowckCtxt<'cx, 'tcx> {
|
|||
is_arg: bool,
|
||||
) -> DiagnosticBuilder<'cx> {
|
||||
let msg = if is_arg { "to immutable argument" } else { "twice to immutable variable" };
|
||||
struct_span_err!(self, span, E0384, "cannot assign {} `{}`", msg, desc,)
|
||||
struct_span_err!(self, span, E0384, "cannot assign {} {}", msg, desc)
|
||||
}
|
||||
|
||||
crate fn cannot_assign(&self, span: Span, desc: &str) -> DiagnosticBuilder<'cx> {
|
||||
|
|
@ -362,7 +362,7 @@ impl<'cx, 'tcx> crate::borrow_check::MirBorrowckCtxt<'cx, 'tcx> {
|
|||
self,
|
||||
mutate_span,
|
||||
E0510,
|
||||
"cannot {} `{}` in {}",
|
||||
"cannot {} {} in {}",
|
||||
action,
|
||||
immutable_place,
|
||||
immutable_section,
|
||||
|
|
|
|||
|
|
@ -45,19 +45,19 @@ fn main() {
|
|||
*b = NC;
|
||||
let ref a @ box ref mut b = Box::new(NC);
|
||||
//~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable
|
||||
//~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
|
||||
//~| ERROR cannot borrow value as mutable because it is also borrowed as immutable
|
||||
*b = NC;
|
||||
drop(a);
|
||||
|
||||
let ref mut a @ box ref b = Box::new(NC);
|
||||
//~^ ERROR cannot borrow value as immutable because it is also borrowed as mutable
|
||||
//~| ERROR cannot borrow `_` as immutable because it is also borrowed as mutable
|
||||
//~| ERROR cannot borrow value as immutable because it is also borrowed as mutable
|
||||
*a = Box::new(NC);
|
||||
drop(b);
|
||||
|
||||
fn f5(ref mut a @ box ref b: Box<NC>) {
|
||||
//~^ ERROR cannot borrow value as immutable because it is also borrowed as mutable
|
||||
//~| ERROR cannot borrow `_` as immutable because it is also borrowed as mutable
|
||||
//~| ERROR cannot borrow value as immutable because it is also borrowed as mutable
|
||||
*a = Box::new(NC);
|
||||
drop(b);
|
||||
}
|
||||
|
|
@ -65,7 +65,7 @@ fn main() {
|
|||
match Box::new(nc()) {
|
||||
ref mut a @ box ref b => {
|
||||
//~^ ERROR cannot borrow value as immutable because it is also borrowed as mutable
|
||||
//~| ERROR cannot borrow `_` as immutable because it is also borrowed as mutable
|
||||
//~| ERROR cannot borrow value as immutable because it is also borrowed as mutable
|
||||
*a = Box::new(NC);
|
||||
drop(b);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ LL | a @ box b => {}
|
|||
| | value used here after move
|
||||
| value moved here
|
||||
|
||||
error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
|
||||
error[E0502]: cannot borrow value as mutable because it is also borrowed as immutable
|
||||
--> $DIR/borrowck-pat-at-and-box.rs:46:21
|
||||
|
|
||||
LL | let ref a @ box ref mut b = Box::new(NC);
|
||||
|
|
@ -111,7 +111,7 @@ LL | let ref a @ box ref mut b = Box::new(NC);
|
|||
LL | drop(a);
|
||||
| - immutable borrow later used here
|
||||
|
||||
error[E0502]: cannot borrow `_` as immutable because it is also borrowed as mutable
|
||||
error[E0502]: cannot borrow value as immutable because it is also borrowed as mutable
|
||||
--> $DIR/borrowck-pat-at-and-box.rs:52:25
|
||||
|
|
||||
LL | let ref mut a @ box ref b = Box::new(NC);
|
||||
|
|
@ -123,7 +123,7 @@ LL | let ref mut a @ box ref b = Box::new(NC);
|
|||
LL | *a = Box::new(NC);
|
||||
| -- mutable borrow later used here
|
||||
|
||||
error[E0502]: cannot borrow `_` as immutable because it is also borrowed as mutable
|
||||
error[E0502]: cannot borrow value as immutable because it is also borrowed as mutable
|
||||
--> $DIR/borrowck-pat-at-and-box.rs:66:25
|
||||
|
|
||||
LL | ref mut a @ box ref b => {
|
||||
|
|
@ -155,7 +155,7 @@ LL | fn f2(a @ box b: Box<C>) {}
|
|||
| value moved here
|
||||
| move occurs because value has type `std::boxed::Box<C>`, which does not implement the `Copy` trait
|
||||
|
||||
error[E0502]: cannot borrow `_` as immutable because it is also borrowed as mutable
|
||||
error[E0502]: cannot borrow value as immutable because it is also borrowed as mutable
|
||||
--> $DIR/borrowck-pat-at-and-box.rs:58:27
|
||||
|
|
||||
LL | fn f5(ref mut a @ box ref b: Box<NC>) {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ fn main() {
|
|||
match &mut Some(1) {
|
||||
ref mut z @ &mut Some(ref a) => {
|
||||
//~^ ERROR cannot borrow value as immutable because it is also borrowed as mutable
|
||||
//~| ERROR cannot borrow `_` as immutable because it is also borrowed as mutable
|
||||
//~| ERROR cannot borrow value as immutable because it is also borrowed as mutable
|
||||
**z = None;
|
||||
println!("{}", *a);
|
||||
}
|
||||
|
|
@ -47,12 +47,12 @@ fn main() {
|
|||
|
||||
let ref mut a @ ref b = u();
|
||||
//~^ ERROR cannot borrow value as immutable because it is also borrowed as mutable
|
||||
//~| ERROR cannot borrow `_` as immutable because it is also borrowed as mutable
|
||||
//~| ERROR cannot borrow value as immutable because it is also borrowed as mutable
|
||||
*a = u();
|
||||
drop(b);
|
||||
let ref a @ ref mut b = u();
|
||||
//~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable
|
||||
//~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
|
||||
//~| ERROR cannot borrow value as mutable because it is also borrowed as immutable
|
||||
*b = u();
|
||||
drop(a);
|
||||
|
||||
|
|
@ -78,8 +78,8 @@ fn main() {
|
|||
ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) => {
|
||||
//~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable
|
||||
//~| ERROR cannot borrow value as mutable because it is also borrowed as immutable
|
||||
//~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
|
||||
//~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
|
||||
//~| ERROR cannot borrow value as mutable because it is also borrowed as immutable
|
||||
//~| ERROR cannot borrow value as mutable because it is also borrowed as immutable
|
||||
*b = U;
|
||||
drop(a);
|
||||
}
|
||||
|
|
@ -123,15 +123,15 @@ fn main() {
|
|||
|
||||
let ref a @ (ref mut b, ref mut c) = (U, U);
|
||||
//~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable
|
||||
//~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
|
||||
//~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
|
||||
//~| ERROR cannot borrow value as mutable because it is also borrowed as immutable
|
||||
//~| ERROR cannot borrow value as mutable because it is also borrowed as immutable
|
||||
*b = U;
|
||||
drop(a);
|
||||
|
||||
let ref a @ (ref mut b, ref mut c) = (U, U);
|
||||
//~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable
|
||||
*b = U; //~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
|
||||
*c = U; //~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
|
||||
*b = U; //~| ERROR cannot borrow value as mutable because it is also borrowed as immutable
|
||||
*c = U; //~| ERROR cannot borrow value as mutable because it is also borrowed as immutable
|
||||
drop(a);
|
||||
let ref mut a @ (ref b, ref c) = (U, U);
|
||||
//~^ ERROR cannot borrow value as immutable because it is also borrowed as mutable
|
||||
|
|
|
|||
|
|
@ -294,7 +294,7 @@ LL | fn f4_also_moved(ref a @ ref mut b @ c: U) {}
|
|||
| | value moved into `c` here
|
||||
| value borrowed, by `b`, here
|
||||
|
||||
error[E0502]: cannot borrow `_` as immutable because it is also borrowed as mutable
|
||||
error[E0502]: cannot borrow value as immutable because it is also borrowed as mutable
|
||||
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:11:31
|
||||
|
|
||||
LL | ref mut z @ &mut Some(ref a) => {
|
||||
|
|
@ -306,7 +306,7 @@ LL | ref mut z @ &mut Some(ref a) => {
|
|||
LL | **z = None;
|
||||
| ---------- mutable borrow later used here
|
||||
|
||||
error[E0502]: cannot borrow `_` as immutable because it is also borrowed as mutable
|
||||
error[E0502]: cannot borrow value as immutable because it is also borrowed as mutable
|
||||
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:48:21
|
||||
|
|
||||
LL | let ref mut a @ ref b = u();
|
||||
|
|
@ -318,7 +318,7 @@ LL | let ref mut a @ ref b = u();
|
|||
LL | *a = u();
|
||||
| -------- mutable borrow later used here
|
||||
|
||||
error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
|
||||
error[E0502]: cannot borrow value as mutable because it is also borrowed as immutable
|
||||
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:53:17
|
||||
|
|
||||
LL | let ref a @ ref mut b = u();
|
||||
|
|
@ -330,7 +330,7 @@ LL | let ref a @ ref mut b = u();
|
|||
LL | drop(a);
|
||||
| - immutable borrow later used here
|
||||
|
||||
error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
|
||||
error[E0502]: cannot borrow value as mutable because it is also borrowed as immutable
|
||||
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:78:20
|
||||
|
|
||||
LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) => {
|
||||
|
|
@ -342,7 +342,7 @@ LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) => {
|
|||
LL | drop(a);
|
||||
| - immutable borrow later used here
|
||||
|
||||
error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
|
||||
error[E0502]: cannot borrow value as mutable because it is also borrowed as immutable
|
||||
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:78:45
|
||||
|
|
||||
LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) => {
|
||||
|
|
@ -402,7 +402,7 @@ LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { drop(a); false
|
|||
|
|
||||
= note: variables bound in patterns cannot be moved from until after the end of the pattern guard
|
||||
|
||||
error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
|
||||
error[E0502]: cannot borrow value as mutable because it is also borrowed as immutable
|
||||
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:124:18
|
||||
|
|
||||
LL | let ref a @ (ref mut b, ref mut c) = (U, U);
|
||||
|
|
@ -414,7 +414,7 @@ LL | let ref a @ (ref mut b, ref mut c) = (U, U);
|
|||
LL | drop(a);
|
||||
| - immutable borrow later used here
|
||||
|
||||
error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
|
||||
error[E0502]: cannot borrow value as mutable because it is also borrowed as immutable
|
||||
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:124:29
|
||||
|
|
||||
LL | let ref a @ (ref mut b, ref mut c) = (U, U);
|
||||
|
|
@ -426,7 +426,7 @@ LL | let ref a @ (ref mut b, ref mut c) = (U, U);
|
|||
LL | drop(a);
|
||||
| - immutable borrow later used here
|
||||
|
||||
error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
|
||||
error[E0502]: cannot borrow value as mutable because it is also borrowed as immutable
|
||||
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:131:18
|
||||
|
|
||||
LL | let ref a @ (ref mut b, ref mut c) = (U, U);
|
||||
|
|
@ -438,7 +438,7 @@ LL | let ref a @ (ref mut b, ref mut c) = (U, U);
|
|||
LL | drop(a);
|
||||
| - immutable borrow later used here
|
||||
|
||||
error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
|
||||
error[E0502]: cannot borrow value as mutable because it is also borrowed as immutable
|
||||
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:131:29
|
||||
|
|
||||
LL | let ref a @ (ref mut b, ref mut c) = (U, U);
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ fn main() {
|
|||
|
||||
let ref mut a @ ref mut b = U;
|
||||
//~^ ERROR cannot borrow value as mutable more than once at a time
|
||||
//~| ERROR cannot borrow `_` as mutable more than once at a time
|
||||
//~| ERROR cannot borrow value as mutable more than once at a time
|
||||
drop(a);
|
||||
let ref mut a @ ref mut b = U;
|
||||
//~^ ERROR cannot borrow value as mutable more than once at a time
|
||||
|
|
@ -37,7 +37,7 @@ fn main() {
|
|||
|
||||
let ref mut a @ ref mut b = U;
|
||||
//~^ ERROR cannot borrow value as mutable more than once at a time
|
||||
//~| ERROR cannot borrow `_` as mutable more than once at a time
|
||||
//~| ERROR cannot borrow value as mutable more than once at a time
|
||||
*a = U;
|
||||
let ref mut a @ ref mut b = U;
|
||||
//~^ ERROR cannot borrow value as mutable more than once at a time
|
||||
|
|
@ -95,11 +95,11 @@ fn main() {
|
|||
ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
|
||||
//~^ ERROR cannot borrow value as mutable more than once at a time
|
||||
//~| ERROR cannot borrow value as mutable more than once at a time
|
||||
//~| ERROR cannot borrow `_` as mutable more than once at a time
|
||||
//~| ERROR cannot borrow `_` as mutable more than once at a time
|
||||
//~| ERROR cannot borrow value as mutable more than once at a time
|
||||
//~| ERROR cannot borrow value as mutable more than once at a time
|
||||
*a = Err(U);
|
||||
|
||||
// FIXME: The binding name `_` used above makes for problematic diagnostics.
|
||||
// FIXME: The binding name value used above makes for problematic diagnostics.
|
||||
// Resolve that somehow...
|
||||
}
|
||||
}
|
||||
|
|
@ -107,8 +107,8 @@ fn main() {
|
|||
ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
|
||||
//~^ ERROR cannot borrow value as mutable more than once at a time
|
||||
//~| ERROR cannot borrow value as mutable more than once at a time
|
||||
//~| ERROR cannot borrow `_` as mutable more than once at a time
|
||||
//~| ERROR cannot borrow `_` as mutable more than once at a time
|
||||
//~| ERROR cannot borrow value as mutable more than once at a time
|
||||
//~| ERROR cannot borrow value as mutable more than once at a time
|
||||
drop(a);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -258,7 +258,7 @@ LL | fn f4_also_moved(ref mut a @ ref mut b @ c: U) {}
|
|||
| | value moved into `c` here
|
||||
| value borrowed, by `b`, here
|
||||
|
||||
error[E0499]: cannot borrow `_` as mutable more than once at a time
|
||||
error[E0499]: cannot borrow value as mutable more than once at a time
|
||||
--> $DIR/borrowck-pat-ref-mut-twice.rs:28:21
|
||||
|
|
||||
LL | let ref mut a @ ref mut b = U;
|
||||
|
|
@ -270,7 +270,7 @@ LL | let ref mut a @ ref mut b = U;
|
|||
LL | drop(a);
|
||||
| - first borrow later used here
|
||||
|
||||
error[E0499]: cannot borrow `_` as mutable more than once at a time
|
||||
error[E0499]: cannot borrow value as mutable more than once at a time
|
||||
--> $DIR/borrowck-pat-ref-mut-twice.rs:38:21
|
||||
|
|
||||
LL | let ref mut a @ ref mut b = U;
|
||||
|
|
@ -318,7 +318,7 @@ LL | let a @ &mut (ref mut b, ref mut c) = &mut (U, U);
|
|||
| | value borrowed here after move
|
||||
| value moved here
|
||||
|
||||
error[E0499]: cannot borrow `_` as mutable more than once at a time
|
||||
error[E0499]: cannot borrow value as mutable more than once at a time
|
||||
--> $DIR/borrowck-pat-ref-mut-twice.rs:95:24
|
||||
|
|
||||
LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
|
||||
|
|
@ -330,7 +330,7 @@ LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
|
|||
LL | *a = Err(U);
|
||||
| ----------- first borrow later used here
|
||||
|
||||
error[E0499]: cannot borrow `_` as mutable more than once at a time
|
||||
error[E0499]: cannot borrow value as mutable more than once at a time
|
||||
--> $DIR/borrowck-pat-ref-mut-twice.rs:95:53
|
||||
|
|
||||
LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
|
||||
|
|
@ -342,7 +342,7 @@ LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
|
|||
LL | *a = Err(U);
|
||||
| ----------- first borrow later used here
|
||||
|
||||
error[E0499]: cannot borrow `_` as mutable more than once at a time
|
||||
error[E0499]: cannot borrow value as mutable more than once at a time
|
||||
--> $DIR/borrowck-pat-ref-mut-twice.rs:107:24
|
||||
|
|
||||
LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
|
||||
|
|
@ -354,7 +354,7 @@ LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
|
|||
LL | drop(a);
|
||||
| - first borrow later used here
|
||||
|
||||
error[E0499]: cannot borrow `_` as mutable more than once at a time
|
||||
error[E0499]: cannot borrow value as mutable more than once at a time
|
||||
--> $DIR/borrowck-pat-ref-mut-twice.rs:107:53
|
||||
|
|
||||
LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ fn main() {
|
|||
let _a: &NotCopy = a;
|
||||
let _b: NotCopy = b;
|
||||
let ref mut a @ b = NotCopy; //~ ERROR cannot move out of value because it is borrowed
|
||||
//~^ ERROR cannot move out of `_` because it is borrowed
|
||||
//~^ ERROR cannot move out of value because it is borrowed
|
||||
let _a: &NotCopy = a;
|
||||
let _b: NotCopy = b;
|
||||
match Ok(NotCopy) {
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ LL | ref a @ b => {
|
|||
| | value moved into `b` here
|
||||
| value borrowed, by `a`, here
|
||||
|
||||
error[E0505]: cannot move out of `_` because it is borrowed
|
||||
error[E0505]: cannot move out of value because it is borrowed
|
||||
--> $DIR/default-binding-modes-both-sides-independent.rs:31:21
|
||||
|
|
||||
LL | let ref mut a @ b = NotCopy;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue