Rollup merge of #117317 - RalfJung:track-caller, r=oli-obk · rust-lang/rust@aed0ed2

@@ -430,47 +430,11 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {

430430

}

431431

}

432432433-

// Note: must be kept in sync with get_caller_location from cg_ssa

434-

pub(crate) fn get_caller_location(&mut self, mut source_info: mir::SourceInfo) -> CValue<'tcx> {

435-

let span_to_caller_location = |fx: &mut FunctionCx<'_, '_, 'tcx>, span: Span| {

436-

use rustc_session::RemapFileNameExt;

437-

let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);

438-

let caller = fx.tcx.sess.source_map().lookup_char_pos(topmost.lo());

439-

let const_loc = fx.tcx.const_caller_location((

440-

rustc_span::symbol::Symbol::intern(

441-

&caller.file.name.for_codegen(&fx.tcx.sess).to_string_lossy(),

442-

),

443-

caller.line as u32,

444-

caller.col_display as u32 + 1,

445-

));

446-

crate::constant::codegen_const_value(fx, const_loc, fx.tcx.caller_location_ty())

447-

};

448-449-

// Walk up the `SourceScope`s, in case some of them are from MIR inlining.

450-

// If so, the starting `source_info.span` is in the innermost inlined

451-

// function, and will be replaced with outer callsite spans as long

452-

// as the inlined functions were `#[track_caller]`.

453-

loop {

454-

let scope_data = &self.mir.source_scopes[source_info.scope];

455-456-

if let Some((callee, callsite_span)) = scope_data.inlined {

457-

// Stop inside the most nested non-`#[track_caller]` function,

458-

// before ever reaching its caller (which is irrelevant).

459-

if !callee.def.requires_caller_location(self.tcx) {

460-

return span_to_caller_location(self, source_info.span);

461-

}

462-

source_info.span = callsite_span;

463-

}

464-465-

// Skip past all of the parents with `inlined: None`.

466-

match scope_data.inlined_parent_scope {

467-

Some(parent) => source_info.scope = parent,

468-

None => break,

469-

}

470-

}

471-472-

// No inlined `SourceScope`s, or all of them were `#[track_caller]`.

473-

self.caller_location.unwrap_or_else(|| span_to_caller_location(self, source_info.span))

433+

pub(crate) fn get_caller_location(&mut self, source_info: mir::SourceInfo) -> CValue<'tcx> {

434+

self.mir.caller_location_span(source_info, self.caller_location, self.tcx, |span| {

435+

let const_loc = self.tcx.span_as_caller_location(span);

436+

crate::constant::codegen_const_value(self, const_loc, self.tcx.caller_location_ty())

437+

})

474438

}

475439476440

pub(crate) fn anonymous_str(&mut self, msg: &str) -> Value {