-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Mention implementers of unsatisfied trait #91873
Mention implementers of unsatisfied trait #91873
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
a8bcbd3
to
f1eb1c0
Compare
Does this fix/work towards fixing #90970? |
As is, it does not:
Looking if there's a straightforward change that can be done. Edit: With a quick check, I managed to get the following:
I would like to iterate a bit further (and report the error higher in the obligation chain so we only talk about What do you think? |
Update: now it does cover it, slightly. |
I think it's already an improvement that it lists those other implementations and thus likely clears up the potential confusion of the user much faster which may arise from the incorrect mention of I first faced this error message a few years ago when I wasn't that familiar with Rust yet and I remember it took me a quite a bit of time to figure out what was going on. So any steps towards fixing this is great!
Sure! I hope you (or someone else of course) can figure out how to suppress, really, references to |
This comment was marked as resolved.
This comment was marked as resolved.
d2ada99
to
9a5872f
Compare
Sorry for the delay. I think it might be better if someone from wg-diagnostics reviewed this. r? rust-lang/diagnostics |
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.
I like the diagnostic change, couple comments on the implementation where we might be able to deduplicate things a bit.
compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
Outdated
Show resolved
Hide resolved
compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
Outdated
Show resolved
Hide resolved
compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
Outdated
Show resolved
Hide resolved
This comment was marked as resolved.
This comment was marked as resolved.
845dc7d
to
ba3450e
Compare
This comment was marked as resolved.
This comment was marked as resolved.
38ef896
to
1bb5b95
Compare
c278cd1
to
e2f263e
Compare
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.
r=me unless you want to squash the commits first
☔ The latest upstream changes (presumably #95552) made this pull request unmergeable. Please resolve the merge conflicts. |
When encountering an unsatisfied trait bound, if there are no other suggestions, mention all the types that *do* implement that trait: ``` error[E0277]: the trait bound `f32: Foo` is not satisfied --> $DIR/impl_wf.rs:22:6 | LL | impl Baz<f32> for f32 { } | ^^^^^^^^ the trait `Foo` is not implemented for `f32` | = help: the following other types implement trait `Foo`: Option<T> i32 str note: required by a bound in `Baz` --> $DIR/impl_wf.rs:18:31 | LL | trait Baz<U: ?Sized> where U: Foo { } | ^^^ required by this bound in `Baz` ``` Mention implementers of traits in `ImplObligation`s. Do not mention other `impl`s for closures, ranges and `?`.
e2f263e
to
e1ef833
Compare
@bors r=davidtwco |
📌 Commit e1ef833 has been approved by |
…ied-trait, r=davidtwco Mention implementers of unsatisfied trait When encountering an unsatisfied trait bound, if there are no other suggestions, mention all the types that *do* implement that trait: ``` error[E0277]: the trait bound `f32: Foo` is not satisfied --> $DIR/impl_wf.rs:22:6 | LL | impl Baz<f32> for f32 { } | ^^^^^^^^ the trait `Foo` is not implemented for `f32` | = help: the trait `Foo` is implemented for `i32` note: required by a bound in `Baz` --> $DIR/impl_wf.rs:18:31 | LL | trait Baz<U: ?Sized> where U: Foo { } | ^^^ required by this bound in `Baz` ``` ``` error[E0277]: the trait bound `u32: Foo` is not satisfied --> $DIR/associated-types-path-2.rs:29:5 | LL | f1(2u32, 4u32); | ^^ the trait `Foo` is not implemented for `u32` | = help: the trait `Foo` is implemented for `i32` note: required by a bound in `f1` --> $DIR/associated-types-path-2.rs:13:14 | LL | pub fn f1<T: Foo>(a: T, x: T::A) {} | ^^^ required by this bound in `f1` ``` Suggest dereferencing in more cases. Fix rust-lang#87437, fix rust-lang#90970.
Rollup of 7 pull requests Successful merges: - rust-lang#91873 (Mention implementers of unsatisfied trait) - rust-lang#95588 (explicitly distinguish pointer::addr and pointer::expose_addr) - rust-lang#95603 (Fix late-bound ICE in `dyn` return type suggestion) - rust-lang#95620 (interpret: remove MemoryExtra in favor of giving access to the Machine) - rust-lang#95630 (Update `NonNull` pointer provenance methods' documentation) - rust-lang#95631 (Refactor: remove unnecessary nested blocks) - rust-lang#95642 (`CandidateSource::XCandidate` -> `CandidateSource::X`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
When encountering an unsatisfied trait bound, if there are no other
suggestions, mention all the types that do implement that trait:
Suggest dereferencing in more cases.
Fix #87437, fix #90970.