Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit fe61575

Browse files
committed
Auto merge of rust-lang#120943 - petrochenkov:somehir3, r=oli-obk
Create some minimal HIR for associated opaque types `LocalDefId`s for opaque types in traits and impls are created after AST -> HIR lowering, so they don't have corresponding HIR and return their various properties through fed queries. In this PR I also feed some core HIR-related queries for these `LocalDefId`s (which happen to be HIR owners). As a result all `LocalDefId`s now have corresponding `HirId`s and HIR nodes, and "optional" methods like `opt_local_def_id_to_hir_id` and `opt_hir_node_by_def_id` can be removed. Follow up to rust-lang#120206.
2 parents c2fbe40 + b6312eb commit fe61575

File tree

16 files changed

+67
-29
lines changed

16 files changed

+67
-29
lines changed

compiler/rustc_ast_lowering/src/index.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub(super) fn index_hir<'hir>(
5555
OwnerNode::TraitItem(item) => collector.visit_trait_item(item),
5656
OwnerNode::ImplItem(item) => collector.visit_impl_item(item),
5757
OwnerNode::ForeignItem(item) => collector.visit_foreign_item(item),
58+
OwnerNode::AssocOpaqueTy(..) => unreachable!(),
5859
};
5960

6061
for (local_id, node) in collector.nodes.iter_enumerated() {

compiler/rustc_hir/src/hir.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2553,6 +2553,11 @@ pub struct OpaqueTy<'hir> {
25532553
pub in_trait: bool,
25542554
}
25552555

2556+
#[derive(Copy, Clone, Debug, HashStable_Generic)]
2557+
pub struct AssocOpaqueTy {
2558+
// Add some data if necessary
2559+
}
2560+
25562561
/// From whence the opaque type came.
25572562
#[derive(Copy, Clone, PartialEq, Eq, Debug, HashStable_Generic)]
25582563
pub enum OpaqueTyOrigin {
@@ -3363,6 +3368,7 @@ pub enum OwnerNode<'hir> {
33633368
TraitItem(&'hir TraitItem<'hir>),
33643369
ImplItem(&'hir ImplItem<'hir>),
33653370
Crate(&'hir Mod<'hir>),
3371+
AssocOpaqueTy(&'hir AssocOpaqueTy),
33663372
}
33673373

33683374
impl<'hir> OwnerNode<'hir> {
@@ -3372,7 +3378,7 @@ impl<'hir> OwnerNode<'hir> {
33723378
| OwnerNode::ForeignItem(ForeignItem { ident, .. })
33733379
| OwnerNode::ImplItem(ImplItem { ident, .. })
33743380
| OwnerNode::TraitItem(TraitItem { ident, .. }) => Some(*ident),
3375-
OwnerNode::Crate(..) => None,
3381+
OwnerNode::Crate(..) | OwnerNode::AssocOpaqueTy(..) => None,
33763382
}
33773383
}
33783384

@@ -3385,6 +3391,7 @@ impl<'hir> OwnerNode<'hir> {
33853391
| OwnerNode::ImplItem(ImplItem { span, .. })
33863392
| OwnerNode::TraitItem(TraitItem { span, .. }) => span,
33873393
OwnerNode::Crate(Mod { spans: ModSpans { inner_span, .. }, .. }) => inner_span,
3394+
OwnerNode::AssocOpaqueTy(..) => unreachable!(),
33883395
}
33893396
}
33903397

@@ -3443,6 +3450,7 @@ impl<'hir> OwnerNode<'hir> {
34433450
| OwnerNode::ImplItem(ImplItem { owner_id, .. })
34443451
| OwnerNode::ForeignItem(ForeignItem { owner_id, .. }) => *owner_id,
34453452
OwnerNode::Crate(..) => crate::CRATE_HIR_ID.owner,
3453+
OwnerNode::AssocOpaqueTy(..) => unreachable!(),
34463454
}
34473455
}
34483456

@@ -3486,6 +3494,7 @@ impl<'hir> Into<Node<'hir>> for OwnerNode<'hir> {
34863494
OwnerNode::ImplItem(n) => Node::ImplItem(n),
34873495
OwnerNode::TraitItem(n) => Node::TraitItem(n),
34883496
OwnerNode::Crate(n) => Node::Crate(n),
3497+
OwnerNode::AssocOpaqueTy(n) => Node::AssocOpaqueTy(n),
34893498
}
34903499
}
34913500
}
@@ -3523,6 +3532,7 @@ pub enum Node<'hir> {
35233532
WhereBoundPredicate(&'hir WhereBoundPredicate<'hir>),
35243533
// FIXME: Merge into `Node::Infer`.
35253534
ArrayLenInfer(&'hir InferArg),
3535+
AssocOpaqueTy(&'hir AssocOpaqueTy),
35263536
// Span by reference to minimize `Node`'s size
35273537
#[allow(rustc::pass_by_value)]
35283538
Err(&'hir Span),
@@ -3573,6 +3583,7 @@ impl<'hir> Node<'hir> {
35733583
| Node::Infer(..)
35743584
| Node::WhereBoundPredicate(..)
35753585
| Node::ArrayLenInfer(..)
3586+
| Node::AssocOpaqueTy(..)
35763587
| Node::Err(..) => None,
35773588
}
35783589
}
@@ -3678,6 +3689,7 @@ impl<'hir> Node<'hir> {
36783689
Node::TraitItem(i) => Some(OwnerNode::TraitItem(i)),
36793690
Node::ImplItem(i) => Some(OwnerNode::ImplItem(i)),
36803691
Node::Crate(i) => Some(OwnerNode::Crate(i)),
3692+
Node::AssocOpaqueTy(i) => Some(OwnerNode::AssocOpaqueTy(i)),
36813693
_ => None,
36823694
}
36833695
}

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ fn check_well_formed(tcx: TyCtxt<'_>, def_id: hir::OwnerId) -> Result<(), ErrorG
196196
hir::OwnerNode::TraitItem(item) => check_trait_item(tcx, item),
197197
hir::OwnerNode::ImplItem(item) => check_impl_item(tcx, item),
198198
hir::OwnerNode::ForeignItem(item) => check_foreign_item(tcx, item),
199+
hir::OwnerNode::AssocOpaqueTy(..) => unreachable!(),
199200
};
200201

201202
if let Some(generics) = node.generics() {

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ fn resolve_bound_vars(tcx: TyCtxt<'_>, local_def_id: hir::OwnerId) -> ResolveBou
262262
visitor.visit_impl_item(item)
263263
}
264264
hir::OwnerNode::Crate(_) => {}
265+
hir::OwnerNode::AssocOpaqueTy(..) => unreachable!(),
265266
}
266267

267268
let mut rl = ResolveBoundVars::default();

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ impl<'a> State<'a> {
121121
self.print_bounds(":", pred.bounds);
122122
}
123123
Node::ArrayLenInfer(_) => self.word("_"),
124+
Node::AssocOpaqueTy(..) => unreachable!(),
124125
Node::Err(_) => self.word("/*ERROR*/"),
125126
}
126127
}

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2174,7 +2174,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21742174
let mut call_finder = FindClosureArg { tcx: self.tcx, calls: vec![] };
21752175
let node = self
21762176
.tcx
2177-
.opt_local_def_id_to_hir_id(self.tcx.hir().get_parent_item(call_expr.hir_id))
2177+
.opt_local_def_id_to_hir_id(
2178+
self.tcx.hir().get_parent_item(call_expr.hir_id).def_id,
2179+
)
21782180
.map(|hir_id| self.tcx.hir_node(hir_id));
21792181
match node {
21802182
Some(hir::Node::Item(item)) => call_finder.visit_item(item),

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2554,6 +2554,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
25542554
hir::OwnerNode::ImplItem(i) => visitor.visit_impl_item(i),
25552555
hir::OwnerNode::TraitItem(i) => visitor.visit_trait_item(i),
25562556
hir::OwnerNode::Crate(_) => bug!("OwnerNode::Crate doesn't not have generics"),
2557+
hir::OwnerNode::AssocOpaqueTy(..) => unreachable!(),
25572558
}
25582559

25592560
let ast_generics = self.tcx.hir().get_generics(lifetime_scope).unwrap();

compiler/rustc_lint/src/late.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
356356
cached_typeck_results: Cell::new(None),
357357
param_env: ty::ParamEnv::empty(),
358358
effective_visibilities: tcx.effective_visibilities(()),
359-
last_node_with_lint_attrs: tcx.local_def_id_to_hir_id(module_def_id.into()),
359+
last_node_with_lint_attrs: tcx.local_def_id_to_hir_id(module_def_id),
360360
generics: None,
361361
only_module: true,
362362
};

compiler/rustc_lint/src/levels.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ fn shallow_lint_levels_on(tcx: TyCtxt<'_>, owner: hir::OwnerId) -> ShallowLintLe
191191
levels.add_id(hir::CRATE_HIR_ID);
192192
levels.visit_mod(mod_, mod_.spans.inner_span, hir::CRATE_HIR_ID)
193193
}
194+
hir::OwnerNode::AssocOpaqueTy(..) => unreachable!(),
194195
},
195196
}
196197

compiler/rustc_middle/src/arena.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ macro_rules! arena_types {
115115
[] features: rustc_feature::Features,
116116
[decode] specialization_graph: rustc_middle::traits::specialization_graph::Graph,
117117
[] crate_inherent_impls: rustc_middle::ty::CrateInherentImpls,
118+
[] hir_owner_nodes: rustc_hir::OwnerNodes<'tcx>,
118119
]);
119120
)
120121
}

0 commit comments

Comments
 (0)