Skip to content

Commit 783a9c9

Browse files
Don't unnecessarily lower associated type bounds to impl trait
1 parent 4043493 commit 783a9c9

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
@@ -1087,24 +1087,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10871087

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

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

0 commit comments

Comments
 (0)