diff options
| author | Ralf Jung <post@ralfj.de> | 2023-10-28 16:16:15 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2023-10-28 16:16:15 +0200 |
| commit | 04fa124feb6e3f78fe9bea9fac7b4cbd033c9160 (patch) | |
| tree | 31b24ddfb93998aa682372ebf5122275ffa7747b /compiler/rustc_const_eval/src/interpret | |
| parent | 351d532a27c56f7af82feaa7d612c412fd5c221c (diff) | |
| download | rust-04fa124feb6e3f78fe9bea9fac7b4cbd033c9160.tar.gz rust-04fa124feb6e3f78fe9bea9fac7b4cbd033c9160.zip | |
share the track_caller handling within a mir::Body
Diffstat (limited to 'compiler/rustc_const_eval/src/interpret')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/eval_context.rs | 40 |
1 files changed, 11 insertions, 29 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index f3c19495a61..07cab5e3400 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -622,35 +622,17 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } } - // Note: this must be kept in sync with get_caller_location from cg_ssa. - - // Walk up the `SourceScope`s, in case some of them are from MIR inlining. - // If so, the starting `source_info.span` is in the innermost inlined - // function, and will be replaced with outer callsite spans as long - // as the inlined functions were `#[track_caller]`. - loop { - let scope_data = &frame.body.source_scopes[source_info.scope]; - - if let Some((callee, callsite_span)) = scope_data.inlined { - // Stop inside the most nested non-`#[track_caller]` function, - // before ever reaching its caller (which is irrelevant). - if !callee.def.requires_caller_location(*self.tcx) { - return source_info.span; - } - source_info.span = callsite_span; - } - - // Skip past all of the parents with `inlined: None`. - match scope_data.inlined_parent_scope { - Some(parent) => source_info.scope = parent, - None => break, - } - } - - // Stop inside the most nested non-`#[track_caller]` function, - // before ever reaching its caller (which is irrelevant). - if !frame.instance.def.requires_caller_location(*self.tcx) { - return source_info.span; + let caller_location = if frame.instance.def.requires_caller_location(*self.tcx) { + // We use `Err(())` as indication that we should continue up the call stack since + // this is a `#[track_caller]` function. + Some(Err(())) + } else { + None + }; + if let Ok(span) = + frame.body.caller_location_span(source_info, caller_location, *self.tcx, Ok) + { + return span; } } |
