Skip to content

Commit a88d94b

Browse files
authored
Rollup merge of #97702 - cjgillot:no-universal-did, r=spastorino
Remove useless LocalDefId in ImplTraitContext::Universal.
2 parents 74f0bcc + 4120080 commit a88d94b

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

compiler/rustc_ast_lowering/src/item.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
266266
let body_id =
267267
this.lower_maybe_async_body(span, &decl, asyncness, body.as_deref());
268268

269-
let itctx = ImplTraitContext::Universal(this.current_hir_id_owner);
269+
let itctx = ImplTraitContext::Universal;
270270
let (generics, decl) = this.lower_generics(generics, id, itctx, |this| {
271271
let ret_id = asyncness.opt_return_id();
272272
this.lower_fn_decl(&decl, Some(id), FnDeclKind::Fn, ret_id)
@@ -385,7 +385,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
385385
// method, it will not be considered an in-band
386386
// lifetime to be added, but rather a reference to a
387387
// parent lifetime.
388-
let itctx = ImplTraitContext::Universal(self.current_hir_id_owner);
388+
let itctx = ImplTraitContext::Universal;
389389
let (generics, (trait_ref, lowered_ty)) =
390390
self.lower_generics(ast_generics, id, itctx, |this| {
391391
let trait_ref = trait_ref.as_ref().map(|trait_ref| {
@@ -655,7 +655,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
655655
kind: match i.kind {
656656
ForeignItemKind::Fn(box Fn { ref sig, ref generics, .. }) => {
657657
let fdec = &sig.decl;
658-
let itctx = ImplTraitContext::Universal(self.current_hir_id_owner);
658+
let itctx = ImplTraitContext::Universal;
659659
let (generics, (fn_dec, fn_args)) =
660660
self.lower_generics(generics, i.id, itctx, |this| {
661661
(
@@ -1237,7 +1237,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
12371237
is_async: Option<NodeId>,
12381238
) -> (&'hir hir::Generics<'hir>, hir::FnSig<'hir>) {
12391239
let header = self.lower_fn_header(sig.header);
1240-
let itctx = ImplTraitContext::Universal(self.current_hir_id_owner);
1240+
let itctx = ImplTraitContext::Universal;
12411241
let (generics, decl) = self.lower_generics(generics, id, itctx, |this| {
12421242
this.lower_fn_decl(&sig.decl, Some(id), kind, is_async)
12431243
});

compiler/rustc_ast_lowering/src/lib.rs

+7-13
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ enum ImplTraitContext {
253253
/// equivalent to a fresh universal parameter like `fn foo<T: Debug>(x: T)`.
254254
///
255255
/// Newly generated parameters should be inserted into the given `Vec`.
256-
Universal(LocalDefId),
256+
Universal,
257257

258258
/// Treat `impl Trait` as shorthand for a new opaque type.
259259
/// Example: `fn foo() -> impl Debug`, where `impl Debug` is conceptually
@@ -887,7 +887,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
887887
hir::TypeBindingKind::Equality { term }
888888
}
889889
AssocConstraintKind::Bound { ref bounds } => {
890-
let mut parent_def_id = self.current_hir_id_owner;
891890
// Piggy-back on the `impl Trait` context to figure out the correct behavior.
892891
let (desugar_to_impl_trait, itctx) = match itctx {
893892
// We are in the return position:
@@ -907,10 +906,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
907906
// so desugar to
908907
//
909908
// fn foo(x: dyn Iterator<Item = impl Debug>)
910-
ImplTraitContext::Universal(parent) if self.is_in_dyn_type => {
911-
parent_def_id = parent;
912-
(true, itctx)
913-
}
909+
ImplTraitContext::Universal if self.is_in_dyn_type => (true, itctx),
914910

915911
// In `type Foo = dyn Iterator<Item: Debug>` we desugar to
916912
// `type Foo = dyn Iterator<Item = impl Debug>` but we have to override the
@@ -936,6 +932,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
936932
// Desugar `AssocTy: Bounds` into `AssocTy = impl Bounds`. We do this by
937933
// constructing the HIR for `impl bounds...` and then lowering that.
938934

935+
let parent_def_id = self.current_hir_id_owner;
939936
let impl_trait_node_id = self.resolver.next_node_id();
940937
self.resolver.create_def(
941938
parent_def_id,
@@ -1214,12 +1211,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12141211
|this| this.lower_param_bounds(bounds, nested_itctx),
12151212
)
12161213
}
1217-
ImplTraitContext::Universal(parent_def_id) => {
1214+
ImplTraitContext::Universal => {
12181215
// Add a definition for the in-band `Param`.
12191216
let def_id = self.resolver.local_def_id(def_node_id);
12201217

1221-
let hir_bounds = self
1222-
.lower_param_bounds(bounds, ImplTraitContext::Universal(parent_def_id));
1218+
let hir_bounds =
1219+
self.lower_param_bounds(bounds, ImplTraitContext::Universal);
12231220
// Set the name to `impl Bound1 + Bound2`.
12241221
let ident = Ident::from_str_and_span(&pprust::ty_to_string(t), span);
12251222
let param = hir::GenericParam {
@@ -1429,10 +1426,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14291426
}
14301427
let inputs = self.arena.alloc_from_iter(inputs.iter().map(|param| {
14311428
if fn_node_id.is_some() {
1432-
self.lower_ty_direct(
1433-
&param.ty,
1434-
ImplTraitContext::Universal(self.current_hir_id_owner),
1435-
)
1429+
self.lower_ty_direct(&param.ty, ImplTraitContext::Universal)
14361430
} else {
14371431
self.lower_ty_direct(
14381432
&param.ty,

0 commit comments

Comments
 (0)