Skip to content

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

@huonw

Description

@huonw
Member
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:

Activity

steveklabnik

steveklabnik commented on Nov 4, 2015

@steveklabnik
Member

Triage: the error is very similar today.

added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Mar 9, 2017
steveklabnik

steveklabnik commented on Sep 24, 2018

@steveklabnik
Member

Triage: no change

added 3 commits that reference this issue on Jul 21, 2019
785acaf
4afecf7
e933f54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      Participants

      @steveklabnik@huonw@Mark-Simulacrum

      Issue actions

        Trait suggestions for type parameters should suggest using the traits as bounds · Issue #21673 · rust-lang/rust