Skip to content

Missing & in "use the fully qualified path for the potential candidates" suggestion #96291

Closed
@dtolnay

Description

@dtolnay

Given the following code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=d14f1277f1ad02ee89b35d73b15d2ad6

struct Thing;

trait Method<T> {
    fn method(&self) -> T;
}

impl Method<i32> for Thing {
    fn method(&self) -> i32 { 0 }
}

impl Method<u32> for Thing {
    fn method(&self) -> u32 { 0 }
}

fn main() {
    let thing = Thing;
    thing.method();
}

The current output is:

error[E0283]: type annotations needed
  --> src/main.rs:17:11
   |
17 |     thing.method();
   |     ------^^^^^^--
   |     |     |
   |     |     cannot infer type for type parameter `T` declared on the trait `Method`
   |     this method call resolves to `T`
   |
note: multiple `impl`s satisfying `Thing: Method<_>` found
  --> src/main.rs:7:1
   |
7  | impl Method<i32> for Thing {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^
...
11 | impl Method<u32> for Thing {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^
help: use the fully qualified path for the potential candidates
   |
17 |     <Thing as Method<i32>>::method(thing);
   |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17 |     <Thing as Method<u32>>::method(thing);
   |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Neither of the suggestions compiles because, unlike ., the suggested syntax does not perform autoref.

The correct output would observe that thing.method() is undergoing autoref and instead suggest:

<Thing as Method<i32>>::method(&thing);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<Thing as Method<u32>>::method(&thing);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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