Skip to content

Commit 7235b1a

Browse files
authored
Rollup merge of #135874 - oli-obk:push-vrvyyrtyxkxm, r=compiler-errors
Enforce that all spans are lowered in ast lowering This should ensure that incremental is used as extensively as possible. It's only a debug assertion, and only enabled when incremental is enabled (as we only lower spans to relative spans then).
2 parents 318466a + 20ae3c0 commit 7235b1a

File tree

4 files changed

+36
-32
lines changed

4 files changed

+36
-32
lines changed

Diff for: compiler/rustc_ast_lowering/src/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2159,7 +2159,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
21592159
let path = hir::ExprKind::Path(hir::QPath::TypeRelative(
21602160
self.arena.alloc(self.ty(span, hir::TyKind::Path(qpath))),
21612161
self.arena.alloc(hir::PathSegment::new(
2162-
Ident::new(name, span),
2162+
Ident::new(name, self.lower_span(span)),
21632163
self.next_id(),
21642164
Res::Err,
21652165
)),

Diff for: compiler/rustc_ast_lowering/src/index.rs

+24-17
Original file line numberDiff line numberDiff line change
@@ -78,24 +78,31 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
7878

7979
// Make sure that the DepNode of some node coincides with the HirId
8080
// owner of that node.
81-
if cfg!(debug_assertions) && hir_id.owner != self.owner {
82-
span_bug!(
83-
span,
84-
"inconsistent HirId at `{:?}` for `{:?}`: \
81+
if cfg!(debug_assertions) {
82+
if hir_id.owner != self.owner {
83+
span_bug!(
84+
span,
85+
"inconsistent HirId at `{:?}` for `{node:?}`: \
8586
current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?})",
86-
self.tcx.sess.source_map().span_to_diagnostic_string(span),
87-
node,
88-
self.tcx
89-
.definitions_untracked()
90-
.def_path(self.owner.def_id)
91-
.to_string_no_crate_verbose(),
92-
self.owner,
93-
self.tcx
94-
.definitions_untracked()
95-
.def_path(hir_id.owner.def_id)
96-
.to_string_no_crate_verbose(),
97-
hir_id.owner,
98-
)
87+
self.tcx.sess.source_map().span_to_diagnostic_string(span),
88+
self.tcx
89+
.definitions_untracked()
90+
.def_path(self.owner.def_id)
91+
.to_string_no_crate_verbose(),
92+
self.owner,
93+
self.tcx
94+
.definitions_untracked()
95+
.def_path(hir_id.owner.def_id)
96+
.to_string_no_crate_verbose(),
97+
hir_id.owner,
98+
)
99+
}
100+
if self.tcx.sess.opts.incremental.is_some()
101+
&& span.parent().is_none()
102+
&& !span.is_dummy()
103+
{
104+
span_bug!(span, "span without a parent: {:#?}, {node:?}", span.data())
105+
}
99106
}
100107

101108
self.nodes[hir_id.local_id] = ParentedNode { parent: self.parent_node, node };

Diff for: compiler/rustc_ast_lowering/src/item.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10921092
// this as a special case.
10931093
return self.lower_fn_body(decl, |this| {
10941094
if attrs.iter().any(|a| a.name_or_empty() == sym::rustc_intrinsic) {
1095+
let span = this.lower_span(span);
10951096
let empty_block = hir::Block {
10961097
hir_id: this.next_id(),
10971098
stmts: &[],

Diff for: compiler/rustc_ast_lowering/src/pat.rs

+10-14
Original file line numberDiff line numberDiff line change
@@ -375,24 +375,24 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
375375
expr: &Expr,
376376
allow_paths: bool,
377377
) -> &'hir hir::PatExpr<'hir> {
378+
let span = self.lower_span(expr.span);
378379
let err = |guar| hir::PatExprKind::Lit {
379-
lit: self.arena.alloc(respan(self.lower_span(expr.span), LitKind::Err(guar))),
380+
lit: self.arena.alloc(respan(span, LitKind::Err(guar))),
380381
negated: false,
381382
};
382383
let kind = match &expr.kind {
383384
ExprKind::Lit(lit) => {
384-
hir::PatExprKind::Lit { lit: self.lower_lit(lit, expr.span), negated: false }
385+
hir::PatExprKind::Lit { lit: self.lower_lit(lit, span), negated: false }
385386
}
386387
ExprKind::ConstBlock(c) => hir::PatExprKind::ConstBlock(self.lower_const_block(c)),
387388
ExprKind::IncludedBytes(bytes) => hir::PatExprKind::Lit {
388-
lit: self.arena.alloc(respan(
389-
self.lower_span(expr.span),
390-
LitKind::ByteStr(Arc::clone(bytes), StrStyle::Cooked),
391-
)),
389+
lit: self
390+
.arena
391+
.alloc(respan(span, LitKind::ByteStr(Arc::clone(bytes), StrStyle::Cooked))),
392392
negated: false,
393393
},
394394
ExprKind::Err(guar) => err(*guar),
395-
ExprKind::Dummy => span_bug!(expr.span, "lowered ExprKind::Dummy"),
395+
ExprKind::Dummy => span_bug!(span, "lowered ExprKind::Dummy"),
396396
ExprKind::Path(qself, path) if allow_paths => hir::PatExprKind::Path(self.lower_qpath(
397397
expr.id,
398398
qself,
@@ -403,21 +403,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
403403
None,
404404
)),
405405
ExprKind::Unary(UnOp::Neg, inner) if let ExprKind::Lit(lit) = &inner.kind => {
406-
hir::PatExprKind::Lit { lit: self.lower_lit(lit, expr.span), negated: true }
406+
hir::PatExprKind::Lit { lit: self.lower_lit(lit, span), negated: true }
407407
}
408408
_ => {
409409
let pattern_from_macro = expr.is_approximately_pattern();
410410
let guar = self.dcx().emit_err(ArbitraryExpressionInPattern {
411-
span: expr.span,
411+
span,
412412
pattern_from_macro_note: pattern_from_macro,
413413
});
414414
err(guar)
415415
}
416416
};
417-
self.arena.alloc(hir::PatExpr {
418-
hir_id: self.lower_node_id(expr.id),
419-
span: expr.span,
420-
kind,
421-
})
417+
self.arena.alloc(hir::PatExpr { hir_id: self.lower_node_id(expr.id), span, kind })
422418
}
423419
}

0 commit comments

Comments
 (0)