From a2f8020e72eff390379fbf60dd4fff592f3c1f3a Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Thu, 13 Apr 2017 12:15:50 +0200 Subject: [PATCH] Add section pointing out how associated item ambiguity is handled. --- text/0000-trait-alias.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/text/0000-trait-alias.md b/text/0000-trait-alias.md index e289dd2310e..58a244a21cb 100644 --- a/text/0000-trait-alias.md +++ b/text/0000-trait-alias.md @@ -179,6 +179,28 @@ fn bar4(x: Box) { ... } // ok (*) The lines marked with `(*)` assume that [#24010](https://github.com/rust-lang/rust/issues/24010) is fixed. +### Ambiguous constraints + +If there are multiple associated types with the same name in a trait alias, +then it is a static error ("ambiguous associated type") to attempt to +constrain that associated type via the trait alias. For example: + +```rust +trait Foo { type Assoc; } +trait Bar { type Assoc; } // same name! + +// This works: +trait FooBar1 = Foo + Bar; + +// This does not work: +trait FooBar2 = Foo + Bar; +fn badness>() { } // ERROR: ambiguous associated type + +// Here are ways to workaround the above error: +fn better1>() { } // (leaves Bar::Assoc unconstrained) +fn better2 + Bar>() { } // constrains both +``` + # Teaching [teaching]: #teaching