Skip to content

Commit a8eea62

Browse files
committed
expose span to M::assert_panic, and provide helper to turn that into CallerLocation
1 parent b1aa3ca commit a8eea62

File tree

6 files changed

+20
-10
lines changed

6 files changed

+20
-10
lines changed

src/librustc_mir/const_eval.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
397397

398398
fn assert_panic(
399399
ecx: &mut InterpCx<'mir, 'tcx, Self>,
400+
_span: Span,
400401
msg: &AssertMessage<'tcx>,
401402
_unwind: Option<mir::BasicBlock>,
402403
) -> InterpResult<'tcx> {

src/librustc_mir/interpret/intrinsics.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
110110

111111
match intrinsic_name {
112112
"caller_location" => {
113-
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
114-
let caller = self.tcx.sess.source_map().lookup_char_pos(topmost.lo());
115-
let location = self.alloc_caller_location(
116-
Symbol::intern(&caller.file.name.to_string()),
117-
caller.line as u32,
118-
caller.col_display as u32 + 1,
119-
)?;
113+
let location = self.alloc_caller_location_for_span(span)?;
120114
self.write_scalar(location.ptr, dest)?;
121115
}
122116

src/librustc_mir/interpret/intrinsics/caller_location.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ use rustc::middle::lang_items::PanicLocationLangItem;
22
use rustc::mir::interpret::{Pointer, PointerArithmetic, Scalar};
33
use rustc::ty::subst::Subst;
44
use rustc_target::abi::{LayoutOf, Size};
5-
use syntax_pos::Symbol;
5+
use syntax_pos::{Symbol, Span};
66

77
use crate::interpret::{MemoryKind, MPlaceTy, intrinsics::{InterpCx, InterpResult, Machine}};
88

99
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
10-
pub fn alloc_caller_location(
10+
crate fn alloc_caller_location(
1111
&mut self,
1212
filename: Symbol,
1313
line: u32,
@@ -47,4 +47,17 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
4747

4848
Ok(location)
4949
}
50+
51+
pub fn alloc_caller_location_for_span(
52+
&mut self,
53+
span: Span,
54+
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
55+
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
56+
let caller = self.tcx.sess.source_map().lookup_char_pos(topmost.lo());
57+
self.alloc_caller_location(
58+
Symbol::intern(&caller.file.name.to_string()),
59+
caller.line as u32,
60+
caller.col_display as u32 + 1,
61+
)
62+
}
5063
}

src/librustc_mir/interpret/machine.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
178178
/// Called to evaluate `Assert` MIR terminators that trigger a panic.
179179
fn assert_panic(
180180
ecx: &mut InterpCx<'mir, 'tcx, Self>,
181+
span: Span,
181182
msg: &AssertMessage<'tcx>,
182183
unwind: Option<mir::BasicBlock>,
183184
) -> InterpResult<'tcx>;

src/librustc_mir/interpret/terminator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
122122
if expected == cond_val {
123123
self.go_to_block(target);
124124
} else {
125-
M::assert_panic(self, msg, cleanup)?;
125+
M::assert_panic(self, terminator.source_info.span, msg, cleanup)?;
126126
}
127127
}
128128

src/librustc_mir/transform/const_prop.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine {
158158

159159
fn assert_panic(
160160
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
161+
_span: Span,
161162
_msg: &rustc::mir::interpret::AssertMessage<'tcx>,
162163
_unwind: Option<rustc::mir::BasicBlock>,
163164
) -> InterpResult<'tcx> {

0 commit comments

Comments
 (0)