Skip to content

Commit 3a09680

Browse files
committed
Ensure nested statics have a HIR node to prevent various queries from ICEing
1 parent bdb682e commit 3a09680

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

compiler/rustc_const_eval/src/interpret/intern.rs

+2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ fn intern_as_new_static<'tcx>(
111111
feed.generics_of(tcx.generics_of(static_id).clone());
112112
feed.def_ident_span(tcx.def_ident_span(static_id));
113113
feed.explicit_predicates_of(tcx.explicit_predicates_of(static_id));
114+
115+
feed.feed_hir()
114116
}
115117

116118
/// How a constant value should be interned.

compiler/rustc_middle/src/ty/context.rs

+21
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,27 @@ impl<'tcx> TyCtxtFeed<'tcx, LocalDefId> {
596596
pub fn feed_owner_id(&self) -> TyCtxtFeed<'tcx, hir::OwnerId> {
597597
TyCtxtFeed { tcx: self.tcx, key: hir::OwnerId { def_id: self.key } }
598598
}
599+
600+
// Fills in all the important parts needed by HIR queries
601+
pub fn feed_hir(&self) {
602+
self.local_def_id_to_hir_id(HirId::make_owner(self.def_id()));
603+
604+
let node = hir::OwnerNode::Synthetic;
605+
let bodies = Default::default();
606+
let attrs = hir::AttributeMap::EMPTY;
607+
608+
let (opt_hash_including_bodies, _) = self.tcx.hash_owner_nodes(node, &bodies, &attrs.map);
609+
let node = node.into();
610+
self.opt_hir_owner_nodes(Some(self.tcx.arena.alloc(hir::OwnerNodes {
611+
opt_hash_including_bodies,
612+
nodes: IndexVec::from_elem_n(
613+
hir::ParentedNode { parent: hir::ItemLocalId::INVALID, node },
614+
1,
615+
),
616+
bodies,
617+
})));
618+
self.feed_owner_id().hir_attrs(attrs);
619+
}
599620
}
600621

601622
/// The central data structure of the compiler. It stores references

compiler/rustc_ty_utils/src/assoc.rs

+4-25
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use rustc_data_structures::fx::FxIndexSet;
2+
use rustc_hir as hir;
23
use rustc_hir::def::DefKind;
34
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId};
45
use rustc_hir::intravisit::{self, Visitor};
5-
use rustc_hir::{self as hir, HirId};
6-
use rustc_index::IndexVec;
76
use rustc_middle::query::Providers;
8-
use rustc_middle::ty::{self, ImplTraitInTraitData, TyCtxt, TyCtxtFeed};
7+
use rustc_middle::ty::{self, ImplTraitInTraitData, TyCtxt};
98
use rustc_span::symbol::kw;
109

1110
pub(crate) fn provide(providers: &mut Providers) {
@@ -238,26 +237,6 @@ fn associated_types_for_impl_traits_in_associated_fn(
238237
}
239238
}
240239

241-
fn feed_hir(feed: &TyCtxtFeed<'_, LocalDefId>) {
242-
feed.local_def_id_to_hir_id(HirId::make_owner(feed.def_id()));
243-
244-
let node = hir::OwnerNode::Synthetic;
245-
let bodies = Default::default();
246-
let attrs = hir::AttributeMap::EMPTY;
247-
248-
let (opt_hash_including_bodies, _) = feed.tcx.hash_owner_nodes(node, &bodies, &attrs.map);
249-
let node = node.into();
250-
feed.opt_hir_owner_nodes(Some(feed.tcx.arena.alloc(hir::OwnerNodes {
251-
opt_hash_including_bodies,
252-
nodes: IndexVec::from_elem_n(
253-
hir::ParentedNode { parent: hir::ItemLocalId::INVALID, node },
254-
1,
255-
),
256-
bodies,
257-
})));
258-
feed.feed_owner_id().hir_attrs(attrs);
259-
}
260-
261240
/// Given an `opaque_ty_def_id` corresponding to an `impl Trait` in an associated
262241
/// function from a trait, synthesize an associated type for that `impl Trait`
263242
/// that inherits properties that we infer from the method and the opaque type.
@@ -279,7 +258,7 @@ fn associated_type_for_impl_trait_in_trait(
279258
let local_def_id = trait_assoc_ty.def_id();
280259
let def_id = local_def_id.to_def_id();
281260

282-
feed_hir(&trait_assoc_ty);
261+
trait_assoc_ty.feed_hir();
283262

284263
// Copy span of the opaque.
285264
trait_assoc_ty.def_ident_span(Some(span));
@@ -333,7 +312,7 @@ fn associated_type_for_impl_trait_in_impl(
333312
let local_def_id = impl_assoc_ty.def_id();
334313
let def_id = local_def_id.to_def_id();
335314

336-
feed_hir(&impl_assoc_ty);
315+
impl_assoc_ty.feed_hir();
337316

338317
// Copy span of the opaque.
339318
impl_assoc_ty.def_ident_span(Some(span));

0 commit comments

Comments
 (0)