Add sanity check.

We force the relative span's parent to be absolute. This avoids having to
handle long dependency chains.
This commit is contained in:
Camille GILLOT 2021-04-27 19:58:46 +02:00
parent 940fa9251e
commit fb5ced0fbd
3 changed files with 9 additions and 3 deletions

View File

@ -788,7 +788,7 @@ fn lifetime_to_generic_param(
node_id,
DefPathData::LifetimeNs(str_name),
ExpnId::root(),
span,
span.with_parent(None),
);
hir::GenericParam {
@ -1520,7 +1520,7 @@ fn lower_opaque_impl_trait(
def_node_id,
DefPathData::LifetimeNs(name.ident().name),
ExpnId::root(),
span,
span.with_parent(None),
);
let (name, kind) = match name {

View File

@ -345,6 +345,8 @@ pub fn new(stable_crate_id: StableCrateId, crate_span: Span) -> Definitions {
assert_eq!(root.local_def_index, CRATE_DEF_INDEX);
let mut def_id_to_span = IndexVec::new();
// A relative span's parent must be an absolute span.
debug_assert_eq!(crate_span.data_untracked().parent, None);
let _root = def_id_to_span.push(crate_span);
debug_assert_eq!(_root, root);
@ -394,6 +396,8 @@ pub fn create_def(
self.expansions_that_defined.insert(def_id, expn_id);
}
// A relative span's parent must be an absolute span.
debug_assert_eq!(span.data_untracked().parent, None);
let _id = self.def_id_to_span.push(span);
debug_assert_eq!(_id, def_id);

View File

@ -28,7 +28,9 @@ fn span_debug(span: rustc_span::Span, f: &mut fmt::Formatter<'_>) -> fmt::Result
fn track_span_parent(def_id: rustc_span::def_id::LocalDefId) {
tls::with_opt(|tcx| {
if let Some(tcx) = tcx {
let _ = tcx.source_span(def_id);
let _span = tcx.source_span(def_id);
// Sanity check: relative span's parent must be an absolute span.
debug_assert_eq!(_span.data_untracked().parent, None);
}
})
}