Remove useless LocalDefId in ImplTraitContext::Universal.

This commit is contained in:
Camille GILLOT 2022-06-03 20:17:12 +02:00
parent e40d5e83dc
commit 4120080d66
2 changed files with 11 additions and 17 deletions

View file

@ -253,7 +253,7 @@ enum ImplTraitContext {
/// equivalent to a fresh universal parameter like `fn foo<T: Debug>(x: T)`.
///
/// Newly generated parameters should be inserted into the given `Vec`.
Universal(LocalDefId),
Universal,
/// Treat `impl Trait` as shorthand for a new opaque type.
/// Example: `fn foo() -> impl Debug`, where `impl Debug` is conceptually
@ -895,7 +895,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir::TypeBindingKind::Equality { term }
}
AssocConstraintKind::Bound { ref bounds } => {
let mut parent_def_id = self.current_hir_id_owner;
// Piggy-back on the `impl Trait` context to figure out the correct behavior.
let (desugar_to_impl_trait, itctx) = match itctx {
// We are in the return position:
@ -915,10 +914,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// so desugar to
//
// fn foo(x: dyn Iterator<Item = impl Debug>)
ImplTraitContext::Universal(parent) if self.is_in_dyn_type => {
parent_def_id = parent;
(true, itctx)
}
ImplTraitContext::Universal if self.is_in_dyn_type => (true, itctx),
// In `type Foo = dyn Iterator<Item: Debug>` we desugar to
// `type Foo = dyn Iterator<Item = impl Debug>` but we have to override the
@ -944,6 +940,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// Desugar `AssocTy: Bounds` into `AssocTy = impl Bounds`. We do this by
// constructing the HIR for `impl bounds...` and then lowering that.
let parent_def_id = self.current_hir_id_owner;
let impl_trait_node_id = self.resolver.next_node_id();
self.resolver.create_def(
parent_def_id,
@ -1186,12 +1183,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|this| this.lower_param_bounds(bounds, nested_itctx),
)
}
ImplTraitContext::Universal(parent_def_id) => {
ImplTraitContext::Universal => {
// Add a definition for the in-band `Param`.
let def_id = self.resolver.local_def_id(def_node_id);
let hir_bounds = self
.lower_param_bounds(bounds, ImplTraitContext::Universal(parent_def_id));
let hir_bounds =
self.lower_param_bounds(bounds, ImplTraitContext::Universal);
// Set the name to `impl Bound1 + Bound2`.
let ident = Ident::from_str_and_span(&pprust::ty_to_string(t), span);
let param = hir::GenericParam {
@ -1401,10 +1398,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
let inputs = self.arena.alloc_from_iter(inputs.iter().map(|param| {
if fn_node_id.is_some() {
self.lower_ty_direct(
&param.ty,
ImplTraitContext::Universal(self.current_hir_id_owner),
)
self.lower_ty_direct(&param.ty, ImplTraitContext::Universal)
} else {
self.lower_ty_direct(
&param.ty,