Skip to content

Incorrect help suggestion on E0790 with parameterized traits #101866

Closed
@polina4096

Description

@polina4096

Given the following code:

trait TraitA<T> {
    fn func();
}

struct StructA {}

impl TraitA<i32> for StructA {
    fn func() {}
}

fn main() {
    TraitA::<i32>::func();
}

The current output is:

error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
  --> src/main.rs:12:5
   |
2  |     fn func();
   |     ---------- `TraitA::func` defined here
...
12 |     TraitA::<i32>::func();
   |     ^^^^^^^^^^^^^^^^^^^ cannot call associated function of trait
   |
help: use the fully-qualified path to the only available implementation
   |
12 |     <::StructA as TraitA>::<i32>::func();
   |     +++++++++++++       +

error: aborting due to previous error

For more information about this error, try `rustc --explain E0790`.

Ideally the output should look like:

error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
  --> src/main.rs:12:5
   |
2  |     fn func();
   |     ---------- `TraitA::func` defined here
...
12 |     TraitA::<i32>::func();
   |     ^^^^^^^^^^^^^^^^^^^ cannot call associated function of trait
   |
help: use the fully-qualified path to the only available implementation
   |
12 |     <StructA as TraitA<i32>>::func();
   |     ++++++++++++           +

error: aborting due to previous error

For more information about this error, try `rustc --explain E0790`.

The suggested code when trying to call associated function on trait without specifying the corresponding impl type does not compile, as the type parameter is in the wrong place.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions