Skip to content

Provide a hint about type parameter conflicting with a structure name #77391

Closed
@KamilaBorowska

Description

@KamilaBorowska

This is something I have seen on users.rust-lang.org: https://users.rust-lang.org/t/implementing-fn-for-a-struct-thats-stored-in-vector/10814

A following code in my opinion should provide a hint to remove <Hello>.

trait Trait {
    fn do_stuff(&self);
}

struct Hello;

impl Hello {
    fn method(&self) {}
}

impl<Hello> Trait for Vec<Hello> {
    fn do_stuff(&self) {
        self[0].method();
    }
}

Currently it provides the following error which is non-ideal:

error[E0599]: no method named `method` found for type parameter `Hello` in the current scope
  --> src/lib.rs:13:17
   |
13 |         self[0].method();
   |                 ^^^^^^ method not found in `Hello`

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.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