Run rustfmt
This commit is contained in:
parent
f4fc43cb20
commit
d3defcaf3b
3 changed files with 691 additions and 450 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -9,20 +9,20 @@
|
|||
// except according to those terms.
|
||||
|
||||
use borrow_check::WriteKind;
|
||||
use syntax_pos::Span;
|
||||
use rustc::middle::region::ScopeTree;
|
||||
use rustc::mir::{BorrowKind, Field, Local, LocalKind, Location, Operand};
|
||||
use rustc::mir::{Place, ProjectionElem, Rvalue, Statement, StatementKind};
|
||||
use rustc::ty::{self, RegionKind};
|
||||
use rustc_data_structures::indexed_vec::Idx;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use syntax_pos::Span;
|
||||
|
||||
use super::borrow_set::BorrowData;
|
||||
use super::{Context, MirBorrowckCtxt};
|
||||
use super::{InitializationRequiringAction, PrefixSet};
|
||||
use super::borrow_set::BorrowData;
|
||||
|
||||
use dataflow::{FlowAtLocation, MovingOutStatements};
|
||||
use dataflow::move_paths::MovePathIndex;
|
||||
use dataflow::{FlowAtLocation, MovingOutStatements};
|
||||
use util::borrowck_errors::{BorrowckErrors, Origin};
|
||||
|
||||
impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
||||
|
|
@ -40,13 +40,9 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
.collect::<Vec<_>>();
|
||||
|
||||
if mois.is_empty() {
|
||||
let root_place = self.prefixes(&place, PrefixSet::All)
|
||||
.last()
|
||||
.unwrap();
|
||||
let root_place = self.prefixes(&place, PrefixSet::All).last().unwrap();
|
||||
|
||||
if self.moved_error_reported
|
||||
.contains(&root_place.clone())
|
||||
{
|
||||
if self.moved_error_reported.contains(&root_place.clone()) {
|
||||
debug!(
|
||||
"report_use_of_moved_or_uninitialized place: error about {:?} suppressed",
|
||||
root_place
|
||||
|
|
@ -54,8 +50,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
return;
|
||||
}
|
||||
|
||||
self.moved_error_reported
|
||||
.insert(root_place.clone());
|
||||
self.moved_error_reported.insert(root_place.clone());
|
||||
|
||||
let item_msg = match self.describe_place(place) {
|
||||
Some(name) => format!("`{}`", name),
|
||||
|
|
@ -178,7 +173,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)
|
||||
&self
|
||||
.describe_place(&borrow.borrowed_place)
|
||||
.unwrap_or("_".to_owned()),
|
||||
Origin::Mir,
|
||||
);
|
||||
|
|
@ -287,8 +283,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
"mutable",
|
||||
) {
|
||||
(BorrowKind::Shared, lft, _, BorrowKind::Mut { .. }, _, rgt)
|
||||
| (BorrowKind::Mut { .. }, _, lft, BorrowKind::Shared, rgt, _) => {
|
||||
tcx.cannot_reborrow_already_borrowed(
|
||||
| (BorrowKind::Mut { .. }, _, lft, BorrowKind::Shared, rgt, _) => tcx
|
||||
.cannot_reborrow_already_borrowed(
|
||||
span,
|
||||
&desc_place,
|
||||
"",
|
||||
|
|
@ -299,11 +295,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
"",
|
||||
None,
|
||||
Origin::Mir,
|
||||
)
|
||||
}
|
||||
),
|
||||
|
||||
(BorrowKind::Mut { .. }, _, _, BorrowKind::Mut { .. }, _, _) => {
|
||||
tcx.cannot_mutably_borrow_multiply(
|
||||
(BorrowKind::Mut { .. }, _, _, BorrowKind::Mut { .. }, _, _) => tcx
|
||||
.cannot_mutably_borrow_multiply(
|
||||
span,
|
||||
&desc_place,
|
||||
"",
|
||||
|
|
@ -311,18 +306,16 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
"",
|
||||
None,
|
||||
Origin::Mir,
|
||||
)
|
||||
}
|
||||
),
|
||||
|
||||
(BorrowKind::Unique, _, _, BorrowKind::Unique, _, _) => {
|
||||
tcx.cannot_uniquely_borrow_by_two_closures(
|
||||
(BorrowKind::Unique, _, _, BorrowKind::Unique, _, _) => tcx
|
||||
.cannot_uniquely_borrow_by_two_closures(
|
||||
span,
|
||||
&desc_place,
|
||||
issued_span,
|
||||
None,
|
||||
Origin::Mir,
|
||||
)
|
||||
}
|
||||
),
|
||||
|
||||
(BorrowKind::Unique, _, _, _, _, _) => tcx.cannot_uniquely_borrow_by_one_closure(
|
||||
span,
|
||||
|
|
@ -335,8 +328,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
Origin::Mir,
|
||||
),
|
||||
|
||||
(BorrowKind::Shared, lft, _, BorrowKind::Unique, _, _) => {
|
||||
tcx.cannot_reborrow_already_uniquely_borrowed(
|
||||
(BorrowKind::Shared, lft, _, BorrowKind::Unique, _, _) => tcx
|
||||
.cannot_reborrow_already_uniquely_borrowed(
|
||||
span,
|
||||
&desc_place,
|
||||
"",
|
||||
|
|
@ -345,11 +338,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
"",
|
||||
None,
|
||||
Origin::Mir,
|
||||
)
|
||||
}
|
||||
),
|
||||
|
||||
(BorrowKind::Mut { .. }, _, lft, BorrowKind::Unique, _, _) => {
|
||||
tcx.cannot_reborrow_already_uniquely_borrowed(
|
||||
(BorrowKind::Mut { .. }, _, lft, BorrowKind::Unique, _, _) => tcx
|
||||
.cannot_reborrow_already_uniquely_borrowed(
|
||||
span,
|
||||
&desc_place,
|
||||
"",
|
||||
|
|
@ -358,8 +350,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
"",
|
||||
None,
|
||||
Origin::Mir,
|
||||
)
|
||||
}
|
||||
),
|
||||
|
||||
(BorrowKind::Shared, _, _, BorrowKind::Shared, _, _) => unreachable!(),
|
||||
};
|
||||
|
|
@ -395,7 +386,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
) {
|
||||
let drop_span = place_span.1;
|
||||
let scope_tree = self.tcx.region_scope_tree(self.mir_def_id);
|
||||
let root_place = self.prefixes(&borrow.borrowed_place, PrefixSet::All)
|
||||
let root_place = self
|
||||
.prefixes(&borrow.borrowed_place, PrefixSet::All)
|
||||
.last()
|
||||
.unwrap();
|
||||
|
||||
|
|
@ -405,7 +397,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
_ => drop_span,
|
||||
};
|
||||
|
||||
if self.access_place_error_reported
|
||||
if self
|
||||
.access_place_error_reported
|
||||
.contains(&(root_place.clone(), borrow_span))
|
||||
{
|
||||
debug!(
|
||||
|
|
@ -475,8 +468,11 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
| (RegionKind::ReClosureBound(_), _)
|
||||
| (RegionKind::ReCanonical(_), _)
|
||||
| (RegionKind::ReErased, _) => {
|
||||
span_bug!(drop_span, "region {:?} does not make sense in this context",
|
||||
borrow.region);
|
||||
span_bug!(
|
||||
drop_span,
|
||||
"region {:?} does not make sense in this context",
|
||||
borrow.region
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -764,9 +760,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
Place::Static(ref static_) => self.describe_field_from_ty(&static_.ty, field),
|
||||
Place::Projection(ref proj) => match proj.elem {
|
||||
ProjectionElem::Deref => self.describe_field(&proj.base, field),
|
||||
ProjectionElem::Downcast(def, variant_index) => {
|
||||
format!("{}", def.variants[variant_index].fields[field.index()].ident)
|
||||
}
|
||||
ProjectionElem::Downcast(def, variant_index) => format!(
|
||||
"{}",
|
||||
def.variants[variant_index].fields[field.index()].ident
|
||||
),
|
||||
ProjectionElem::Field(_, field_type) => {
|
||||
self.describe_field_from_ty(&field_type, field)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use borrow_check::borrow_set::BorrowData;
|
||||
use borrow_check::nll::region_infer::{Cause, RegionInferenceContext};
|
||||
use borrow_check::{Context, MirBorrowckCtxt, WriteKind};
|
||||
use borrow_check::borrow_set::BorrowData;
|
||||
use rustc::mir::visit::{MirVisitable, PlaceContext, Visitor};
|
||||
use rustc::mir::{Local, Location, Mir, Place};
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
|
|
@ -45,69 +45,68 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
let borrow_region_vid = regioncx.to_region_vid(borrow.region);
|
||||
if let Some(cause) = regioncx.why_region_contains_point(borrow_region_vid, context.loc) {
|
||||
match cause {
|
||||
Cause::LiveVar(local, location) => {
|
||||
match find_regular_use(mir, regioncx, borrow, location, local) {
|
||||
Some(p) => {
|
||||
Cause::LiveVar(local, location) => match find_regular_use(
|
||||
mir, regioncx, borrow, location, local,
|
||||
) {
|
||||
Some(p) => {
|
||||
err.span_label(mir.source_info(p).span, format!("borrow later used here"));
|
||||
}
|
||||
|
||||
None => {
|
||||
span_bug!(
|
||||
mir.source_info(context.loc).span,
|
||||
"Cause should end in a LiveVar"
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
Cause::DropVar(local, location) => match find_drop_use(
|
||||
mir, regioncx, borrow, location, local,
|
||||
) {
|
||||
Some(p) => match &mir.local_decls[local].name {
|
||||
Some(local_name) => {
|
||||
err.span_label(
|
||||
mir.source_info(p).span,
|
||||
format!("borrow later used here"),
|
||||
format!("borrow later used here, when `{}` is dropped", local_name),
|
||||
);
|
||||
}
|
||||
|
||||
None => {
|
||||
span_bug!(
|
||||
mir.source_info(context.loc).span,
|
||||
"Cause should end in a LiveVar"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some((WriteKind::StorageDeadOrDrop, place)) = kind_place {
|
||||
if let Place::Local(borrowed_local) = place {
|
||||
let dropped_local_scope =
|
||||
mir.local_decls[local].visibility_scope;
|
||||
let borrowed_local_scope =
|
||||
mir.local_decls[*borrowed_local].visibility_scope;
|
||||
|
||||
Cause::DropVar(local, location) => {
|
||||
match find_drop_use(mir, regioncx, borrow, location, local) {
|
||||
Some(p) => match &mir.local_decls[local].name {
|
||||
Some(local_name) => {
|
||||
err.span_label(
|
||||
mir.source_info(p).span,
|
||||
format!(
|
||||
"borrow later used here, when `{}` is dropped",
|
||||
local_name
|
||||
),
|
||||
);
|
||||
|
||||
if let Some((WriteKind::StorageDeadOrDrop, place)) = kind_place {
|
||||
if let Place::Local(borrowed_local) = place {
|
||||
let dropped_local_scope = mir.local_decls[local].visibility_scope;
|
||||
let borrowed_local_scope = mir.local_decls[*borrowed_local].visibility_scope;
|
||||
|
||||
if mir.is_sub_scope(borrowed_local_scope, dropped_local_scope) {
|
||||
err.note("values in a scope are dropped in the opposite order they are defined");
|
||||
}
|
||||
if mir.is_sub_scope(borrowed_local_scope, dropped_local_scope) {
|
||||
err.note(
|
||||
"values in a scope are dropped \
|
||||
in the opposite order they are defined",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {
|
||||
err.span_label(
|
||||
mir.local_decls[local].source_info.span,
|
||||
"borrow may end up in a temporary, created here",
|
||||
);
|
||||
|
||||
err.span_label(
|
||||
mir.source_info(p).span,
|
||||
"temporary later dropped here, \
|
||||
potentially using the reference",
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
}
|
||||
None => {
|
||||
span_bug!(
|
||||
mir.source_info(context.loc).span,
|
||||
"Cause should end in a DropVar"
|
||||
err.span_label(
|
||||
mir.local_decls[local].source_info.span,
|
||||
"borrow may end up in a temporary, created here",
|
||||
);
|
||||
|
||||
err.span_label(
|
||||
mir.source_info(p).span,
|
||||
"temporary later dropped here, \
|
||||
potentially using the reference",
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
None => {
|
||||
span_bug!(
|
||||
mir.source_info(context.loc).span,
|
||||
"Cause should end in a DropVar"
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Cause::UniversalRegion(region_vid) => {
|
||||
if let Some(region) = regioncx.to_error_region(region_vid) {
|
||||
|
|
@ -206,15 +205,12 @@ impl<'gcx, 'tcx> UseFinder<'gcx, 'tcx> {
|
|||
..p
|
||||
});
|
||||
} else {
|
||||
stack.extend(
|
||||
block_data
|
||||
.terminator()
|
||||
.successors()
|
||||
.map(|&basic_block| Location {
|
||||
statement_index: 0,
|
||||
block: basic_block,
|
||||
}),
|
||||
);
|
||||
stack.extend(block_data.terminator().successors().map(|&basic_block| {
|
||||
Location {
|
||||
statement_index: 0,
|
||||
block: basic_block,
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue