rust-lang / rust-lang/rust

Import associated item of generic trait and confusing "type annotations needed"

Open
#159,199 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics F-import_trait_associated_functions T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
#![feature(import_trait_associated_functions)]

trait X<Y> {
    fn foo() -> String;
}

use X::foo;

fn test() {
    let _ = foo();
}
Current output
error[E0283]: type annotations needed
  --> src/lib.rs:10:13
   |
10 |     let _ = foo();
   |             ^^^^^ cannot infer type
   |
   = note: the type must implement `X<_>`

For more information about this error, try `rustc --explain E0283`.
Desired output

Either the import should be disallowed, or the error should suggest using a trait-qualified function name.

Rationale and extra context

I don't know if there is any way to use an imported associated item of a generic trait?

Tracking issue

Other cases

Rust Version
Nightly channel
Build using the Nightly version: 1.99.0-nightly

(2026-07-11 be8e82435eb04fbe75ed)
Anything else?

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example in src/lib.rs with the nightly toolchain and read the diagnostic around E0283, then review tracking issue #134691 for the feature's intended behavior. Done means the import is rejected or the resulting error suggests a trait-qualified function name for the generic associated item.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.