diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 9232be8ea2b5b..9edc30ceb199e 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -788,7 +788,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { node_id, DefPathData::LifetimeNs(str_name), ExpnId::root(), - span, + span.with_parent(None), ); hir::GenericParam { @@ -1520,7 +1520,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { def_node_id, DefPathData::LifetimeNs(name.ident().name), ExpnId::root(), - span, + span.with_parent(None), ); let (name, kind) = match name { diff --git a/compiler/rustc_hir/src/definitions.rs b/compiler/rustc_hir/src/definitions.rs index ada012b6697f8..5f56f3a32adde 100644 --- a/compiler/rustc_hir/src/definitions.rs +++ b/compiler/rustc_hir/src/definitions.rs @@ -345,6 +345,8 @@ impl 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 @@ impl Definitions { 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); diff --git a/compiler/rustc_interface/src/callbacks.rs b/compiler/rustc_interface/src/callbacks.rs index 03c75655d6a33..95bd2993456ab 100644 --- a/compiler/rustc_interface/src/callbacks.rs +++ b/compiler/rustc_interface/src/callbacks.rs @@ -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); } }) }