Skip to content

Commit f865e3d

Browse files
committed
bodge
1 parent a5d2db4 commit f865e3d

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -538,9 +538,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
538538
}
539539
self.visit_fn_ret_ty(&f.decl.output)
540540
}
541-
TyKind::ImplTrait(_, ref bounds) => {
542-
self.with_hir_id_owner(None, |this| {
543-
walk_list!(this, visit_param_bound, bounds);
541+
TyKind::ImplTrait(def_node_id, _) => {
542+
self.lctx.allocate_hir_id_counter(def_node_id);
543+
self.with_hir_id_owner(Some(def_node_id), |this| {
544+
visit::walk_ty(this, t);
544545
});
545546
}
546547
_ => visit::walk_ty(self, t),
@@ -1351,10 +1352,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13511352
// Add a definition for the in-band `Param`.
13521353
let def_id = self.resolver.local_def_id(def_node_id);
13531354

1354-
let hir_bounds = self.lower_param_bounds(
1355-
bounds,
1356-
ImplTraitContext::Universal(in_band_ty_params),
1357-
);
1355+
self.allocate_hir_id_counter(def_node_id);
1356+
1357+
let hir_bounds = self.with_hir_id_owner(def_node_id, |this| {
1358+
this.lower_param_bounds(
1359+
bounds,
1360+
ImplTraitContext::Universal(in_band_ty_params),
1361+
)
1362+
});
13581363
// Set the name to `impl Bound1 + Bound2`.
13591364
let ident = Ident::from_str_and_span(&pprust::ty_to_string(t), span);
13601365
in_band_ty_params.push(hir::GenericParam {

compiler/rustc_middle/src/hir/map/collector.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,26 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
360360
}
361361

362362
fn visit_generic_param(&mut self, param: &'hir GenericParam<'hir>) {
363-
self.insert(param.span, param.hir_id, Node::GenericParam(param));
364-
intravisit::walk_generic_param(self, param);
363+
if let hir::GenericParamKind::Type {
364+
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
365+
..
366+
} = param.kind
367+
{
368+
debug_assert_eq!(
369+
param.hir_id.owner,
370+
self.definitions.opt_hir_id_to_local_def_id(param.hir_id).unwrap()
371+
);
372+
self.with_dep_node_owner(param.hir_id.owner, param, |this, hash| {
373+
this.insert_with_hash(param.span, param.hir_id, Node::GenericParam(param), hash);
374+
375+
this.with_parent(param.hir_id, |this| {
376+
intravisit::walk_generic_param(this, param);
377+
});
378+
});
379+
} else {
380+
self.insert(param.span, param.hir_id, Node::GenericParam(param));
381+
intravisit::walk_generic_param(self, param);
382+
}
365383
}
366384

367385
fn visit_trait_item(&mut self, ti: &'hir TraitItem<'hir>) {

compiler/rustc_passes/src/hir_id_validator.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,16 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for HirIdValidator<'a, 'hir> {
163163
// we are currently in. So for those it's correct that they have a
164164
// different owner.
165165
}
166+
167+
fn visit_generic_param(&mut self, param: &'hir hir::GenericParam<'hir>) {
168+
if let hir::GenericParamKind::Type {
169+
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
170+
..
171+
} = param.kind
172+
{
173+
// Do nothing because bodging is fun.
174+
} else {
175+
intravisit::walk_generic_param(self, param);
176+
}
177+
}
166178
}

0 commit comments

Comments
 (0)