Skip to content

Commit 548929d

Browse files
Don't unnecessarily lower associated type bounds to impl trait
1 parent 22d582a commit 548929d

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

10951095
// Piggy-back on the `impl Trait` context to figure out the correct behavior.
10961096
let desugar_kind = match itctx {
1097-
// We are in the return position:
1098-
//
1099-
// fn foo() -> impl Iterator<Item: Debug>
1100-
//
1101-
// so desugar to
1102-
//
1103-
// fn foo() -> impl Iterator<Item = impl Debug>
1104-
ImplTraitContext::ReturnPositionOpaqueTy { .. }
1105-
| ImplTraitContext::TypeAliasesOpaqueTy { .. } => DesugarKind::ImplTrait,
1106-
1107-
// We are in the argument position, but within a dyn type:
1097+
// in an argument, RPIT, or TAIT, if we are within a dyn type:
11081098
//
11091099
// fn foo(x: dyn Iterator<Item: Debug>)
11101100
//
1111-
// so desugar to
1101+
// then desugar to:
11121102
//
11131103
// fn foo(x: dyn Iterator<Item = impl Debug>)
1114-
ImplTraitContext::Universal if self.is_in_dyn_type => DesugarKind::ImplTrait,
1104+
//
1105+
// This is because dyn traits must have all of their associated types specified.
1106+
ImplTraitContext::ReturnPositionOpaqueTy { .. }
1107+
| ImplTraitContext::TypeAliasesOpaqueTy { .. }
1108+
| ImplTraitContext::Universal
1109+
if self.is_in_dyn_type =>
1110+
{
1111+
DesugarKind::ImplTrait
1112+
}
11151113

11161114
ImplTraitContext::Disallowed(position) if self.is_in_dyn_type => {
11171115
DesugarKind::Error(position)

0 commit comments

Comments
 (0)