Skip to content

Commit 117586e

Browse files
committed
Add method to Mir that maps a Location to its SourceInfo.
1 parent 43fb82d commit 117586e

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/librustc/mir/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,19 @@ impl<'tcx> Mir<'tcx> {
284284
debug_assert!(location.statement_index < block.statements.len());
285285
block.statements[location.statement_index].make_nop()
286286
}
287+
288+
/// Returns the source info associated with `location`.
289+
pub fn source_info(&self, location: Location) -> &SourceInfo {
290+
let block = &self[location.block];
291+
let stmts = &block.statements;
292+
let idx = location.statement_index;
293+
if location.statement_index < stmts.len() {
294+
&stmts[idx].source_info
295+
} else {
296+
assert!(location.statement_index == stmts.len());
297+
&block.terminator().source_info
298+
}
299+
}
287300
}
288301

289302
#[derive(Clone, Debug)]

src/librustc_mir/borrow_check.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,9 +1126,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
11261126

11271127
// Retrieve span of given borrow from the current MIR representation
11281128
fn retrieve_borrow_span(&self, borrow: &BorrowData) -> Span {
1129-
self.mir.basic_blocks()[borrow.location.block]
1130-
.statements[borrow.location.statement_index]
1131-
.source_info.span
1129+
self.mir.source_info(borrow.location).span
11321130
}
11331131
}
11341132

0 commit comments

Comments
 (0)