Add method to Mir that maps a Location to its SourceInfo.

This commit is contained in:
Felix S. Klock II 2017-10-04 11:46:35 +02:00
parent 43fb82d2fa
commit 117586e6e9
2 changed files with 14 additions and 3 deletions

View file

@ -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)]

View file

@ -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
}
}