Suggest trait bound on type parameter when it is unconstrained

Given

```
mented on Jan 26, 2015 •
 trait Foo { fn method(&self) {} }

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

suggest constraining `T` with `Foo`.
This commit is contained in:
Esteban Küber 2019-07-17 16:34:13 -07:00
parent 2eb0bc5e3c
commit f22bc2d3ff
5 changed files with 147 additions and 35 deletions

View file

@ -4,9 +4,11 @@ error[E0599]: no function or associated item named `dim` found for type `D` in t
LL | entries: [T; D::dim()],
| ^^^ function or associated item not found in `D`
|
= help: items from traits can only be used if the trait is implemented and in scope
= note: the following trait defines an item `dim`, perhaps you need to implement it:
candidate #1: `Dim`
= help: items from traits can only be used if the type parameter is bounded by the trait
help: the following trait defines an item `dim`, perhaps you need to restrict type parameter `D` with it:
|
LL | pub struct Vector<T, D: Dim + Dim> {
| ^^^^^^^^
error: aborting due to previous error