Skip to content

Commit 69ef26a

Browse files
committed
Clarified details of trait generic inferrence.
1 parent 3f17ff8 commit 69ef26a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

text/0000-import-trait-associated-functions.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,21 @@ use some_module::Trait::func;
189189

190190
The restriction on importing parent trait associated functions is a consequence of this desugaring, see https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=51bef9ba69ce1fc20248e987bf106bd4 for examples of the errors you get when you try to call parent trait associated functions through a child trait. We will likely want better error messages than this if a user tries to import a parent function.
191191

192+
Note that trait generics are handled by this desugaring using type inference. As above, given `Trait<T>`,
193+
```rust
194+
use Trait::func as m;
195+
m(x, y, z);
196+
```
197+
desugars to
198+
```rust
199+
Trait::func(x, y, z);
200+
```
201+
which compiles if and only if `T` can be inferred from the function call. For example, if `func` was
202+
```
203+
fn func(a: T, b: i32, c: i32) {}
204+
```
205+
then `T` would be inferred to be the type of `x`, assuming `x` itself can be inferred.
206+
192207
# Drawbacks
193208
[drawbacks]: #drawbacks
194209

0 commit comments

Comments
 (0)