Skip to content

Commit

Permalink
Merge pull request #5 from pnkfelix/mult-unbound-assoc-types-with-sam…
Browse files Browse the repository at this point in the history
…e-name

Add section pointing out how associated item ambiguity is handled.
  • Loading branch information
hadronized authored Apr 13, 2017
2 parents 2b14c14 + a2f8020 commit 5c94f49
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions text/0000-trait-alias.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,28 @@ fn bar4(x: Box<IntIterator + Sink + 'static>) { ... } // 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<Assoc = String> + Bar<Assoc = i32>;

// This does not work:
trait FooBar2 = Foo + Bar;
fn badness<T: FooBar2<Assoc = String>>() { } // ERROR: ambiguous associated type

// Here are ways to workaround the above error:
fn better1<T: FooBar2 + Foo<Assoc = String>>() { } // (leaves Bar::Assoc unconstrained)
fn better2<T: FooBar2 + Foo<Assoc = String> + Bar<Assoc = i32>>() { } // constrains both
```

# Teaching
[teaching]: #teaching

Expand Down

0 comments on commit 5c94f49

Please sign in to comment.