Skip to content

Commit

Permalink
Fix tests after two-phase borrow rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphire-arches committed Mar 9, 2018
1 parent e4e377f commit 03f198f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/librustc_mir/dataflow/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<'a, 'tcx, MWF, P> dot::Labeller<'a> for Graph<'a, 'tcx, MWF, P>
// | | | | bb11[0]: active |
// +---------+----------------------------------+------------------+------------------+
// | [00-00] | _7 = const Foo::twiddle(move _8) | [0c-00] | [f3-0f] |
// +---------+----------------------------------+------------------+------------------+
// +---------+----------------------------------+------------------+------------------+
let mut v = Vec::new();
self.node_label_internal(n, &mut v, *n, self.mbcx.mir()).unwrap();
dot::LabelText::html(String::from_utf8(v).unwrap())
Expand Down Expand Up @@ -140,7 +140,7 @@ where MWF: MirWithFlowState<'tcx>,
block: BasicBlock,
mir: &Mir) -> io::Result<()> {
// Header rows
const HDRS: [&'static str; 4] = ["ENTRY", "MIR", "GEN", "KILL"];
const HDRS: [&'static str; 4] = ["ENTRY", "MIR", "BLOCK GENS", "BLOCK KILLS"];
const HDR_FMT: &'static str = "bgcolor=\"grey\"";
write!(w, "<table><tr><td rowspan=\"{}\">", HDRS.len())?;
write!(w, "{:?}", block.index())?;
Expand Down
27 changes: 10 additions & 17 deletions src/librustc_mir/dataflow/impls/borrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,6 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
}
}

/// Represents what kind of usage we've seen.
enum PlaceUsageType {
/// No usage seen
None,
/// Has been seen as the argument to a StorageDead statement. This is required to
/// gracefully handle cases where user code has an unneeded
StorageKilled,
/// Has been used in borrow-activating context
BorrowActivateUsage
}

/// A MIR visitor that determines if a specific place is used in a two-phase activating
/// manner in a given chunk of MIR.
struct ContainsUseOfPlace<'b, 'tcx: 'b> {
Expand Down Expand Up @@ -404,7 +393,8 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
let stmt = &block_data.statements[location.statement_index];
if let mir::StatementKind::EndRegion(region_scope) = stmt.kind {
if &ReScope(region_scope) == region {
// We encountered an EndRegion statement that terminates the provided region
// We encountered an EndRegion statement that terminates the provided
// region
return true;
}
}
Expand All @@ -430,7 +420,7 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
/// See
/// - https://github.com/rust-lang/rust/issues/48431
/// for detailed design notes.
/// See the TODO in the body of the function for notes on extending support to more
/// See the FIXME in the body of the function for notes on extending support to more
/// general two-phased borrows.
fn compute_activation_location(&self,
start_location: Location,
Expand Down Expand Up @@ -473,7 +463,7 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
}

if self.location_contains_use(curr_loc, assigned_place) {
// TODO: Handle this case a little more gracefully. Perhaps collect
// FIXME: Handle this case a little more gracefully. Perhaps collect
// all uses in a vector, and find the point in the CFG that dominates
// all of them?
// Right now this is sufficient though since there should only be exactly
Expand Down Expand Up @@ -596,7 +586,9 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
// `_sets`.
}

fn before_statement_effect(&self, sets: &mut BlockSets<ReserveOrActivateIndex>, location: Location) {
fn before_statement_effect(&self,
sets: &mut BlockSets<ReserveOrActivateIndex>,
location: Location) {
debug!("Borrows::before_statement_effect sets: {:?} location: {:?}", sets, location);
self.kill_loans_out_of_scope_at_location(sets, location);
}
Expand Down Expand Up @@ -662,7 +654,6 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {

// Issue #46746: Two-phase borrows handles
// stmts of form `Tmp = &mut Borrow` ...
// XXX bob_twinkles experiment with removing this
match lhs {
Place::Local(..) | Place::Static(..) => {} // okay
Place::Projection(..) => {
Expand Down Expand Up @@ -704,7 +695,9 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
}
}

fn before_terminator_effect(&self, sets: &mut BlockSets<ReserveOrActivateIndex>, location: Location) {
fn before_terminator_effect(&self,
sets: &mut BlockSets<ReserveOrActivateIndex>,
location: Location) {
debug!("Borrows::before_terminator_effect sets: {:?} location: {:?}", sets, location);
self.kill_loans_out_of_scope_at_location(sets, location);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// in the type of `p` includes the points after `&v[0]` up to (but not
// including) the call to `use_x`. The `else` branch is not included.

// compile-flags:-Zborrowck=compare -Znll
// compile-flags:-Zborrowck=compare -Znll -Ztwo-phase-borrows

#![allow(warnings)]
#![feature(rustc_attrs)]
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/issue-45157.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ fn main() {
let nref = &u.z.c;
//~^ ERROR cannot borrow `u.z.c` as immutable because it is also borrowed as mutable [E0502]
println!("{} {}", mref, nref)
//~^ ERROR cannot borrow `u.s.a` as mutable because it is also borrowed as immutable [E0502]
}
}

13 changes: 1 addition & 12 deletions src/test/ui/issue-45157.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,6 @@ LL | //~^ ERROR cannot borrow `u.z.c` as immutable because it is also bo
LL | println!("{} {}", mref, nref)
| ---- borrow later used here

error[E0502]: cannot borrow `u.s.a` as mutable because it is also borrowed as immutable
--> $DIR/issue-45157.rs:39:27
|
LL | let nref = &u.z.c;
| ------ immutable borrow occurs here
LL | //~^ ERROR cannot borrow `u.z.c` as immutable because it is also borrowed as mutable [E0502]
LL | println!("{} {}", mref, nref)
| ^^^^ ---- borrow later used here
| |
| mutable borrow occurs here

error: aborting due to 2 previous errors
error: aborting due to previous error

If you want more information on this error, try using "rustc --explain E0502"

0 comments on commit 03f198f

Please sign in to comment.