mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
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).
This commit is contained in:
commit
7235b1a44e
@ -2159,7 +2159,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
let path = hir::ExprKind::Path(hir::QPath::TypeRelative(
|
||||
self.arena.alloc(self.ty(span, hir::TyKind::Path(qpath))),
|
||||
self.arena.alloc(hir::PathSegment::new(
|
||||
Ident::new(name, span),
|
||||
Ident::new(name, self.lower_span(span)),
|
||||
self.next_id(),
|
||||
Res::Err,
|
||||
)),
|
||||
|
@ -78,24 +78,31 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
|
||||
|
||||
// Make sure that the DepNode of some node coincides with the HirId
|
||||
// owner of that node.
|
||||
if cfg!(debug_assertions) && hir_id.owner != self.owner {
|
||||
span_bug!(
|
||||
span,
|
||||
"inconsistent HirId at `{:?}` for `{:?}`: \
|
||||
if cfg!(debug_assertions) {
|
||||
if hir_id.owner != self.owner {
|
||||
span_bug!(
|
||||
span,
|
||||
"inconsistent HirId at `{:?}` for `{node:?}`: \
|
||||
current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?})",
|
||||
self.tcx.sess.source_map().span_to_diagnostic_string(span),
|
||||
node,
|
||||
self.tcx
|
||||
.definitions_untracked()
|
||||
.def_path(self.owner.def_id)
|
||||
.to_string_no_crate_verbose(),
|
||||
self.owner,
|
||||
self.tcx
|
||||
.definitions_untracked()
|
||||
.def_path(hir_id.owner.def_id)
|
||||
.to_string_no_crate_verbose(),
|
||||
hir_id.owner,
|
||||
)
|
||||
self.tcx.sess.source_map().span_to_diagnostic_string(span),
|
||||
self.tcx
|
||||
.definitions_untracked()
|
||||
.def_path(self.owner.def_id)
|
||||
.to_string_no_crate_verbose(),
|
||||
self.owner,
|
||||
self.tcx
|
||||
.definitions_untracked()
|
||||
.def_path(hir_id.owner.def_id)
|
||||
.to_string_no_crate_verbose(),
|
||||
hir_id.owner,
|
||||
)
|
||||
}
|
||||
if self.tcx.sess.opts.incremental.is_some()
|
||||
&& span.parent().is_none()
|
||||
&& !span.is_dummy()
|
||||
{
|
||||
span_bug!(span, "span without a parent: {:#?}, {node:?}", span.data())
|
||||
}
|
||||
}
|
||||
|
||||
self.nodes[hir_id.local_id] = ParentedNode { parent: self.parent_node, node };
|
||||
|
@ -1092,6 +1092,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
// this as a special case.
|
||||
return self.lower_fn_body(decl, |this| {
|
||||
if attrs.iter().any(|a| a.name_or_empty() == sym::rustc_intrinsic) {
|
||||
let span = this.lower_span(span);
|
||||
let empty_block = hir::Block {
|
||||
hir_id: this.next_id(),
|
||||
stmts: &[],
|
||||
|
@ -375,24 +375,24 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
expr: &Expr,
|
||||
allow_paths: bool,
|
||||
) -> &'hir hir::PatExpr<'hir> {
|
||||
let span = self.lower_span(expr.span);
|
||||
let err = |guar| hir::PatExprKind::Lit {
|
||||
lit: self.arena.alloc(respan(self.lower_span(expr.span), LitKind::Err(guar))),
|
||||
lit: self.arena.alloc(respan(span, LitKind::Err(guar))),
|
||||
negated: false,
|
||||
};
|
||||
let kind = match &expr.kind {
|
||||
ExprKind::Lit(lit) => {
|
||||
hir::PatExprKind::Lit { lit: self.lower_lit(lit, expr.span), negated: false }
|
||||
hir::PatExprKind::Lit { lit: self.lower_lit(lit, span), negated: false }
|
||||
}
|
||||
ExprKind::ConstBlock(c) => hir::PatExprKind::ConstBlock(self.lower_const_block(c)),
|
||||
ExprKind::IncludedBytes(bytes) => hir::PatExprKind::Lit {
|
||||
lit: self.arena.alloc(respan(
|
||||
self.lower_span(expr.span),
|
||||
LitKind::ByteStr(Arc::clone(bytes), StrStyle::Cooked),
|
||||
)),
|
||||
lit: self
|
||||
.arena
|
||||
.alloc(respan(span, LitKind::ByteStr(Arc::clone(bytes), StrStyle::Cooked))),
|
||||
negated: false,
|
||||
},
|
||||
ExprKind::Err(guar) => err(*guar),
|
||||
ExprKind::Dummy => span_bug!(expr.span, "lowered ExprKind::Dummy"),
|
||||
ExprKind::Dummy => span_bug!(span, "lowered ExprKind::Dummy"),
|
||||
ExprKind::Path(qself, path) if allow_paths => hir::PatExprKind::Path(self.lower_qpath(
|
||||
expr.id,
|
||||
qself,
|
||||
@ -403,21 +403,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
None,
|
||||
)),
|
||||
ExprKind::Unary(UnOp::Neg, inner) if let ExprKind::Lit(lit) = &inner.kind => {
|
||||
hir::PatExprKind::Lit { lit: self.lower_lit(lit, expr.span), negated: true }
|
||||
hir::PatExprKind::Lit { lit: self.lower_lit(lit, span), negated: true }
|
||||
}
|
||||
_ => {
|
||||
let pattern_from_macro = expr.is_approximately_pattern();
|
||||
let guar = self.dcx().emit_err(ArbitraryExpressionInPattern {
|
||||
span: expr.span,
|
||||
span,
|
||||
pattern_from_macro_note: pattern_from_macro,
|
||||
});
|
||||
err(guar)
|
||||
}
|
||||
};
|
||||
self.arena.alloc(hir::PatExpr {
|
||||
hir_id: self.lower_node_id(expr.id),
|
||||
span: expr.span,
|
||||
kind,
|
||||
})
|
||||
self.arena.alloc(hir::PatExpr { hir_id: self.lower_node_id(expr.id), span, kind })
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user