Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
huonw opened this issue Jan 26, 2015 · 2 comments · Fixed by #62772
Closed

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

huonw opened this issue Jan 26, 2015 · 2 comments · Fixed by #62772
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-traits Area: Trait system C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@huonw
Copy link
Member

huonw commented Jan 26, 2015

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:

@huonw huonw added A-diagnostics Area: Messages for errors, warnings, and lints A-traits Area: Trait system labels Jan 26, 2015
@steveklabnik
Copy link
Member

Triage: the error is very similar today.

@steveklabnik steveklabnik added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 22, 2017
@steveklabnik
Copy link
Member

Triage: no change

Centril added a commit to Centril/rust that referenced this issue Jul 21, 2019
Suggest trait bound on type parameter when it is unconstrained

Given

```
trait Foo { fn method(&self) {} }

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

suggest constraining `T` with `Foo`.

Fix rust-lang#21673, fix rust-lang#41030.
Centril added a commit to Centril/rust that referenced this issue Jul 23, 2019
Suggest trait bound on type parameter when it is unconstrained

Given

```
trait Foo { fn method(&self) {} }

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

suggest constraining `T` with `Foo`.

Fix rust-lang#21673, fix rust-lang#41030.
Centril added a commit to Centril/rust that referenced this issue Jul 24, 2019
Suggest trait bound on type parameter when it is unconstrained

Given

```
trait Foo { fn method(&self) {} }

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

suggest constraining `T` with `Foo`.

Fix rust-lang#21673, fix rust-lang#41030.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-traits Area: Trait system C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants