Skip to content

Commit dadd817

Browse files
committed
Fix generating CTFE backtrace on optimized MIR
During MIR optimization, we may inline function calls acrross crates. While we can inline the corresponding scopes into `Body.source_scopes`, we cannot inline the corresponding data from `source_scope_local_data`, since it references crate-local data. This commit makes us fall back to the root lint level when generating a CTFE backtrace, if it was not possible to find crate-local data for a scope in `source_scope_local_data`. Fixes rust-lang#66137
1 parent a333eed commit dadd817

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/librustc/mir/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ pub struct Body<'tcx> {
105105

106106
/// Crate-local information for each source scope, that can't (and
107107
/// needn't) be tracked across crates.
108+
///
109+
/// Before optimizations run, every scope in `source_scopes` is guarnateed
110+
/// to have an entry in `source_scope_local_data` (assuming it is `ClearCrossCrate::Set`).
111+
///
112+
/// However, after optimizations are run, there may be some scopes with no entry
113+
/// in `source_scope_local_data:`. This is due to the fact that MIR inlining can
114+
/// cause scopes from a different crate to be inlined into this `Body`, which
115+
/// cannot have crate-local data.
108116
pub source_scope_local_data: ClearCrossCrate<IndexVec<SourceScope, SourceScopeLocalData>>,
109117

110118
/// The yield type of the function, if it is a generator.

src/librustc_mir/interpret/eval_context.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,12 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
816816
block.terminator().source_info
817817
};
818818
match body.source_scope_local_data {
819-
mir::ClearCrossCrate::Set(ref ivs) => Some(ivs[source_info.scope].lint_root),
819+
// The scope may have been inlined from a different crate, in which
820+
// case we will not have crate-local data for it. If that is the case,
821+
// we just use our root lint level.
822+
mir::ClearCrossCrate::Set(ref ivs) => {
823+
ivs.get(source_info.scope).map(|d| d.lint_root)
824+
}
820825
mir::ClearCrossCrate::Clear => None,
821826
}
822827
});

0 commit comments

Comments
 (0)