Skip to content

Commit 3683191

Browse files
Don't unnecessarily lower associated type bounds to impl trait
1 parent 0b1392f commit 3683191

File tree

1 file changed

+11
-13
lines changed
  • compiler/rustc_ast_lowering/src

1 file changed

+11
-13
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -1086,24 +1086,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10861086

10871087
// Piggy-back on the `impl Trait` context to figure out the correct behavior.
10881088
let desugar_kind = match itctx {
1089-
// We are in the return position:
1090-
//
1091-
// fn foo() -> impl Iterator<Item: Debug>
1092-
//
1093-
// so desugar to
1094-
//
1095-
// fn foo() -> impl Iterator<Item = impl Debug>
1096-
ImplTraitContext::ReturnPositionOpaqueTy { .. }
1097-
| ImplTraitContext::TypeAliasesOpaqueTy { .. } => DesugarKind::ImplTrait,
1098-
1099-
// We are in the argument position, but within a dyn type:
1089+
// in an argument, RPIT, or TAIT, if we are within a dyn type:
11001090
//
11011091
// fn foo(x: dyn Iterator<Item: Debug>)
11021092
//
1103-
// so desugar to
1093+
// then desugar to:
11041094
//
11051095
// fn foo(x: dyn Iterator<Item = impl Debug>)
1106-
ImplTraitContext::Universal if self.is_in_dyn_type => DesugarKind::ImplTrait,
1096+
//
1097+
// This is because dyn traits must have all of their associated types specified.
1098+
ImplTraitContext::ReturnPositionOpaqueTy { .. }
1099+
| ImplTraitContext::TypeAliasesOpaqueTy { .. }
1100+
| ImplTraitContext::Universal
1101+
if self.is_in_dyn_type =>
1102+
{
1103+
DesugarKind::ImplTrait
1104+
}
11071105

11081106
ImplTraitContext::Disallowed(position) if self.is_in_dyn_type => {
11091107
DesugarKind::Error(position)

0 commit comments

Comments
 (0)