Skip to content

Commit abc1178

Browse files
committed
[WIP] Create some minimal HIR for associated opaque types
1 parent 980cf08 commit abc1178

File tree

16 files changed

+71
-24
lines changed

16 files changed

+71
-24
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
@@ -2548,6 +2548,11 @@ pub struct OpaqueTy<'hir> {
25482548
pub in_trait: bool,
25492549
}
25502550

2551+
#[derive(Copy, Clone, Debug, HashStable_Generic)]
2552+
pub struct AssocOpaqueTy {
2553+
// Maybe add some data if necessary
2554+
}
2555+
25512556
/// From whence the opaque type came.
25522557
#[derive(Copy, Clone, PartialEq, Eq, Debug, HashStable_Generic)]
25532558
pub enum OpaqueTyOrigin {
@@ -3331,6 +3336,7 @@ pub enum OwnerNode<'hir> {
33313336
TraitItem(&'hir TraitItem<'hir>),
33323337
ImplItem(&'hir ImplItem<'hir>),
33333338
Crate(&'hir Mod<'hir>),
3339+
AssocOpaqueTy(&'hir AssocOpaqueTy),
33343340
}
33353341

33363342
impl<'hir> OwnerNode<'hir> {
@@ -3340,7 +3346,7 @@ impl<'hir> OwnerNode<'hir> {
33403346
| OwnerNode::ForeignItem(ForeignItem { ident, .. })
33413347
| OwnerNode::ImplItem(ImplItem { ident, .. })
33423348
| OwnerNode::TraitItem(TraitItem { ident, .. }) => Some(*ident),
3343-
OwnerNode::Crate(..) => None,
3349+
OwnerNode::Crate(..) | OwnerNode::AssocOpaqueTy(..) => None,
33443350
}
33453351
}
33463352

@@ -3353,6 +3359,7 @@ impl<'hir> OwnerNode<'hir> {
33533359
| OwnerNode::ImplItem(ImplItem { span, .. })
33543360
| OwnerNode::TraitItem(TraitItem { span, .. }) => span,
33553361
OwnerNode::Crate(Mod { spans: ModSpans { inner_span, .. }, .. }) => inner_span,
3362+
OwnerNode::AssocOpaqueTy(..) => unreachable!(),
33563363
}
33573364
}
33583365

@@ -3411,6 +3418,7 @@ impl<'hir> OwnerNode<'hir> {
34113418
| OwnerNode::ImplItem(ImplItem { owner_id, .. })
34123419
| OwnerNode::ForeignItem(ForeignItem { owner_id, .. }) => *owner_id,
34133420
OwnerNode::Crate(..) => crate::CRATE_HIR_ID.owner,
3421+
OwnerNode::AssocOpaqueTy(..) => unreachable!(),
34143422
}
34153423
}
34163424

@@ -3454,6 +3462,7 @@ impl<'hir> Into<Node<'hir>> for OwnerNode<'hir> {
34543462
OwnerNode::ImplItem(n) => Node::ImplItem(n),
34553463
OwnerNode::TraitItem(n) => Node::TraitItem(n),
34563464
OwnerNode::Crate(n) => Node::Crate(n),
3465+
OwnerNode::AssocOpaqueTy(n) => Node::AssocOpaqueTy(n),
34573466
}
34583467
}
34593468
}
@@ -3491,6 +3500,7 @@ pub enum Node<'hir> {
34913500
WhereBoundPredicate(&'hir WhereBoundPredicate<'hir>),
34923501
// FIXME: Merge into `Node::Infer`.
34933502
ArrayLenInfer(&'hir InferArg),
3503+
AssocOpaqueTy(&'hir AssocOpaqueTy),
34943504
// Span by reference to minimize `Node`'s size
34953505
#[allow(rustc::pass_by_value)]
34963506
Err(&'hir Span),
@@ -3541,6 +3551,7 @@ impl<'hir> Node<'hir> {
35413551
| Node::Infer(..)
35423552
| Node::WhereBoundPredicate(..)
35433553
| Node::ArrayLenInfer(..)
3554+
| Node::AssocOpaqueTy(..)
35443555
| Node::Err(..) => None,
35453556
}
35463557
}
@@ -3646,6 +3657,7 @@ impl<'hir> Node<'hir> {
36463657
Node::TraitItem(i) => Some(OwnerNode::TraitItem(i)),
36473658
Node::ImplItem(i) => Some(OwnerNode::ImplItem(i)),
36483659
Node::Crate(i) => Some(OwnerNode::Crate(i)),
3660+
Node::AssocOpaqueTy(i) => Some(OwnerNode::AssocOpaqueTy(i)),
36493661
_ => None,
36503662
}
36513663
}

compiler/rustc_hir_analysis/src/check/wfcheck.rs

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

199200
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
@@ -270,6 +270,7 @@ fn resolve_bound_vars(tcx: TyCtxt<'_>, local_def_id: hir::OwnerId) -> ResolveBou
270270
visitor.visit_impl_item(item)
271271
}
272272
hir::OwnerNode::Crate(_) => {}
273+
hir::OwnerNode::AssocOpaqueTy(..) => unreachable!(),
273274
}
274275

275276
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
@@ -2059,7 +2059,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20592059
let mut call_finder = FindClosureArg { tcx: self.tcx, calls: vec![] };
20602060
let node = self
20612061
.tcx
2062-
.opt_local_def_id_to_hir_id(self.tcx.hir().get_parent_item(call_expr.hir_id))
2062+
.opt_local_def_id_to_hir_id(
2063+
self.tcx.hir().get_parent_item(call_expr.hir_id).def_id,
2064+
)
20632065
.map(|hir_id| self.tcx.hir_node(hir_id));
20642066
match node {
20652067
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
@@ -2564,6 +2564,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
25642564
hir::OwnerNode::ImplItem(i) => visitor.visit_impl_item(i),
25652565
hir::OwnerNode::TraitItem(i) => visitor.visit_trait_item(i),
25662566
hir::OwnerNode::Crate(_) => bug!("OwnerNode::Crate doesn't not have generics"),
2567+
hir::OwnerNode::AssocOpaqueTy(..) => unreachable!(),
25672568
}
25682569

25692570
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
@@ -190,6 +190,7 @@ fn shallow_lint_levels_on(tcx: TyCtxt<'_>, owner: hir::OwnerId) -> ShallowLintLe
190190
levels.add_id(hir::CRATE_HIR_ID);
191191
levels.visit_mod(mod_, mod_.spans.inner_span, hir::CRATE_HIR_ID)
192192
}
193+
hir::OwnerNode::AssocOpaqueTy(..) => unreachable!(),
193194
},
194195
}
195196

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)