-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Suggest correct code for associated fn with type parameters #68982
Comments
I hit this today, couldn't remember the exact prototype so I wanted the compiler to suggest it to me (typing this, I realize how amazing it is that Rust gets most of these suggestions right. Thanks for all the work in this area!). Playground: Copy-pasting the suggestion leads to this: About the second error:
Couldn't the compiler also deduce that For the resugaring error, I'd be willing to tackle this, if you think this is something achievable for a relatively new contributor! |
@alarsyo there are different parts that could potentially be tackled of different level of difficulty. The underlying problem is that by the time the compile error happens, we no longer have access to the original bound information. We know that the method requires An alternative to the "correct" fix above would be to try to unify multiple bounds into a single one when possible. Doing that is concentrated in a single part of the compiler, which can be easier to understand, but will require tricky logic. I would look at all the traits bounds ( Finally, I would love to handle the equality constraint What do you think? Is any of this something of the scope size you'd like to tackle? Edit: Looking at #70908, it seems to me like what would be necessary to accomplish the last part of my comments above would be to pass all the predicates to this function and perform the "unification" I mentioned for the previous cases, so doing either the first or second approach, you can get the last case almost for free 😃 |
Hi @estebank, sorry for the late reply.
I think I can try and build something for the alternative to the "correct" fix you mention, i.e. manually merge an associated type equality constraint bound with another bound if the other bound is about
Making sure I understand this correctly, the difference with the previous idea would be correcting the user when he writes the equality constraint, rather fixing the suggestion provided by the compiler? (both things being complementary to each other, of course). Did I get this right? 😄
So starting with this seems like it'd be a good path? If I understand correctly, implementing the "manual merge" of related bounds would allow its use both to fix the "method impl" suggestion I hit with |
I'll start working on that "unification". Looking at #70908, I'm having a hard time identifying where I'd get started though 😅 |
@estebank friendly ping in case this went past you (nothing pressing if you're not available though!) |
I think you got it right, we would want to support both cases independently (likely in separate PRs). One is reducing the likelihood of hitting the equality case, but anyone could try to write it without waiting for rustc to point them in that direction, so ideally we cover both cases.
Correct. It would be what we need and would work for most cases (but not 100% because we're rejoining things that got separated for a reason, but it would work well enough for all the common cases).
Now with a fresh set of eyes I'm thinking now that you can probably try to unify things just with the information you have in
Sorry! The previous notifications did indeed get drowned and am currently with intermittent internet access. Do not hesitate to ping me again if you need any further help though! |
Current output:
We need to fix how we handle the incorrect syntax, but the initial suggestion is now fixed. |
Provide more suggestions on invalid equality where bounds ``` error: equality constraints are not yet supported in `where` clauses --> $DIR/equality-bound.rs:50:9 | LL | IntoIterator::Item = A | ^^^^^^^^^^^^^^^^^^^^^^ not supported | = note: see issue rust-lang#20041 <rust-lang#20041> for more information help: if `IntoIterator::Item` is an associated type you're trying to set, use the associated type binding syntax | LL ~ fn from_iter<T: IntoIterator<Item = A>>(_: T) -> Self LL ~ | error: equality constraints are not yet supported in `where` clauses --> $DIR/equality-bound.rs:63:9 | LL | T::Item = A | ^^^^^^^^^^^ not supported | = note: see issue rust-lang#20041 <rust-lang#20041> for more information help: if `IntoIterator::Item` is an associated type you're trying to set, use the associated type binding syntax | LL ~ fn from_iter<T: IntoIterator<Item = A>>(_: T) -> Self LL ~ | ``` Fix rust-lang#68982.
Rollup merge of rust-lang#120751 - estebank:issue-68982, r=nnethercote Provide more suggestions on invalid equality where bounds ``` error: equality constraints are not yet supported in `where` clauses --> $DIR/equality-bound.rs:50:9 | LL | IntoIterator::Item = A | ^^^^^^^^^^^^^^^^^^^^^^ not supported | = note: see issue rust-lang#20041 <rust-lang#20041> for more information help: if `IntoIterator::Item` is an associated type you're trying to set, use the associated type binding syntax | LL ~ fn from_iter<T: IntoIterator<Item = A>>(_: T) -> Self LL ~ | error: equality constraints are not yet supported in `where` clauses --> $DIR/equality-bound.rs:63:9 | LL | T::Item = A | ^^^^^^^^^^^ not supported | = note: see issue rust-lang#20041 <rust-lang#20041> for more information help: if `IntoIterator::Item` is an associated type you're trying to set, use the associated type binding syntax | LL ~ fn from_iter<T: IntoIterator<Item = A>>(_: T) -> Self LL ~ | ``` Fix rust-lang#68982.
#68689 partially addresses #50734, but we need to resugar the predicates to unify the output of a trait obligation with related projection obligations (associated types).
For example
should be
The text was updated successfully, but these errors were encountered: