-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Detect method not being present that is present in other tuple types #142034
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
Merged
+218
−2
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,39 @@ | ||
trait WorksOnDefault { | ||
fn do_something() {} | ||
} | ||
|
||
impl<T: Default> WorksOnDefault for T {} | ||
//~^ NOTE the following trait bounds were not satisfied | ||
//~| NOTE unsatisfied trait bound introduced here | ||
|
||
trait Foo {} | ||
|
||
trait WorksOnFoo { | ||
fn do_be_do() {} | ||
} | ||
|
||
impl<T: Foo> WorksOnFoo for T {} | ||
//~^ NOTE the following trait bounds were not satisfied | ||
//~| NOTE unsatisfied trait bound introduced here | ||
|
||
impl<A: Foo, B: Foo, C: Foo> Foo for (A, B, C) {} | ||
//~^ NOTE `Foo` is implemented for `(i32, u32, String)` | ||
impl Foo for i32 {} | ||
impl Foo for &i32 {} | ||
impl Foo for u32 {} | ||
impl Foo for String {} | ||
|
||
fn main() { | ||
let _success = <(i32, u32, String)>::do_something(); | ||
let _failure = <(i32, &u32, String)>::do_something(); //~ ERROR E0599 | ||
//~^ NOTE `Default` is implemented for `(i32, u32, String)` | ||
//~| NOTE function or associated item cannot be called on | ||
let _success = <(i32, u32, String)>::do_be_do(); | ||
let _failure = <(i32, &u32, String)>::do_be_do(); //~ ERROR E0599 | ||
//~^ NOTE function or associated item cannot be called on | ||
let _success = <(i32, u32, String)>::default(); | ||
let _failure = <(i32, &u32, String)>::default(); //~ ERROR E0599 | ||
//~^ NOTE `Default` is implemented for `(i32, u32, String)` | ||
//~| NOTE function or associated item cannot be called on | ||
//~| NOTE the following trait bounds were not satisfied | ||
} |
This file contains hidden or 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,58 @@ | ||
error[E0599]: the function or associated item `do_something` exists for tuple `(i32, &u32, String)`, but its trait bounds were not satisfied | ||
--> $DIR/missing-bound-on-tuple.rs:28:43 | ||
| | ||
LL | let _failure = <(i32, &u32, String)>::do_something(); | ||
| ^^^^^^^^^^^^ function or associated item cannot be called on `(i32, &u32, String)` due to unsatisfied trait bounds | ||
| | ||
note: the following trait bounds were not satisfied: | ||
`&(i32, &u32, String): Default` | ||
`&mut (i32, &u32, String): Default` | ||
`(i32, &u32, String): Default` | ||
--> $DIR/missing-bound-on-tuple.rs:5:9 | ||
| | ||
LL | impl<T: Default> WorksOnDefault for T {} | ||
| ^^^^^^^ -------------- - | ||
| | | ||
| unsatisfied trait bound introduced here | ||
note: `Default` is implemented for `(i32, u32, String)` but not for `(i32, &u32, String)` | ||
--> $SRC_DIR/core/src/tuple.rs:LL:COL | ||
= note: this error originates in the macro `tuple_impls` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0599]: the function or associated item `do_be_do` exists for tuple `(i32, &u32, String)`, but its trait bounds were not satisfied | ||
--> $DIR/missing-bound-on-tuple.rs:32:43 | ||
| | ||
LL | let _failure = <(i32, &u32, String)>::do_be_do(); | ||
| ^^^^^^^^ function or associated item cannot be called on `(i32, &u32, String)` due to unsatisfied trait bounds | ||
| | ||
note: the following trait bounds were not satisfied: | ||
`&(i32, &u32, String): Foo` | ||
`&mut (i32, &u32, String): Foo` | ||
`(i32, &u32, String): Foo` | ||
--> $DIR/missing-bound-on-tuple.rs:15:9 | ||
| | ||
LL | impl<T: Foo> WorksOnFoo for T {} | ||
| ^^^ ---------- - | ||
| | | ||
| unsatisfied trait bound introduced here | ||
note: `Foo` is implemented for `(i32, u32, String)` but not for `(i32, &u32, String)` | ||
--> $DIR/missing-bound-on-tuple.rs:19:1 | ||
| | ||
LL | impl<A: Foo, B: Foo, C: Foo> Foo for (A, B, C) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0599]: the function or associated item `default` exists for tuple `(i32, &u32, String)`, but its trait bounds were not satisfied | ||
--> $DIR/missing-bound-on-tuple.rs:35:43 | ||
| | ||
LL | let _failure = <(i32, &u32, String)>::default(); | ||
| ^^^^^^^ function or associated item cannot be called on `(i32, &u32, String)` due to unsatisfied trait bounds | ||
| | ||
= note: the following trait bounds were not satisfied: | ||
`&u32: Default` | ||
which is required by `(i32, &u32, String): Default` | ||
note: `Default` is implemented for `(i32, u32, String)` but not for `(i32, &u32, String)` | ||
--> $SRC_DIR/core/src/tuple.rs:LL:COL | ||
= note: this error originates in the macro `tuple_impls` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0599`. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a smell blatantly taken from another diagnostic. This seems to be a recurring useful need: assert if a certain (trait) predicate would be fulfilled with a different type, and if so, get the span for that specific
impl
. We should probably add a mechanism of doing that toTyCtxt
.