rustfmt over error_reporting, explain_borrow and region_infer mods
This commit is contained in:
parent
ff7dca50a4
commit
99c42dccfa
4 changed files with 513 additions and 454 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -17,7 +17,7 @@ use rustc_data_structures::indexed_vec::Idx;
|
|||
|
||||
use std::rc::Rc;
|
||||
|
||||
use super::{MirBorrowckCtxt, Context};
|
||||
use super::{Context, MirBorrowckCtxt};
|
||||
use super::{InitializationRequiringAction, PrefixSet};
|
||||
use dataflow::{ActiveBorrows, BorrowData, FlowAtLocation, MovingOutStatements};
|
||||
use dataflow::move_paths::MovePathIndex;
|
||||
|
|
@ -97,7 +97,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
} else {
|
||||
true
|
||||
}
|
||||
},
|
||||
}
|
||||
_ => true,
|
||||
};
|
||||
|
||||
|
|
@ -107,9 +107,11 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
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
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -155,7 +157,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
span,
|
||||
&self.describe_place(place).unwrap_or("_".to_owned()),
|
||||
self.retrieve_borrow_span(borrow),
|
||||
&self.describe_place(&borrow.borrowed_place).unwrap_or("_".to_owned()),
|
||||
&self.describe_place(&borrow.borrowed_place)
|
||||
.unwrap_or("_".to_owned()),
|
||||
Origin::Mir,
|
||||
);
|
||||
|
||||
|
|
@ -176,8 +179,14 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
use rustc::hir::ExprClosure;
|
||||
use rustc::mir::AggregateKind;
|
||||
|
||||
let local = match self.mir[location.block].statements.get(location.statement_index) {
|
||||
Some(&Statement { kind: StatementKind::Assign(Place::Local(local), _), .. }) => local,
|
||||
let local = match self.mir[location.block]
|
||||
.statements
|
||||
.get(location.statement_index)
|
||||
{
|
||||
Some(&Statement {
|
||||
kind: StatementKind::Assign(Place::Local(local), _),
|
||||
..
|
||||
}) => local,
|
||||
_ => return None,
|
||||
};
|
||||
|
||||
|
|
@ -203,8 +212,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
.with_freevars(node_id, |freevars| {
|
||||
for (v, place) in freevars.iter().zip(places) {
|
||||
match *place {
|
||||
Operand::Copy(Place::Local(l)) |
|
||||
Operand::Move(Place::Local(l)) if local == l =>
|
||||
Operand::Copy(Place::Local(l))
|
||||
| Operand::Move(Place::Local(l)) if local == l =>
|
||||
{
|
||||
debug!(
|
||||
"find_closure_span: found captured local {:?}",
|
||||
|
|
@ -256,8 +265,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
"immutable",
|
||||
"mutable",
|
||||
) {
|
||||
(BorrowKind::Shared, lft, _, BorrowKind::Mut { .. }, _, rgt) |
|
||||
(BorrowKind::Mut { .. }, _, lft, BorrowKind::Shared, rgt, _) => self.tcx
|
||||
(BorrowKind::Shared, lft, _, BorrowKind::Mut { .. }, _, rgt)
|
||||
| (BorrowKind::Mut { .. }, _, lft, BorrowKind::Shared, rgt, _) => self.tcx
|
||||
.cannot_reborrow_already_borrowed(
|
||||
span,
|
||||
&desc_place,
|
||||
|
|
@ -356,11 +365,13 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
context: Context,
|
||||
borrow: &BorrowData<'tcx>,
|
||||
drop_span: Span,
|
||||
borrows: &ActiveBorrows<'cx, 'gcx, 'tcx>
|
||||
borrows: &ActiveBorrows<'cx, 'gcx, 'tcx>,
|
||||
) {
|
||||
let end_span = borrows.opt_region_end_span(&borrow.region);
|
||||
let scope_tree = borrows.0.scope_tree();
|
||||
let root_place = self.prefixes(&borrow.borrowed_place, PrefixSet::All).last().unwrap();
|
||||
let root_place = self.prefixes(&borrow.borrowed_place, PrefixSet::All)
|
||||
.last()
|
||||
.unwrap();
|
||||
|
||||
let borrow_span = self.mir.source_info(borrow.location).span;
|
||||
let proper_span = match *root_place {
|
||||
|
|
@ -368,13 +379,18 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
_ => drop_span,
|
||||
};
|
||||
|
||||
if self.access_place_error_reported.contains(&(root_place.clone(), borrow_span)) {
|
||||
debug!("suppressing access_place error when borrow doesn't live long enough for {:?}",
|
||||
borrow_span);
|
||||
if self.access_place_error_reported
|
||||
.contains(&(root_place.clone(), borrow_span))
|
||||
{
|
||||
debug!(
|
||||
"suppressing access_place error when borrow doesn't live long enough for {:?}",
|
||||
borrow_span
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
self.access_place_error_reported.insert((root_place.clone(), borrow_span));
|
||||
self.access_place_error_reported
|
||||
.insert((root_place.clone(), borrow_span));
|
||||
|
||||
match (borrow.region, &self.describe_place(&borrow.borrowed_place)) {
|
||||
(RegionKind::ReScope(_), Some(name)) => {
|
||||
|
|
@ -386,9 +402,9 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
drop_span,
|
||||
borrow_span,
|
||||
proper_span,
|
||||
end_span
|
||||
end_span,
|
||||
);
|
||||
},
|
||||
}
|
||||
(RegionKind::ReScope(_), None) => {
|
||||
self.report_scoped_temporary_value_does_not_live_long_enough(
|
||||
context,
|
||||
|
|
@ -397,14 +413,14 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
drop_span,
|
||||
borrow_span,
|
||||
proper_span,
|
||||
end_span
|
||||
end_span,
|
||||
);
|
||||
},
|
||||
(RegionKind::ReEarlyBound(_), Some(name)) |
|
||||
(RegionKind::ReFree(_), Some(name)) |
|
||||
(RegionKind::ReStatic, Some(name)) |
|
||||
(RegionKind::ReEmpty, Some(name)) |
|
||||
(RegionKind::ReVar(_), Some(name)) => {
|
||||
}
|
||||
(RegionKind::ReEarlyBound(_), Some(name))
|
||||
| (RegionKind::ReFree(_), Some(name))
|
||||
| (RegionKind::ReStatic, Some(name))
|
||||
| (RegionKind::ReEmpty, Some(name))
|
||||
| (RegionKind::ReVar(_), Some(name)) => {
|
||||
self.report_unscoped_local_value_does_not_live_long_enough(
|
||||
context,
|
||||
name,
|
||||
|
|
@ -415,12 +431,12 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
proper_span,
|
||||
end_span,
|
||||
);
|
||||
},
|
||||
(RegionKind::ReEarlyBound(_), None) |
|
||||
(RegionKind::ReFree(_), None) |
|
||||
(RegionKind::ReStatic, None) |
|
||||
(RegionKind::ReEmpty, None) |
|
||||
(RegionKind::ReVar(_), None) => {
|
||||
}
|
||||
(RegionKind::ReEarlyBound(_), None)
|
||||
| (RegionKind::ReFree(_), None)
|
||||
| (RegionKind::ReStatic, None)
|
||||
| (RegionKind::ReEmpty, None)
|
||||
| (RegionKind::ReVar(_), None) => {
|
||||
self.report_unscoped_temporary_value_does_not_live_long_enough(
|
||||
context,
|
||||
&scope_tree,
|
||||
|
|
@ -430,13 +446,13 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
proper_span,
|
||||
end_span,
|
||||
);
|
||||
},
|
||||
(RegionKind::ReLateBound(_, _), _) |
|
||||
(RegionKind::ReSkolemized(_, _), _) |
|
||||
(RegionKind::ReClosureBound(_), _) |
|
||||
(RegionKind::ReErased, _) => {
|
||||
}
|
||||
(RegionKind::ReLateBound(_, _), _)
|
||||
| (RegionKind::ReSkolemized(_, _), _)
|
||||
| (RegionKind::ReClosureBound(_), _)
|
||||
| (RegionKind::ReErased, _) => {
|
||||
span_bug!(drop_span, "region does not make sense in this context");
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -451,11 +467,16 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
_proper_span: Span,
|
||||
end_span: Option<Span>,
|
||||
) {
|
||||
let mut err = self.tcx.path_does_not_live_long_enough(borrow_span,
|
||||
&format!("`{}`", name),
|
||||
Origin::Mir);
|
||||
let mut err = self.tcx.path_does_not_live_long_enough(
|
||||
borrow_span,
|
||||
&format!("`{}`", name),
|
||||
Origin::Mir,
|
||||
);
|
||||
err.span_label(borrow_span, "borrowed value does not live long enough");
|
||||
err.span_label(drop_span, format!("`{}` dropped here while still borrowed", name));
|
||||
err.span_label(
|
||||
drop_span,
|
||||
format!("`{}` dropped here while still borrowed", name),
|
||||
);
|
||||
if let Some(end) = end_span {
|
||||
err.span_label(end, "borrowed value needs to live until here");
|
||||
}
|
||||
|
|
@ -473,11 +494,14 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
proper_span: Span,
|
||||
end_span: Option<Span>,
|
||||
) {
|
||||
let mut err = self.tcx.path_does_not_live_long_enough(proper_span,
|
||||
"borrowed value",
|
||||
Origin::Mir);
|
||||
let mut err =
|
||||
self.tcx
|
||||
.path_does_not_live_long_enough(proper_span, "borrowed value", Origin::Mir);
|
||||
err.span_label(proper_span, "temporary value does not live long enough");
|
||||
err.span_label(drop_span, "temporary value dropped here while still borrowed");
|
||||
err.span_label(
|
||||
drop_span,
|
||||
"temporary value dropped here while still borrowed",
|
||||
);
|
||||
err.note("consider using a `let` binding to increase its lifetime");
|
||||
if let Some(end) = end_span {
|
||||
err.span_label(end, "temporary value needs to live until here");
|
||||
|
|
@ -499,19 +523,16 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
) {
|
||||
debug!(
|
||||
"report_unscoped_local_value_does_not_live_long_enough(\
|
||||
{:?}, {:?}, {:?}, {:?}, {:?}, {:?}\
|
||||
)",
|
||||
context,
|
||||
name,
|
||||
scope_tree,
|
||||
borrow,
|
||||
drop_span,
|
||||
borrow_span
|
||||
{:?}, {:?}, {:?}, {:?}, {:?}, {:?}\
|
||||
)",
|
||||
context, name, scope_tree, borrow, drop_span, borrow_span
|
||||
);
|
||||
|
||||
let mut err = self.tcx.path_does_not_live_long_enough(borrow_span,
|
||||
&format!("`{}`", name),
|
||||
Origin::Mir);
|
||||
let mut err = self.tcx.path_does_not_live_long_enough(
|
||||
borrow_span,
|
||||
&format!("`{}`", name),
|
||||
Origin::Mir,
|
||||
);
|
||||
err.span_label(borrow_span, "borrowed value does not live long enough");
|
||||
err.span_label(drop_span, "borrowed value only lives until here");
|
||||
|
||||
|
|
@ -537,22 +558,18 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
drop_span: Span,
|
||||
_borrow_span: Span,
|
||||
proper_span: Span,
|
||||
_end_span: Option<Span>
|
||||
_end_span: Option<Span>,
|
||||
) {
|
||||
debug!(
|
||||
"report_unscoped_temporary_value_does_not_live_long_enough(\
|
||||
{:?}, {:?}, {:?}, {:?}, {:?}\
|
||||
)",
|
||||
context,
|
||||
scope_tree,
|
||||
borrow,
|
||||
drop_span,
|
||||
proper_span
|
||||
{:?}, {:?}, {:?}, {:?}, {:?}\
|
||||
)",
|
||||
context, scope_tree, borrow, drop_span, proper_span
|
||||
);
|
||||
|
||||
let mut err = self.tcx.path_does_not_live_long_enough(proper_span,
|
||||
"borrowed value",
|
||||
Origin::Mir);
|
||||
let mut err =
|
||||
self.tcx
|
||||
.path_does_not_live_long_enough(proper_span, "borrowed value", Origin::Mir);
|
||||
err.span_label(proper_span, "temporary value does not live long enough");
|
||||
err.span_label(drop_span, "temporary value only lives until here");
|
||||
|
||||
|
|
@ -746,9 +763,9 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
ProjectionElem::Field(_, field_type) => {
|
||||
self.describe_field_from_ty(&field_type, field)
|
||||
}
|
||||
ProjectionElem::Index(..) |
|
||||
ProjectionElem::ConstantIndex { .. } |
|
||||
ProjectionElem::Subslice { .. } => {
|
||||
ProjectionElem::Index(..)
|
||||
| ProjectionElem::ConstantIndex { .. }
|
||||
| ProjectionElem::Subslice { .. } => {
|
||||
format!("{}", self.describe_field(&proj.base, field))
|
||||
}
|
||||
},
|
||||
|
|
@ -805,13 +822,11 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
Place::Local(local) => {
|
||||
let local = &self.mir.local_decls[*local];
|
||||
Some(local.ty)
|
||||
},
|
||||
}
|
||||
Place::Static(ref st) => Some(st.ty),
|
||||
Place::Projection(ref proj) => {
|
||||
match proj.elem {
|
||||
ProjectionElem::Field(_, ty) => Some(ty),
|
||||
_ => None,
|
||||
}
|
||||
Place::Projection(ref proj) => match proj.elem {
|
||||
ProjectionElem::Field(_, ty) => Some(ty),
|
||||
_ => None,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
|
||||
Cause::UniversalRegion(region_vid) => {
|
||||
if let Some(region) = regioncx.to_error_region(region_vid) {
|
||||
|
||||
self.tcx.note_and_explain_free_region(
|
||||
err,
|
||||
"borrowed value must be valid for ",
|
||||
|
|
@ -82,8 +81,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
_ => {
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -573,10 +573,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
// an error that multiple bounds are required.
|
||||
tcx.sess.span_err(
|
||||
type_test.span,
|
||||
&format!(
|
||||
"`{}` does not live long enough",
|
||||
type_test.generic_kind,
|
||||
),
|
||||
&format!("`{}` does not live long enough", type_test.generic_kind,),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -593,8 +590,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
return self.definitions[r].external_name;
|
||||
} else {
|
||||
let inferred_values = self.inferred_values
|
||||
.as_ref()
|
||||
.expect("region values not yet inferred");
|
||||
.as_ref()
|
||||
.expect("region values not yet inferred");
|
||||
let upper_bound = self.universal_upper_bound(r);
|
||||
if inferred_values.contains(r, upper_bound) {
|
||||
self.to_error_region(upper_bound)
|
||||
|
|
@ -806,9 +803,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
) -> bool {
|
||||
debug!(
|
||||
"eval_region_test(point={:?}, lower_bound={:?}, test={:?})",
|
||||
point,
|
||||
lower_bound,
|
||||
test
|
||||
point, lower_bound, test
|
||||
);
|
||||
|
||||
match test {
|
||||
|
|
@ -840,9 +835,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
) -> bool {
|
||||
debug!(
|
||||
"eval_outlives({:?}: {:?} @ {:?})",
|
||||
sup_region,
|
||||
sub_region,
|
||||
point
|
||||
sup_region, sub_region, point
|
||||
);
|
||||
|
||||
// Roughly speaking, do a DFS of all region elements reachable
|
||||
|
|
@ -947,8 +940,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
|
||||
debug!(
|
||||
"check_universal_region: fr={:?} does not outlive shorter_fr={:?}",
|
||||
longer_fr,
|
||||
shorter_fr,
|
||||
longer_fr, shorter_fr,
|
||||
);
|
||||
|
||||
let blame_span = self.blame_span(longer_fr, shorter_fr);
|
||||
|
|
@ -1123,10 +1115,7 @@ impl fmt::Debug for Constraint {
|
|||
write!(
|
||||
formatter,
|
||||
"({:?}: {:?} @ {:?}) due to {:?}",
|
||||
self.sup,
|
||||
self.sub,
|
||||
self.point,
|
||||
self.span
|
||||
self.sup, self.sub, self.point, self.span
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -1176,9 +1165,7 @@ impl<'gcx, 'tcx> ClosureRegionRequirementsExt<'gcx, 'tcx> for ClosureRegionRequi
|
|||
|
||||
debug!(
|
||||
"apply_requirements(location={:?}, closure_def_id={:?}, closure_substs={:?})",
|
||||
location,
|
||||
closure_def_id,
|
||||
closure_substs
|
||||
location, closure_def_id, closure_substs
|
||||
);
|
||||
|
||||
// Get Tu.
|
||||
|
|
@ -1206,9 +1193,7 @@ impl<'gcx, 'tcx> ClosureRegionRequirementsExt<'gcx, 'tcx> for ClosureRegionRequi
|
|||
"apply_requirements: region={:?} \
|
||||
outlived_region={:?} \
|
||||
outlives_requirement={:?}",
|
||||
region,
|
||||
outlived_region,
|
||||
outlives_requirement,
|
||||
region, outlived_region, outlives_requirement,
|
||||
);
|
||||
infcx.sub_regions(origin, outlived_region, region);
|
||||
}
|
||||
|
|
@ -1219,9 +1204,7 @@ impl<'gcx, 'tcx> ClosureRegionRequirementsExt<'gcx, 'tcx> for ClosureRegionRequi
|
|||
"apply_requirements: ty={:?} \
|
||||
outlived_region={:?} \
|
||||
outlives_requirement={:?}",
|
||||
ty,
|
||||
outlived_region,
|
||||
outlives_requirement,
|
||||
ty, outlived_region, outlives_requirement,
|
||||
);
|
||||
infcx.register_region_obligation(
|
||||
body_id,
|
||||
|
|
@ -1276,19 +1259,12 @@ impl CauseExt for Rc<Cause> {
|
|||
impl Cause {
|
||||
pub(crate) fn root_cause(&self) -> &Cause {
|
||||
match self {
|
||||
Cause::LiveVar(..) |
|
||||
Cause::DropVar(..) |
|
||||
Cause::LiveOther(..) |
|
||||
Cause::UniversalRegion(..) => {
|
||||
self
|
||||
}
|
||||
Cause::LiveVar(..)
|
||||
| Cause::DropVar(..)
|
||||
| Cause::LiveOther(..)
|
||||
| Cause::UniversalRegion(..) => self,
|
||||
|
||||
Cause::Outlives {
|
||||
original_cause,
|
||||
..
|
||||
} => {
|
||||
original_cause.root_cause()
|
||||
}
|
||||
Cause::Outlives { original_cause, .. } => original_cause.root_cause(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue