Skip to content

Trait suggestions for type parameters should suggest using the traits as bounds #21673

Closed
@huonw

Description

@huonw
trait Foo { fn method(&self) {} }

fn call_method<T>(x: &T) {
    x.method()
}

fn main() {}

currently gives

error[E0599]: no method named `method` found for type `&T` in the current scope
 --> src/main.rs:4:7
  |
4 |     x.method()
  |       ^^^^^^
  |
  = help: items from traits can only be used if the trait is implemented and in scope
  = note: the following trait defines an item `method`, perhaps you need to implement it:
          candidate #1: `Foo`

but the long help would be better as something like:

methods from traits can only be called if the the type parameter is bounded those traits; the following trait defines a method method:

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemC-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