Skip to content

Commit

Permalink
minor refactorings to fix trait import issue
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurikholkar committed Mar 10, 2018
1 parent f60788b commit 3f0ce08
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 42 deletions.
52 changes: 10 additions & 42 deletions src/librustc_mir/borrow_check/mod.rs
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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) {
Expand Down Expand Up @@ -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");
Expand All @@ -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)
Expand Down Expand Up @@ -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
}
}

1 change: 1 addition & 0 deletions src/librustc_mir/util/mod.rs
Expand Up @@ -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};
Expand Down

0 comments on commit 3f0ce08

Please sign in to comment.