Skip to content

Commit

Permalink
Add sanity check.
Browse files Browse the repository at this point in the history
We force the relative span's parent to be absolute. This avoids having to
handle long dependency chains.
  • Loading branch information
cjgillot committed Sep 10, 2021
1 parent 940fa92 commit fb5ced0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/lib.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_hir/src/definitions.rs
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_interface/src/callbacks.rs
Expand Up @@ -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);
}
})
}
Expand Down

0 comments on commit fb5ced0

Please sign in to comment.