Skip to content

Commit 30917da

Browse files
committed
wip
1 parent 5830a49 commit 30917da

File tree

5 files changed

+32
-43
lines changed

5 files changed

+32
-43
lines changed

compiler/rustc_ast_lowering/src/index.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,6 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
146146
self.visit_body(body);
147147
}
148148

149-
fn visit_nested_opaque_ty(&mut self, opaq: &'hir OpaqueTy<'hir>) -> Self::Result {
150-
self.visit_opaque_ty(opaq)
151-
}
152-
153149
fn visit_param(&mut self, param: &'hir Param<'hir>) {
154150
let node = Node::Param(param);
155151
self.insert(param.pat.span, param.hir_id, node);

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,16 +1619,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16191619
opaque_ty_span: Span,
16201620
lower_item_bounds: impl FnOnce(&mut Self) -> &'hir [hir::GenericBound<'hir>],
16211621
) -> hir::TyKind<'hir> {
1622-
let opaque_ty_hir_id = self.next_id();
16231622
let opaque_ty_def_id = self.create_def(
1624-
self.current_hir_id_owner.def_id, // FIXME: should this use self.current_def_id_parent?
1623+
self.current_def_id_parent,
16251624
opaque_ty_node_id,
16261625
kw::Empty,
16271626
DefKind::OpaqueTy,
16281627
opaque_ty_span,
16291628
);
1630-
debug!(?opaque_ty_def_id);
1631-
self.children.push((opaque_ty_def_id, hir::MaybeOwner::NonOwner(opaque_ty_hir_id)));
1629+
let opaque_ty_hir_id = self.lower_node_id(opaque_ty_node_id);
1630+
debug!(?opaque_ty_def_id, ?opaque_ty_hir_id);
16321631

16331632
// Map from captured (old) lifetime to synthetic (new) lifetime.
16341633
// Used to resolve lifetimes in the bounds of the opaque.

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3959,7 +3959,7 @@ impl<'hir> Node<'hir> {
39593959
| Node::TraitItem(TraitItem { generics, .. })
39603960
| Node::ImplItem(ImplItem { generics, .. }) => Some(generics),
39613961
Node::Item(item) => item.kind.generics(),
3962-
Node::OpaqueTy(opaq) => Some(opaq.generics),
3962+
Node::OpaqueTy(opaque) => Some(opaque.generics),
39633963
_ => None,
39643964
}
39653965
}

compiler/rustc_hir/src/intravisit.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -294,14 +294,6 @@ pub trait Visitor<'v>: Sized {
294294
Self::Result::output()
295295
}
296296

297-
#[track_caller]
298-
fn visit_nested_opaque_ty(&mut self, opaq: &'v OpaqueTy<'v>) -> Self::Result {
299-
if Self::NestedFilter::INTRA {
300-
try_visit!(self.visit_opaque_ty(opaq));
301-
}
302-
Self::Result::output()
303-
}
304-
305297
fn visit_param(&mut self, param: &'v Param<'v>) -> Self::Result {
306298
walk_param(self, param)
307299
}
@@ -435,8 +427,8 @@ pub trait Visitor<'v>: Sized {
435427
fn visit_poly_trait_ref(&mut self, t: &'v PolyTraitRef<'v>) -> Self::Result {
436428
walk_poly_trait_ref(self, t)
437429
}
438-
fn visit_opaque_ty(&mut self, opaq: &'v OpaqueTy<'v>) -> Self::Result {
439-
walk_opaque_ty(self, opaq)
430+
fn visit_opaque_ty(&mut self, opaque: &'v OpaqueTy<'v>) -> Self::Result {
431+
walk_opaque_ty(self, opaque)
440432
}
441433
fn visit_variant_data(&mut self, s: &'v VariantData<'v>) -> Self::Result {
442434
walk_struct_def(self, s)
@@ -904,8 +896,8 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) -> V::Resul
904896
TyKind::Path(ref qpath) => {
905897
try_visit!(visitor.visit_qpath(qpath, typ.hir_id, typ.span));
906898
}
907-
TyKind::OpaqueDef(opaq, lifetimes, _in_trait) => {
908-
try_visit!(visitor.visit_nested_opaque_ty(opaq));
899+
TyKind::OpaqueDef(opaque, lifetimes, _in_trait) => {
900+
try_visit!(visitor.visit_opaque_ty(opaque));
909901
walk_list!(visitor, visit_generic_arg, lifetimes);
910902
}
911903
TyKind::Array(ref ty, ref length) => {
@@ -1195,8 +1187,17 @@ pub fn walk_poly_trait_ref<'v, V: Visitor<'v>>(
11951187
visitor.visit_trait_ref(&trait_ref.trait_ref)
11961188
}
11971189

1198-
pub fn walk_opaque_ty<'v, V: Visitor<'v>>(visitor: &mut V, opaq: &'v OpaqueTy<'v>) -> V::Result {
1199-
let &OpaqueTy { hir_id, generics, bounds, .. } = opaq;
1190+
pub fn walk_opaque_ty<'v, V: Visitor<'v>>(visitor: &mut V, opaque: &'v OpaqueTy<'v>) -> V::Result {
1191+
let &OpaqueTy {
1192+
hir_id,
1193+
def_id: _,
1194+
generics,
1195+
bounds,
1196+
origin: _,
1197+
lifetime_mapping: _,
1198+
in_trait: _,
1199+
span: _,
1200+
} = opaque;
12001201
try_visit!(visitor.visit_id(hir_id));
12011202
try_visit!(walk_generics(visitor, generics));
12021203
walk_list!(visitor, visit_param_bound, bounds);

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -486,34 +486,27 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
486486
}
487487

488488
#[instrument(level = "debug", skip(self))]
489-
fn visit_opaque_ty(&mut self, opaq: &'tcx rustc_hir::OpaqueTy<'tcx>) {
490-
let (hir::OpaqueTyOrigin::FnReturn(parent)
491-
| hir::OpaqueTyOrigin::AsyncFn(parent)
492-
| hir::OpaqueTyOrigin::TyAlias { parent, .. }) = opaq.origin;
493-
489+
fn visit_opaque_ty(&mut self, opaque: &'tcx rustc_hir::OpaqueTy<'tcx>) {
494490
// We want to start our early-bound indices at the end of the parent scope,
495491
// not including any parent `impl Trait`s.
496492
let mut bound_vars = FxIndexMap::default();
497-
debug!(?opaq.generics.params);
498-
for param in opaq.generics.params {
493+
debug!(?opaque.generics.params);
494+
for param in opaque.generics.params {
499495
let (def_id, reg) = ResolvedArg::early(param);
500496
bound_vars.insert(def_id, reg);
501497
}
502498

503-
let scope = Scope::Root { opt_parent_item: Some(parent) };
504-
let hir_id = self.tcx.local_def_id_to_hir_id(opaq.def_id);
499+
let hir_id = self.tcx.local_def_id_to_hir_id(opaque.def_id);
500+
let scope = Scope::Binder {
501+
hir_id,
502+
bound_vars,
503+
s: self.scope,
504+
scope_type: BinderScopeType::Normal,
505+
where_bound_origin: None,
506+
};
505507
self.with(scope, |this| {
506-
let scope = Scope::Binder {
507-
hir_id,
508-
bound_vars,
509-
s: this.scope,
510-
scope_type: BinderScopeType::Normal,
511-
where_bound_origin: None,
512-
};
513-
this.with(scope, |this| {
514-
let scope = Scope::TraitRefBoundary { s: this.scope };
515-
this.with(scope, |this| intravisit::walk_opaque_ty(this, opaq))
516-
});
508+
let scope = Scope::TraitRefBoundary { s: this.scope };
509+
this.with(scope, |this| intravisit::walk_opaque_ty(this, opaque))
517510
})
518511
}
519512

0 commit comments

Comments
 (0)