Skip to content

Commit fb5ced0

Browse files
committed
Add sanity check.
We force the relative span's parent to be absolute. This avoids having to handle long dependency chains.
1 parent 940fa92 commit fb5ced0

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
788788
node_id,
789789
DefPathData::LifetimeNs(str_name),
790790
ExpnId::root(),
791-
span,
791+
span.with_parent(None),
792792
);
793793

794794
hir::GenericParam {
@@ -1520,7 +1520,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15201520
def_node_id,
15211521
DefPathData::LifetimeNs(name.ident().name),
15221522
ExpnId::root(),
1523-
span,
1523+
span.with_parent(None),
15241524
);
15251525

15261526
let (name, kind) = match name {

compiler/rustc_hir/src/definitions.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ impl Definitions {
345345
assert_eq!(root.local_def_index, CRATE_DEF_INDEX);
346346

347347
let mut def_id_to_span = IndexVec::new();
348+
// A relative span's parent must be an absolute span.
349+
debug_assert_eq!(crate_span.data_untracked().parent, None);
348350
let _root = def_id_to_span.push(crate_span);
349351
debug_assert_eq!(_root, root);
350352

@@ -394,6 +396,8 @@ impl Definitions {
394396
self.expansions_that_defined.insert(def_id, expn_id);
395397
}
396398

399+
// A relative span's parent must be an absolute span.
400+
debug_assert_eq!(span.data_untracked().parent, None);
397401
let _id = self.def_id_to_span.push(span);
398402
debug_assert_eq!(_id, def_id);
399403

compiler/rustc_interface/src/callbacks.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ fn span_debug(span: rustc_span::Span, f: &mut fmt::Formatter<'_>) -> fmt::Result
2828
fn track_span_parent(def_id: rustc_span::def_id::LocalDefId) {
2929
tls::with_opt(|tcx| {
3030
if let Some(tcx) = tcx {
31-
let _ = tcx.source_span(def_id);
31+
let _span = tcx.source_span(def_id);
32+
// Sanity check: relative span's parent must be an absolute span.
33+
debug_assert_eq!(_span.data_untracked().parent, None);
3234
}
3335
})
3436
}

0 commit comments

Comments
 (0)