1
Fork 0

Add SourceScope::inlined_instance

This commit is contained in:
Tomasz Miąsko 2022-07-03 00:00:00 +00:00
parent eba361ae36
commit 7e7d007467
2 changed files with 18 additions and 5 deletions

View file

@ -1650,6 +1650,22 @@ impl SourceScope {
ClearCrossCrate::Clear => None,
}
}
/// The instance this source scope was inlined from, if any.
#[inline]
pub fn inlined_instance<'tcx>(
self,
source_scopes: &IndexVec<SourceScope, SourceScopeData<'tcx>>,
) -> Option<ty::Instance<'tcx>> {
let scope_data = &source_scopes[self];
if let Some((inlined_instance, _)) = scope_data.inlined {
Some(inlined_instance)
} else if let Some(inlined_scope) = scope_data.inlined_parent_scope {
Some(source_scopes[inlined_scope].inlined.unwrap().0)
} else {
None
}
}
}
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]