Skip to content

Commit 1c2483e

Browse files
committed
Address review feedback.
1 parent 99165ce commit 1c2483e

File tree

4 files changed

+10
-17
lines changed

4 files changed

+10
-17
lines changed

src/librustc_codegen_ssa/mir/block.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -771,14 +771,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
771771
}
772772

773773
let needs_location =
774-
instance.map(|i| i.def.requires_caller_location(self.cx.tcx())).unwrap_or_default();
774+
instance.map_or(false, |i| i.def.requires_caller_location(self.cx.tcx()));
775775
if needs_location {
776776
assert_eq!(
777777
fn_abi.args.len(), args.len() + 1,
778778
"#[track_caller] fn's must have 1 more argument in their ABI than in their MIR",
779779
);
780780
let location = self.get_caller_location(&mut bx, span);
781-
let last_arg = &fn_abi.args.last().unwrap();
781+
let last_arg = fn_abi.args.last().unwrap();
782782
self.codegen_argument(&mut bx, location, &mut llargs, last_arg);
783783
}
784784

src/librustc_codegen_ssa/mir/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,10 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
435435
"#[track_caller] fn's must have 1 more argument in their ABI than in their MIR",
436436
);
437437

438-
let arg = &fx.fn_abi.args.last().unwrap();
438+
let arg = fx.fn_abi.args.last().unwrap();
439439
match arg.mode {
440440
PassMode::Direct(_) => (),
441-
_ => panic!("caller location must be PassMode::Direct, found {:?}", arg.mode),
441+
_ => bug!("caller location must be PassMode::Direct, found {:?}", arg.mode),
442442
}
443443

444444
fx.caller_location = Some(OperandRef {

src/librustc_mir/interpret/intrinsics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
112112
// `src/librustc/ty/constness.rs`
113113
match intrinsic_name {
114114
sym::caller_location => {
115-
let span = self.find_closest_untracked_caller_location(span);
115+
let span = self.find_closest_untracked_caller_location().unwrap_or(span);
116116
let location = self.alloc_caller_location_for_span(span);
117117
self.write_scalar(location.ptr, dest)?;
118118
}

src/librustc_mir/interpret/intrinsics/caller_location.rs

+5-12
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,17 @@ use crate::interpret::{Scalar, MemoryKind, MPlaceTy, intrinsics::{InterpCx, Mach
77

88
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
99
/// Walks up the callstack from the intrinsic's callsite, searching for the first frame which is
10-
/// not `#[track_caller]`. Returns the (passed) span of the intrinsic's callsite if the first
11-
/// frame in the stack is untracked so that we can display the callsite of the intrinsic within
12-
/// that function.
13-
crate fn find_closest_untracked_caller_location(
14-
&self,
15-
intrinsic_loc: Span,
16-
) -> Span {
17-
debug!("finding closest untracked caller relative to {:?}", intrinsic_loc);
18-
19-
let mut caller_span = intrinsic_loc;
10+
/// not `#[track_caller]`.
11+
crate fn find_closest_untracked_caller_location(&self) -> Option<Span> {
12+
let mut caller_span = None;
2013
for next_caller in self.stack.iter().rev() {
2114
if !next_caller.instance.def.requires_caller_location(*self.tcx) {
2215
return caller_span;
2316
}
24-
caller_span = next_caller.span;
17+
caller_span = Some(next_caller.span);
2518
}
2619

27-
intrinsic_loc
20+
caller_span
2821
}
2922

3023
/// Allocate a `const core::panic::Location` with the provided filename and line/column numbers.

0 commit comments

Comments
 (0)