Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for use Trait::func #3591

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions text/0000-import-trait-associated-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,21 @@ use some_module::Trait::func;

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.

Note that trait generics are handled by this desugaring using type inference. As above, given `Trait<T>`,
```rust
use Trait::func as m;
m(x, y, z);
```
desugars to
```rust
Trait::func(x, y, z);
```
which compiles if and only if `T` can be inferred from the function call. For example, if `func` was
```
fn func(a: T, b: i32, c: i32) {}
obsgolem marked this conversation as resolved.
Show resolved Hide resolved
```
then `T` would be inferred to be the type of `x`, assuming `x` itself can be inferred.

# Drawbacks
[drawbacks]: #drawbacks

Expand Down