diff --git a/compiler/rustc_ast_lowering/src/index.rs b/compiler/rustc_ast_lowering/src/index.rs index 793fe9cfd5e2e..9078b1f889cde 100644 --- a/compiler/rustc_ast_lowering/src/index.rs +++ b/compiler/rustc_ast_lowering/src/index.rs @@ -55,7 +55,7 @@ pub(super) fn index_hir<'hir>( OwnerNode::TraitItem(item) => collector.visit_trait_item(item), OwnerNode::ImplItem(item) => collector.visit_impl_item(item), OwnerNode::ForeignItem(item) => collector.visit_foreign_item(item), - OwnerNode::AssocOpaqueTy(..) => unreachable!(), + OwnerNode::Synthetic => unreachable!(), }; for (local_id, node) in collector.nodes.iter_enumerated() { diff --git a/compiler/rustc_const_eval/src/interpret/intern.rs b/compiler/rustc_const_eval/src/interpret/intern.rs index 17bb59aae8f17..2f04f053bac3e 100644 --- a/compiler/rustc_const_eval/src/interpret/intern.rs +++ b/compiler/rustc_const_eval/src/interpret/intern.rs @@ -111,6 +111,8 @@ fn intern_as_new_static<'tcx>( feed.generics_of(tcx.generics_of(static_id).clone()); feed.def_ident_span(tcx.def_ident_span(static_id)); feed.explicit_predicates_of(tcx.explicit_predicates_of(static_id)); + + feed.feed_hir() } /// How a constant value should be interned. diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 186b8716d9a51..67fe68b7563c4 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -2552,11 +2552,6 @@ pub struct OpaqueTy<'hir> { pub in_trait: bool, } -#[derive(Copy, Clone, Debug, HashStable_Generic)] -pub struct AssocOpaqueTy { - // Add some data if necessary -} - /// From whence the opaque type came. #[derive(Copy, Clone, PartialEq, Eq, Debug, HashStable_Generic)] pub enum OpaqueTyOrigin { @@ -3367,7 +3362,7 @@ pub enum OwnerNode<'hir> { TraitItem(&'hir TraitItem<'hir>), ImplItem(&'hir ImplItem<'hir>), Crate(&'hir Mod<'hir>), - AssocOpaqueTy(&'hir AssocOpaqueTy), + Synthetic, } impl<'hir> OwnerNode<'hir> { @@ -3377,7 +3372,7 @@ impl<'hir> OwnerNode<'hir> { | OwnerNode::ForeignItem(ForeignItem { ident, .. }) | OwnerNode::ImplItem(ImplItem { ident, .. }) | OwnerNode::TraitItem(TraitItem { ident, .. }) => Some(*ident), - OwnerNode::Crate(..) | OwnerNode::AssocOpaqueTy(..) => None, + OwnerNode::Crate(..) | OwnerNode::Synthetic => None, } } @@ -3390,7 +3385,7 @@ impl<'hir> OwnerNode<'hir> { | OwnerNode::ImplItem(ImplItem { span, .. }) | OwnerNode::TraitItem(TraitItem { span, .. }) => span, OwnerNode::Crate(Mod { spans: ModSpans { inner_span, .. }, .. }) => inner_span, - OwnerNode::AssocOpaqueTy(..) => unreachable!(), + OwnerNode::Synthetic => unreachable!(), } } @@ -3449,7 +3444,7 @@ impl<'hir> OwnerNode<'hir> { | OwnerNode::ImplItem(ImplItem { owner_id, .. }) | OwnerNode::ForeignItem(ForeignItem { owner_id, .. }) => *owner_id, OwnerNode::Crate(..) => crate::CRATE_HIR_ID.owner, - OwnerNode::AssocOpaqueTy(..) => unreachable!(), + OwnerNode::Synthetic => unreachable!(), } } @@ -3493,7 +3488,7 @@ impl<'hir> Into> for OwnerNode<'hir> { OwnerNode::ImplItem(n) => Node::ImplItem(n), OwnerNode::TraitItem(n) => Node::TraitItem(n), OwnerNode::Crate(n) => Node::Crate(n), - OwnerNode::AssocOpaqueTy(n) => Node::AssocOpaqueTy(n), + OwnerNode::Synthetic => Node::Synthetic, } } } @@ -3531,7 +3526,8 @@ pub enum Node<'hir> { WhereBoundPredicate(&'hir WhereBoundPredicate<'hir>), // FIXME: Merge into `Node::Infer`. ArrayLenInfer(&'hir InferArg), - AssocOpaqueTy(&'hir AssocOpaqueTy), + // Created by query feeding + Synthetic, // Span by reference to minimize `Node`'s size #[allow(rustc::pass_by_value)] Err(&'hir Span), @@ -3582,7 +3578,7 @@ impl<'hir> Node<'hir> { | Node::Infer(..) | Node::WhereBoundPredicate(..) | Node::ArrayLenInfer(..) - | Node::AssocOpaqueTy(..) + | Node::Synthetic | Node::Err(..) => None, } } @@ -3688,7 +3684,7 @@ impl<'hir> Node<'hir> { Node::TraitItem(i) => Some(OwnerNode::TraitItem(i)), Node::ImplItem(i) => Some(OwnerNode::ImplItem(i)), Node::Crate(i) => Some(OwnerNode::Crate(i)), - Node::AssocOpaqueTy(i) => Some(OwnerNode::AssocOpaqueTy(i)), + Node::Synthetic => Some(OwnerNode::Synthetic), _ => None, } } diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 41b03f0b66e4f..b5377e40bfdd9 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -196,7 +196,7 @@ fn check_well_formed(tcx: TyCtxt<'_>, def_id: hir::OwnerId) -> Result<(), ErrorG hir::OwnerNode::TraitItem(item) => check_trait_item(tcx, item), hir::OwnerNode::ImplItem(item) => check_impl_item(tcx, item), hir::OwnerNode::ForeignItem(item) => check_foreign_item(tcx, item), - hir::OwnerNode::AssocOpaqueTy(..) => unreachable!(), + hir::OwnerNode::Synthetic => unreachable!(), }; if let Some(generics) = node.generics() { diff --git a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs index d1da2fa0fdc26..86b075a84a703 100644 --- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs +++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs @@ -262,7 +262,7 @@ fn resolve_bound_vars(tcx: TyCtxt<'_>, local_def_id: hir::OwnerId) -> ResolveBou visitor.visit_impl_item(item) } hir::OwnerNode::Crate(_) => {} - hir::OwnerNode::AssocOpaqueTy(..) => unreachable!(), + hir::OwnerNode::Synthetic => unreachable!(), } let mut rl = ResolveBoundVars::default(); diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index e070db9423df1..34c245839478f 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -121,7 +121,7 @@ impl<'a> State<'a> { self.print_bounds(":", pred.bounds); } Node::ArrayLenInfer(_) => self.word("_"), - Node::AssocOpaqueTy(..) => unreachable!(), + Node::Synthetic => unreachable!(), Node::Err(_) => self.word("/*ERROR*/"), } } diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 5d2a95593cd25..331b3b97c3496 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -2553,7 +2553,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { hir::OwnerNode::ImplItem(i) => visitor.visit_impl_item(i), hir::OwnerNode::TraitItem(i) => visitor.visit_trait_item(i), hir::OwnerNode::Crate(_) => bug!("OwnerNode::Crate doesn't not have generics"), - hir::OwnerNode::AssocOpaqueTy(..) => unreachable!(), + hir::OwnerNode::Synthetic => unreachable!(), } let ast_generics = self.tcx.hir().get_generics(lifetime_scope).unwrap(); diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index 21af6a182a9df..26fc3f20b2cb5 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -191,7 +191,7 @@ fn shallow_lint_levels_on(tcx: TyCtxt<'_>, owner: hir::OwnerId) -> ShallowLintLe levels.add_id(hir::CRATE_HIR_ID); levels.visit_mod(mod_, mod_.spans.inner_span, hir::CRATE_HIR_ID) } - hir::OwnerNode::AssocOpaqueTy(..) => unreachable!(), + hir::OwnerNode::Synthetic => unreachable!(), }, } diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 5043bd855ccb9..718b6948ae1c8 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -954,7 +954,7 @@ impl<'hir> Map<'hir> { Node::Crate(item) => item.spans.inner_span, Node::WhereBoundPredicate(pred) => pred.span, Node::ArrayLenInfer(inf) => inf.span, - Node::AssocOpaqueTy(..) => unreachable!(), + Node::Synthetic => unreachable!(), Node::Err(span) => *span, } } @@ -1219,7 +1219,7 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String { Node::Crate(..) => String::from("(root_crate)"), Node::WhereBoundPredicate(_) => node_str("where bound predicate"), Node::ArrayLenInfer(_) => node_str("array len infer"), - Node::AssocOpaqueTy(..) => unreachable!(), + Node::Synthetic => unreachable!(), Node::Err(_) => node_str("error"), } } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 10a4da4042903..5de2e2fb1e7f2 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -596,6 +596,27 @@ impl<'tcx> TyCtxtFeed<'tcx, LocalDefId> { pub fn feed_owner_id(&self) -> TyCtxtFeed<'tcx, hir::OwnerId> { TyCtxtFeed { tcx: self.tcx, key: hir::OwnerId { def_id: self.key } } } + + // Fills in all the important parts needed by HIR queries + pub fn feed_hir(&self) { + self.local_def_id_to_hir_id(HirId::make_owner(self.def_id())); + + let node = hir::OwnerNode::Synthetic; + let bodies = Default::default(); + let attrs = hir::AttributeMap::EMPTY; + + let (opt_hash_including_bodies, _) = self.tcx.hash_owner_nodes(node, &bodies, &attrs.map); + let node = node.into(); + self.opt_hir_owner_nodes(Some(self.tcx.arena.alloc(hir::OwnerNodes { + opt_hash_including_bodies, + nodes: IndexVec::from_elem_n( + hir::ParentedNode { parent: hir::ItemLocalId::INVALID, node }, + 1, + ), + bodies, + }))); + self.feed_owner_id().hir_attrs(attrs); + } } /// The central data structure of the compiler. It stores references diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs index 6eb03bc0f5fbc..b7135de08ba84 100644 --- a/compiler/rustc_passes/src/reachable.rs +++ b/compiler/rustc_passes/src/reachable.rs @@ -247,7 +247,7 @@ impl<'tcx> ReachableContext<'tcx> { | Node::Field(_) | Node::Ty(_) | Node::Crate(_) - | Node::AssocOpaqueTy(..) => {} + | Node::Synthetic => {} _ => { bug!( "found unexpected node kind in worklist: {} ({:?})", diff --git a/compiler/rustc_ty_utils/src/assoc.rs b/compiler/rustc_ty_utils/src/assoc.rs index 50a8eb869b992..ba75424ec0c6d 100644 --- a/compiler/rustc_ty_utils/src/assoc.rs +++ b/compiler/rustc_ty_utils/src/assoc.rs @@ -1,11 +1,10 @@ use rustc_data_structures::fx::FxIndexSet; +use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId}; use rustc_hir::intravisit::{self, Visitor}; -use rustc_hir::{self as hir, HirId}; -use rustc_index::IndexVec; use rustc_middle::query::Providers; -use rustc_middle::ty::{self, ImplTraitInTraitData, TyCtxt, TyCtxtFeed}; +use rustc_middle::ty::{self, ImplTraitInTraitData, TyCtxt}; use rustc_span::symbol::kw; pub(crate) fn provide(providers: &mut Providers) { @@ -238,28 +237,6 @@ fn associated_types_for_impl_traits_in_associated_fn( } } -fn feed_hir(feed: &TyCtxtFeed<'_, LocalDefId>) { - feed.local_def_id_to_hir_id(HirId::make_owner(feed.def_id())); - - let node = hir::OwnerNode::AssocOpaqueTy(&hir::AssocOpaqueTy {}); - let bodies = Default::default(); - let attrs = hir::AttributeMap::EMPTY; - - let (opt_hash_including_bodies, _) = feed.tcx.hash_owner_nodes(node, &bodies, &attrs.map); - feed.opt_hir_owner_nodes(Some(feed.tcx.arena.alloc(hir::OwnerNodes { - opt_hash_including_bodies, - nodes: IndexVec::from_elem_n( - hir::ParentedNode { - parent: hir::ItemLocalId::INVALID, - node: hir::Node::AssocOpaqueTy(&hir::AssocOpaqueTy {}), - }, - 1, - ), - bodies, - }))); - feed.feed_owner_id().hir_attrs(attrs); -} - /// Given an `opaque_ty_def_id` corresponding to an `impl Trait` in an associated /// function from a trait, synthesize an associated type for that `impl Trait` /// that inherits properties that we infer from the method and the opaque type. @@ -281,7 +258,7 @@ fn associated_type_for_impl_trait_in_trait( let local_def_id = trait_assoc_ty.def_id(); let def_id = local_def_id.to_def_id(); - feed_hir(&trait_assoc_ty); + trait_assoc_ty.feed_hir(); // Copy span of the opaque. trait_assoc_ty.def_ident_span(Some(span)); @@ -335,7 +312,7 @@ fn associated_type_for_impl_trait_in_impl( let local_def_id = impl_assoc_ty.def_id(); let def_id = local_def_id.to_def_id(); - feed_hir(&impl_assoc_ty); + impl_assoc_ty.feed_hir(); // Copy span of the opaque. impl_assoc_ty.def_ident_span(Some(span));