File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -189,6 +189,28 @@ fn bar4(x: Box<IntIterator + Sink + 'static>) { ... } // ok (*)
189
189
The lines marked with ` (*) ` assume that [ #24010 ] ( https://github.com/rust-lang/rust/issues/24010 ) is
190
190
fixed.
191
191
192
+ ### Ambiguous constraints
193
+
194
+ If there are multiple associated types with the same name in a trait alias,
195
+ then it is a static error ("ambiguous associated type") to attempt to
196
+ constrain that associated type via the trait alias. For example:
197
+
198
+ ``` rust
199
+ trait Foo { type Assoc ; }
200
+ trait Bar { type Assoc ; } // same name!
201
+
202
+ // This works:
203
+ trait FooBar1 = Foo <Assoc = String > + Bar <Assoc = i32 >;
204
+
205
+ // This does not work:
206
+ trait FooBar2 = Foo + Bar ;
207
+ fn badness <T : FooBar2 <Assoc = String >>() { } // ERROR: ambiguous associated type
208
+
209
+ // Here are ways to workaround the above error:
210
+ fn better1 <T : FooBar2 + Foo <Assoc = String >>() { } // (leaves Bar::Assoc unconstrained)
211
+ fn better2 <T : FooBar2 + Foo <Assoc = String > + Bar <Assoc = i32 >>() { } // constrains both
212
+ ```
213
+
192
214
# Teaching
193
215
[ teaching ] : #teaching
194
216
You can’t perform that action at this time.
0 commit comments