-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suggest constraining type parameters
- Loading branch information
Showing
4 changed files
with
144 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/test/ui/suggestions/missing-trait-bounds-for-method-call.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#[derive(Default, PartialEq)] | ||
struct Foo<T> { | ||
bar: Box<[T]>, | ||
} | ||
|
||
trait Bar { | ||
fn foo(&self) {} | ||
} | ||
|
||
impl<T: Default + Bar> Bar for Foo<T> {} | ||
|
||
impl<T> Foo<T> { | ||
fn bar(&self) { | ||
self.foo(); | ||
//~^ ERROR no method named `foo` found for reference `&Foo<T>` in the current scope | ||
} | ||
} | ||
|
||
struct Fin<T> where T: Bar { | ||
bar: Box<[T]>, | ||
} | ||
|
||
impl<T: Default + Bar> Bar for Fin<T> {} | ||
|
||
impl<T: Bar> Fin<T> { | ||
fn bar(&self) { | ||
self.foo(); | ||
//~^ ERROR no method named `foo` found for reference `&Fin<T>` in the current scope | ||
} | ||
} | ||
fn main() {} |
44 changes: 44 additions & 0 deletions
44
src/test/ui/suggestions/missing-trait-bounds-for-method-call.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
error[E0599]: no method named `foo` found for reference `&Foo<T>` in the current scope | ||
--> $DIR/missing-trait-bounds-for-method-call.rs:14:14 | ||
| | ||
LL | struct Foo<T> { | ||
| ------------- doesn't satisfy `Foo<T>: Bar` | ||
... | ||
LL | trait Bar { | ||
| --------- `Bar` defines an item `foo`, perhaps you need to implement it | ||
... | ||
LL | self.foo(); | ||
| ^^^ method not found in `&Foo<T>` | ||
| | ||
= note: the method `foo` exists but the following trait bounds were not satisfied: | ||
`T: Bar` which is required by `Foo<T>: Bar` | ||
`T: std::default::Default` which is required by `Foo<T>: Bar` | ||
= help: items from traits can only be used if the trait is implemented and in scope | ||
help: consider restricting the type parameters to satisfy the obligations | ||
| | ||
LL | struct Foo<T> where T: Bar, T: std::default::Default { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0599]: no method named `foo` found for reference `&Fin<T>` in the current scope | ||
--> $DIR/missing-trait-bounds-for-method-call.rs:27:14 | ||
| | ||
LL | trait Bar { | ||
| --------- `Bar` defines an item `foo`, perhaps you need to implement it | ||
... | ||
LL | struct Fin<T> where T: Bar { | ||
| -------------------------- doesn't satisfy `Fin<T>: Bar` | ||
... | ||
LL | self.foo(); | ||
| ^^^ method not found in `&Fin<T>` | ||
| | ||
= note: the method `foo` exists but the following trait bounds were not satisfied: | ||
`T: std::default::Default` which is required by `Fin<T>: Bar` | ||
= help: items from traits can only be used if the trait is implemented and in scope | ||
help: consider restricting the type parameter to satisfy the obligation | ||
| | ||
LL | struct Fin<T> where T: Bar, T: std::default::Default { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0599`. |