forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#62772 - estebank:trait-bound, r=matthewjasper
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.
- Loading branch information
Showing
5 changed files
with
148 additions
and
36 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
trait Foo { | ||
fn method(&self) {} | ||
} | ||
|
||
fn call_method<T: std::fmt::Debug>(x: &T) { | ||
x.method() //~ ERROR E0599 | ||
} | ||
|
||
fn call_method_2<T>(x: T) { | ||
x.method() //~ ERROR E0599 | ||
} | ||
|
||
fn main() {} |
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,27 @@ | ||
error[E0599]: no method named `method` found for type `&T` in the current scope | ||
--> $DIR/issue-21673.rs:6:7 | ||
| | ||
LL | x.method() | ||
| ^^^^^^ | ||
| | ||
= help: items from traits can only be used if the type parameter is bounded by the trait | ||
help: the following trait defines an item `method`, perhaps you need to restrict type parameter `T` with it: | ||
| | ||
LL | fn call_method<T: Foo + std::fmt::Debug>(x: &T) { | ||
| ^^^^^^^^ | ||
|
||
error[E0599]: no method named `method` found for type `T` in the current scope | ||
--> $DIR/issue-21673.rs:10:7 | ||
| | ||
LL | x.method() | ||
| ^^^^^^ | ||
| | ||
= help: items from traits can only be used if the type parameter is bounded by the trait | ||
help: the following trait defines an item `method`, perhaps you need to restrict type parameter `T` with it: | ||
| | ||
LL | fn call_method_2<T: Foo>(x: T) { | ||
| ^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0599`. |