minor refactorings to fix trait import issue
This commit is contained in:
parent
f60788b9b2
commit
3f0ce0858e
2 changed files with 11 additions and 42 deletions
|
|
@ -17,7 +17,7 @@ use rustc::hir::map::definitions::DefPathData;
|
|||
use rustc::infer::InferCtxt;
|
||||
use rustc::ty::{self, ParamEnv, TyCtxt};
|
||||
use rustc::ty::maps::Providers;
|
||||
use rustc::mir::{AssertMessage, BasicBlock, BorrowKind, Local, Location, Place, Visitor};
|
||||
use rustc::mir::{AssertMessage, BasicBlock, BorrowKind, Local, Location, Place};
|
||||
use rustc::mir::{Mir, Mutability, Operand, Projection, ProjectionElem, Rvalue};
|
||||
use rustc::mir::{Field, Statement, StatementKind, Terminator, TerminatorKind};
|
||||
use rustc::mir::ClosureRegionRequirements;
|
||||
|
|
@ -43,6 +43,7 @@ use dataflow::indexes::BorrowIndex;
|
|||
use dataflow::move_paths::{IllegalMoveOriginKind, MoveError};
|
||||
use dataflow::move_paths::{HasMoveData, LookupResult, MoveData, MovePathIndex};
|
||||
use util::borrowck_errors::{BorrowckErrors, Origin};
|
||||
use util::collect_writes::FindAssignments;
|
||||
|
||||
use std::iter;
|
||||
|
||||
|
|
@ -56,37 +57,6 @@ mod prefixes;
|
|||
|
||||
use std::borrow::Cow;
|
||||
|
||||
struct FindLocalAssignmentVisitor {
|
||||
needle: Local,
|
||||
locations: Vec<Location>,
|
||||
placectxt: PlaceContext,
|
||||
location: Location,
|
||||
}
|
||||
|
||||
impl<'tcx> Visitor<'tcx> for FindLocalAssignmentVisitor {
|
||||
fn visit_local(&mut self,
|
||||
local: &Local,
|
||||
place_context: PlaceContext<'tcx>,
|
||||
location: Location) {
|
||||
if self.needle != *local {
|
||||
return;
|
||||
}
|
||||
|
||||
match place_context {
|
||||
PlaceContext::Store | PlaceContext::Call => {
|
||||
self.locations.push(location);
|
||||
}
|
||||
PlaceContext::AsmOutput | PlaceContext::Drop| PlaceContext::Inspect |
|
||||
PlaceContext::Borrow| PlaceContext::Projection| PlaceContext::Copy|
|
||||
PlaceContext::Move| PlaceContext::StorageLive| PlaceContext::StorageDead|
|
||||
PlaceContext::Validate => {
|
||||
}
|
||||
}
|
||||
|
||||
Visitor::visit_local(local,place_context,location)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) mod nll;
|
||||
|
||||
pub fn provide(providers: &mut Providers) {
|
||||
|
|
@ -1587,7 +1557,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
None => "immutable item".to_owned(),
|
||||
};
|
||||
|
||||
// call find_assignments() here
|
||||
let mut err = self.tcx
|
||||
.cannot_borrow_path_as_mutable(span, &item_msg, Origin::Mir);
|
||||
err.span_label(span, "cannot borrow as mutable");
|
||||
|
|
@ -1604,6 +1573,14 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||
if let Err(place_err) = self.is_mutable(place, is_local_mutation_allowed) {
|
||||
error_reported = true;
|
||||
|
||||
match *place{
|
||||
Place::Local(local) => {let locations = self.mir.find_assignments(local);
|
||||
|
||||
for n in &locations{
|
||||
debug!("locations ={:?}", n);}
|
||||
}
|
||||
_ => {}}
|
||||
|
||||
let item_msg = if error_reported{
|
||||
if let Some(name) = self.describe_place(place_err) {
|
||||
format!("`&`-reference {}", name)
|
||||
|
|
@ -2269,12 +2246,3 @@ impl ContextKind {
|
|||
}
|
||||
}
|
||||
|
||||
impl Mir {
|
||||
fn find_assignments(&self, local: Local, place_context:PlaceContext, location:Location) -> Vec<Location>
|
||||
{
|
||||
let mut visitor = FindLocalAssignmentVisitor { needle: local, locations: vec![], location:location, place_context: };
|
||||
visitor.visit_mir(self);
|
||||
visitor.locations
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ mod alignment;
|
|||
mod graphviz;
|
||||
pub(crate) mod pretty;
|
||||
pub mod liveness;
|
||||
pub mod collect_writes;
|
||||
|
||||
pub use self::alignment::is_disaligned;
|
||||
pub use self::pretty::{dump_enabled, dump_mir, write_mir_pretty, PassWhere};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue