Skip to content

Commit 7e7d007

Browse files
committed
Add SourceScope::inlined_instance
1 parent eba361a commit 7e7d007

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

compiler/rustc_codegen_ssa/src/mir/coverageinfo.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@ use super::FunctionCx;
99
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
1010
pub fn codegen_coverage(&self, bx: &mut Bx, coverage: Coverage, scope: SourceScope) {
1111
// Determine the instance that coverage data was originally generated for.
12-
let scope_data = &self.mir.source_scopes[scope];
13-
let instance = if let Some((inlined_instance, _)) = scope_data.inlined {
14-
self.monomorphize(inlined_instance)
15-
} else if let Some(inlined_scope) = scope_data.inlined_parent_scope {
16-
self.monomorphize(self.mir.source_scopes[inlined_scope].inlined.unwrap().0)
12+
let instance = if let Some(inlined) = scope.inlined_instance(&self.mir.source_scopes) {
13+
self.monomorphize(inlined)
1714
} else {
1815
self.instance
1916
};

compiler/rustc_middle/src/mir/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -1650,6 +1650,22 @@ impl SourceScope {
16501650
ClearCrossCrate::Clear => None,
16511651
}
16521652
}
1653+
1654+
/// The instance this source scope was inlined from, if any.
1655+
#[inline]
1656+
pub fn inlined_instance<'tcx>(
1657+
self,
1658+
source_scopes: &IndexVec<SourceScope, SourceScopeData<'tcx>>,
1659+
) -> Option<ty::Instance<'tcx>> {
1660+
let scope_data = &source_scopes[self];
1661+
if let Some((inlined_instance, _)) = scope_data.inlined {
1662+
Some(inlined_instance)
1663+
} else if let Some(inlined_scope) = scope_data.inlined_parent_scope {
1664+
Some(source_scopes[inlined_scope].inlined.unwrap().0)
1665+
} else {
1666+
None
1667+
}
1668+
}
16531669
}
16541670

16551671
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]

0 commit comments

Comments
 (0)