Skip to content

Commit 2be4cc0

Browse files
committedNov 1, 2017
Auto merge of #45538 - nikomatsakis:nll-liveness, r=pnkfelix
enable non-lexical lifetimes in the MIR borrow checker This PR, joint work with @spastorino, fills out the NLL infrastructure and integrates it with the borrow checker. **Don't get too excited:** it includes still a number of hacks (the subtyping code is particularly hacky). However, it *does* kinda' work. =) The final commit demonstrates this by including a test that -- with both the AST borrowck and MIR borrowck -- reports an error by default. But if you pass `-Znll`, you only get an error from the AST borrowck, demonstrating that the integration succeeds: ``` struct MyStruct { field: String } fn main() { let mut my_struct = MyStruct { field: format!("Hello") }; let value = &my_struct.field; if value.is_empty() { my_struct.field.push_str("Hello, world!"); //~^ ERROR cannot borrow (Ast) } } ```
2 parents a3f990d + aae3e74 commit 2be4cc0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2102
-622
lines changed
 

‎src/librustc/middle/region.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub struct BlockRemainder {
158158

159159
newtype_index!(FirstStatementIndex
160160
{
161-
DEBUG_NAME = "",
161+
DEBUG_FORMAT = "{}",
162162
MAX = SCOPE_DATA_REMAINDER_MAX,
163163
});
164164

‎src/librustc/mir/mod.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ pub enum BorrowKind {
417417

418418
newtype_index!(Local
419419
{
420-
DEBUG_NAME = "_",
420+
DEBUG_FORMAT = "_{}",
421421
const RETURN_POINTER = 0,
422422
});
423423

@@ -553,7 +553,7 @@ pub struct UpvarDecl {
553553
///////////////////////////////////////////////////////////////////////////
554554
// BasicBlock
555555

556-
newtype_index!(BasicBlock { DEBUG_NAME = "bb" });
556+
newtype_index!(BasicBlock { DEBUG_FORMAT = "bb{}" });
557557

558558
///////////////////////////////////////////////////////////////////////////
559559
// BasicBlockData and Terminator
@@ -1135,7 +1135,7 @@ pub type LvalueProjection<'tcx> = Projection<'tcx, Lvalue<'tcx>, Local, Ty<'tcx>
11351135
/// and the index is a local.
11361136
pub type LvalueElem<'tcx> = ProjectionElem<'tcx, Local, Ty<'tcx>>;
11371137

1138-
newtype_index!(Field { DEBUG_NAME = "field" });
1138+
newtype_index!(Field { DEBUG_FORMAT = "field[{}]" });
11391139

11401140
impl<'tcx> Lvalue<'tcx> {
11411141
pub fn field(self, f: Field, ty: Ty<'tcx>) -> Lvalue<'tcx> {
@@ -1202,7 +1202,7 @@ impl<'tcx> Debug for Lvalue<'tcx> {
12021202

12031203
newtype_index!(VisibilityScope
12041204
{
1205-
DEBUG_NAME = "scope",
1205+
DEBUG_FORMAT = "scope[{}]",
12061206
const ARGUMENT_VISIBILITY_SCOPE = 0,
12071207
});
12081208

@@ -1529,7 +1529,7 @@ pub struct Constant<'tcx> {
15291529
pub literal: Literal<'tcx>,
15301530
}
15311531

1532-
newtype_index!(Promoted { DEBUG_NAME = "promoted" });
1532+
newtype_index!(Promoted { DEBUG_FORMAT = "promoted[{}]" });
15331533

15341534
#[derive(Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
15351535
pub enum Literal<'tcx> {
@@ -1637,6 +1637,14 @@ impl fmt::Debug for Location {
16371637
}
16381638

16391639
impl Location {
1640+
/// Returns the location immediately after this one within the enclosing block.
1641+
///
1642+
/// Note that if this location represents a terminator, then the
1643+
/// resulting location would be out of bounds and invalid.
1644+
pub fn successor_within_block(&self) -> Location {
1645+
Location { block: self.block, statement_index: self.statement_index + 1 }
1646+
}
1647+
16401648
pub fn dominates(&self, other: &Location, dominators: &Dominators<BasicBlock>) -> bool {
16411649
if self.block == other.block {
16421650
self.statement_index <= other.statement_index

0 commit comments

Comments
 (0)
Please sign in to comment.