-
Notifications
You must be signed in to change notification settings - Fork 13k
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
In presence of impl <T: Trait1> Trait2 for T
, when X: Trait2
fails, Rust guides you towards satisfying X: Trait1
instead of X: Trait2
#124802
Comments
Here's a somewhat minimized example: error[E0599]: the method `into_pi` exists for enum `Option<T>`, but its trait bounds were not satisfied
--> src/lib.rs:7:7
|
7 | v.into_pi()
| ^^^^^^^
|
= note: the following trait bounds were not satisfied:
`&Option<T>: PI`
which is required by `&Option<T>: IntoPI`
`&mut Option<T>: PI`
which is required by `&mut Option<T>: IntoPI`
warning: unused import: `IntoPI`
--> src/lib.rs:1:10
|
1 | use pi::{IntoPI, PI};
| ^^^^^^
|
= note: `#[warn(unused_imports)]` on by default If you inline error[E0599]: the method `into_pi` exists for enum `Option<T>`, but its trait bounds were not satisfied
--> src/lib.rs:39:7
|
39 | v.into_pi()
| ^^^^^^^
|
note: the following trait bounds were not satisfied:
`&Option<T>: PI`
`&mut Option<T>: PI`
--> src/lib.rs:13:9
|
13 | impl<T: PI> IntoPI for T {
| ^^ ------ -
| |
| unsatisfied trait bound introduced here
= help: items from traits can only be used if the trait is implemented and in scope
note: `IntoPI` defines an item `into_pi`, perhaps you need to implement it
--> src/lib.rs:8:1
|
8 | pub trait IntoPI {
| ^^^^^^^^^^^^^^^^ indeed the culprit behind such weird diagnostic messages is this impl impl<T: PI> IntoPI for T {
type I = T;
fn into_pi(self) -> Self::I {
self
}
} without it, you get the correct suggestion to add the But if instead you remove the = note: the following trait bounds were not satisfied:
`Option<T>: PI`
which is required by `Option<T>: IntoPI`
`&Option<T>: PI`
which is required by `&Option<T>: IntoPI`
`&mut Option<T>: PI`
which is required by `&mut Option<T>: IntoPI` which now has 3 items instead of two. Similarly, adding error[E0599]: no method named `into_pi` found for enum `Option` in the current scope
--> src/lib.rs:7:7
|
7 | v.into_pi()
| ^^^^^^^
|
help: there is a method `into` with a similar name
|
7 | v.into()
| ~~~~
warning: unused import: `IntoPI`
--> src/lib.rs:1:10
|
1 | use pi::{IntoPI, PI};
| ^^^^^^
|
= note: `#[warn(unused_imports)]` on by default TL;DRSo, to recap. You have two traits. So I guess @rustbot label -E-needs-mcve |
: Send
bound with rayon
's IntoParallelIterator
impl <T: Trait1> Trait2 for T
, when X: Trait2
fails, Rust guides you towards satisfying X: Trait1
instead of X: Trait2
In this case, we get a suggestion to restrict trait S {}
trait A {}
// impl<T: S> A for T {}
impl<T: S> A for Option<T> {}
fn f<T>(v: Option<T>) -> impl A { v } Is that similar to the issue that's being brought up? |
I think so |
@rustbot claim |
Don't suggest `.into_iter()` on iterators This makes the the suggestion to call `.into_iter()` only consider unsatisfied `Iterator` bounds for the receiver type itself. That way, it ignores predicates generated by trying to auto-ref the receiver (the result of which usually won't implement `Iterator`). Fixes rust-lang#127511 Unfortunately, the error in that case is still confusing: it labels `Iterator` as an unsatisfied bound because `&impl Iterator: Iterator` can't be satisfied, despite that not being required or helpful. I'd like to handle that in a separate PR. ~~I'm hoping fixing rust-lang#124802 will fix it too.~~ It doesn't look connected to that issue. Still, I think it'd be clearest to visually distinguish unsatisfied predicates from different attempts at `pick_method`; I'll make a PR for that soon.
Rollup merge of rust-lang#132760 - dianne:iter-into-iter, r=lcnr Don't suggest `.into_iter()` on iterators This makes the the suggestion to call `.into_iter()` only consider unsatisfied `Iterator` bounds for the receiver type itself. That way, it ignores predicates generated by trying to auto-ref the receiver (the result of which usually won't implement `Iterator`). Fixes rust-lang#127511 Unfortunately, the error in that case is still confusing: it labels `Iterator` as an unsatisfied bound because `&impl Iterator: Iterator` can't be satisfied, despite that not being required or helpful. I'd like to handle that in a separate PR. ~~I'm hoping fixing rust-lang#124802 will fix it too.~~ It doesn't look connected to that issue. Still, I think it'd be clearest to visually distinguish unsatisfied predicates from different attempts at `pick_method`; I'll make a PR for that soon.
Don't suggest `.into_iter()` on iterators This makes the the suggestion to call `.into_iter()` only consider unsatisfied `Iterator` bounds for the receiver type itself. That way, it ignores predicates generated by trying to auto-ref the receiver (the result of which usually won't implement `Iterator`). Fixes rust-lang#127511 Unfortunately, the error in that case is still confusing: it labels `Iterator` as an unsatisfied bound because `&impl Iterator: Iterator` can't be satisfied, despite that not being required or helpful. I'd like to handle that in a separate PR. ~~I'm hoping fixing rust-lang#124802 will fix it too.~~ It doesn't look connected to that issue. Still, I think it'd be clearest to visually distinguish unsatisfied predicates from different attempts at `pick_method`; I'll make a PR for that soon.
Code
Current output
Desired output
What's really missing is a
T: Send
bound.Rationale and extra context
No response
Other cases
No response
Rust Version
Anything else?
I will try to provide a MCVE. In the meantime, @rustbot label +E-needs-mcve
The text was updated successfully, but these errors were encountered: