Skip to content

Commit

Permalink
Add method to Mir that maps a Location to its SourceInfo.
Browse files Browse the repository at this point in the history
  • Loading branch information
pnkfelix committed Oct 4, 2017
1 parent 43fb82d commit 117586e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/librustc/mir/mod.rs
Expand Up @@ -284,6 +284,19 @@ impl<'tcx> Mir<'tcx> {
debug_assert!(location.statement_index < block.statements.len());
block.statements[location.statement_index].make_nop()
}

/// Returns the source info associated with `location`.
pub fn source_info(&self, location: Location) -> &SourceInfo {
let block = &self[location.block];
let stmts = &block.statements;
let idx = location.statement_index;
if location.statement_index < stmts.len() {
&stmts[idx].source_info
} else {
assert!(location.statement_index == stmts.len());
&block.terminator().source_info
}
}
}

#[derive(Clone, Debug)]
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_mir/borrow_check.rs
Expand Up @@ -1126,9 +1126,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>

// Retrieve span of given borrow from the current MIR representation
fn retrieve_borrow_span(&self, borrow: &BorrowData) -> Span {
self.mir.basic_blocks()[borrow.location.block]
.statements[borrow.location.statement_index]
.source_info.span
self.mir.source_info(borrow.location).span
}
}

Expand Down

0 comments on commit 117586e

Please sign in to comment.