Skip to content

Commit 703d95e

Browse files
committed
Auto merge of #105133 - oli-obk:promoted_def_ids, r=cjgillot
Ensure query backtraces work for `DefId`s created after ast lowering r? `@cjgillot`
2 parents 24f2704 + ab75d77 commit 703d95e

File tree

7 files changed

+31
-12
lines changed

7 files changed

+31
-12
lines changed

compiler/rustc_ast_lowering/src/asm.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
222222
// Wrap the expression in an AnonConst.
223223
let parent_def_id = self.current_hir_id_owner;
224224
let node_id = self.next_node_id();
225-
self.create_def(parent_def_id.def_id, node_id, DefPathData::AnonConst);
225+
self.create_def(
226+
parent_def_id.def_id,
227+
node_id,
228+
DefPathData::AnonConst,
229+
*op_sp,
230+
);
226231
let anon_const = AnonConst { id: node_id, value: P(expr) };
227232
hir::InlineAsmOperand::SymFn {
228233
anon_const: self.lower_anon_const(&anon_const),

compiler/rustc_ast_lowering/src/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
365365
let node_id = self.next_node_id();
366366

367367
// Add a definition for the in-band const def.
368-
self.create_def(parent_def_id.def_id, node_id, DefPathData::AnonConst);
368+
self.create_def(parent_def_id.def_id, node_id, DefPathData::AnonConst, f.span);
369369

370370
let anon_const = AnonConst { id: node_id, value: arg };
371371
generic_args.push(AngleBracketedArg::Arg(GenericArg::Const(anon_const)));

compiler/rustc_ast_lowering/src/lib.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
487487
parent: LocalDefId,
488488
node_id: ast::NodeId,
489489
data: DefPathData,
490+
span: Span,
490491
) -> LocalDefId {
491492
debug_assert_ne!(node_id, ast::DUMMY_NODE_ID);
492493
assert!(
@@ -497,7 +498,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
497498
self.tcx.hir().def_key(self.local_def_id(node_id)),
498499
);
499500

500-
let def_id = self.tcx.create_def(parent, data).def_id();
501+
let def_id = self.tcx.at(span).create_def(parent, data).def_id();
501502

502503
debug!("create_def: def_id_to_node_id[{:?}] <-> {:?}", def_id, node_id);
503504
self.resolver.node_id_to_def_id.insert(node_id, def_id);
@@ -823,6 +824,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
823824
self.current_hir_id_owner.def_id,
824825
param,
825826
DefPathData::LifetimeNs(kw::UnderscoreLifetime),
827+
ident.span,
826828
);
827829
debug!(?_def_id);
828830

@@ -1151,15 +1153,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11511153

11521154
let parent_def_id = self.current_hir_id_owner;
11531155
let node_id = self.next_node_id();
1156+
let span = self.lower_span(ty.span);
11541157

11551158
// Add a definition for the in-band const def.
11561159
let def_id = self.create_def(
11571160
parent_def_id.def_id,
11581161
node_id,
11591162
DefPathData::AnonConst,
1163+
span,
11601164
);
11611165

1162-
let span = self.lower_span(ty.span);
11631166
let path_expr = Expr {
11641167
id: ty.id,
11651168
kind: ExprKind::Path(qself.clone(), path.clone()),
@@ -1353,12 +1356,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13531356
itctx,
13541357
),
13551358
ImplTraitContext::Universal => {
1359+
let span = t.span;
13561360
self.create_def(
13571361
self.current_hir_id_owner.def_id,
13581362
*def_node_id,
13591363
DefPathData::ImplTrait,
1364+
span,
13601365
);
1361-
let span = t.span;
13621366
let ident = Ident::from_str_and_span(&pprust::ty_to_string(t), span);
13631367
let (param, bounds, path) =
13641368
self.lower_generic_and_bounds(*def_node_id, span, ident, bounds);
@@ -1455,6 +1459,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14551459
self.current_hir_id_owner.def_id,
14561460
opaque_ty_node_id,
14571461
DefPathData::ImplTrait,
1462+
opaque_ty_span,
14581463
);
14591464
debug!(?opaque_ty_def_id);
14601465

@@ -1608,6 +1613,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16081613
parent_def_id,
16091614
node_id,
16101615
DefPathData::LifetimeNs(lifetime.ident.name),
1616+
lifetime.ident.span,
16111617
);
16121618
remapping.insert(old_def_id, new_def_id);
16131619

@@ -1624,6 +1630,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16241630
parent_def_id,
16251631
node_id,
16261632
DefPathData::LifetimeNs(kw::UnderscoreLifetime),
1633+
lifetime.ident.span,
16271634
);
16281635
remapping.insert(old_def_id, new_def_id);
16291636

@@ -1806,7 +1813,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18061813
let fn_def_id = self.local_def_id(fn_node_id);
18071814

18081815
let opaque_ty_def_id =
1809-
self.create_def(fn_def_id, opaque_ty_node_id, DefPathData::ImplTrait);
1816+
self.create_def(fn_def_id, opaque_ty_node_id, DefPathData::ImplTrait, opaque_ty_span);
18101817

18111818
// When we create the opaque type for this async fn, it is going to have
18121819
// to capture all the lifetimes involved in the signature (including in the
@@ -1866,6 +1873,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18661873
opaque_ty_def_id,
18671874
inner_node_id,
18681875
DefPathData::LifetimeNs(ident.name),
1876+
ident.span,
18691877
);
18701878
new_remapping.insert(outer_def_id, inner_def_id);
18711879

compiler/rustc_middle/src/query/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,7 @@ rustc_queries! {
11091109
desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) }
11101110
cache_on_disk_if { def_id.is_local() }
11111111
separate_provide_extern
1112+
feedable
11121113
}
11131114

11141115
/// Gets the span for the identifier of the definition.

compiler/rustc_middle/src/ty/context.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,9 @@ impl<'tcx> TyCtxt<'tcx> {
15071507
self.def_path(def_id).to_string_no_crate_verbose()
15081508
)
15091509
}
1510+
}
15101511

1512+
impl<'tcx> TyCtxtAt<'tcx> {
15111513
/// Create a new definition within the incr. comp. engine.
15121514
pub fn create_def(
15131515
self,
@@ -1536,9 +1538,13 @@ impl<'tcx> TyCtxt<'tcx> {
15361538
// - this write will have happened before these queries are called.
15371539
let def_id = self.definitions.write().create_def(parent, data);
15381540

1539-
TyCtxtFeed { tcx: self, def_id }
1541+
let feed = TyCtxtFeed { tcx: self.tcx, def_id };
1542+
feed.def_span(self.span);
1543+
feed
15401544
}
1545+
}
15411546

1547+
impl<'tcx> TyCtxt<'tcx> {
15421548
pub fn iter_local_def_id(self) -> impl Iterator<Item = LocalDefId> + 'tcx {
15431549
// Create a dependency to the red node to be sure we re-execute this when the amount of
15441550
// definitions change.

compiler/rustc_middle/src/ty/query.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,10 @@ macro_rules! define_feedable {
344344

345345
match cached {
346346
Ok(old) => {
347-
assert_eq!(
348-
value, old,
349-
"Trying to feed an already recorded value for query {} key={key:?}",
347+
bug!(
348+
"Trying to feed an already recorded value for query {} key={key:?}:\nold value: {old:?}\nnew value: {value:?}",
350349
stringify!($name),
351350
);
352-
return old;
353351
}
354352
Err(()) => (),
355353
}

compiler/rustc_query_system/src/dep_graph/graph.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,8 @@ impl<K: DepKind> DepGraph<K> {
532532
let mut edges = SmallVec::new();
533533
K::read_deps(|task_deps| match task_deps {
534534
TaskDepsRef::Allow(deps) => edges.extend(deps.lock().reads.iter().copied()),
535-
TaskDepsRef::Ignore | TaskDepsRef::Forbid => {
535+
TaskDepsRef::Ignore => {} // During HIR lowering, we have no dependencies.
536+
TaskDepsRef::Forbid => {
536537
panic!("Cannot summarize when dependencies are not recorded.")
537538
}
538539
});

0 commit comments

Comments
 (0)