-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Fix ICE when multiple supertrait substitutions need assoc but only one is provided #133392
base: master
Are you sure you want to change the base?
Conversation
changes to the core type system HIR ty lowering was modified cc @fmease |
@bors try |
Fix ICE when multiple supertrait substitutions need assoc but only one is provided I'll write more here when the crate run is done. Fixes rust-lang#133388 r? lcnr `@rustbot` author
This comment has been minimized.
This comment has been minimized.
☀️ Try build successful - checks-actions |
@craterbot check |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
8a10f68
to
2a0ede8
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as off-topic.
This comment was marked as off-topic.
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🎉 Experiment
|
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
@rfcbot fcp merge Hi @rust-lang/types. Please see the PR description. This fixes what I consider to be a minor issue in the way we validate the associated types that are required to be specified for a |
Team member @compiler-errors has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
☔ The latest upstream changes (presumably #133694) made this pull request unmergeable. Please resolve the merge conflicts. |
2a0ede8
to
24da053
Compare
🔔 This is now entering its final comment period, as per the review above. 🔔 |
@bors r+ rollup |
oh lel, i thought it finished the fcp period 😅 @bors r- |
LL | let q: <dyn Dyn<i32, u32> as Sup<u32>>::Assoc = Default::default(); | ||
| ^^^^^^^^^^^^^ help: specify the associated type: `Dyn<i32, u32, Assoc = Type>` |
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.
Kind of funny that you just cant specify the associated type equality bounds here
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.
Yeah, that's a fundamental limitation of Rust atm. I can't be arsed to improve the diagnostic, though I can open an issue for the diagnostic being confusing if you care.
☔ The latest upstream changes (presumably #134164) made this pull request unmergeable. Please resolve the merge conflicts. |
24da053
to
43e2fd5
Compare
Dyn traits must have all of their associated types constrained either by:
dyn Iterator<Item = u32>
,trait ConstrainedIterator: Iterator<Item = u32> {}
, then you may writedyn ConstrainedIterator
which doesn't need to mentionItem
.However, the object type lowering code did not consider the fact that there may be multiple supertraits with different substitutions, so it just used the associated type's def id as a key for keeping track of which associated types are missing:
rust/compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs
Line 131 in 1fc691e
This means that we can have missing associated types when there are mutliple supertraits with different substitutions and only one of them is constrained, like:
The above example allows you to name
<dyn Dyn<i32, u32> as Sup<u32>>::Assoc
even though it is not possible to project since it's neither constrained by a manually written projection bound or a supertrait bound. This successfully type-checks, but leads to a codegen ICE since we are not able to project the associated type.This PR fixes the validation for checking that a dyn trait mentions all of its associated type bounds. This is theoretically a breaking change, since you could technically use that
dyn Dyn<A, B>
type mentionedin the example above without actually projecting to the bad associated type, but I don't expect it to ever be relevant to a user since it's almost certainly a bug. This is corroborated with the crater results1, which show no failures2.Crater: #133392 (comment)
Fixes #133388
Footnotes
I cratered this originally with Fix dyn incompleteness with multiple supertraits with different substitutions #133397, which is a PR that is stacked on top, then re-ran crater with just the failures from that PR. ↩
If you look at the crater results, it shows all of the passes as "unknown". I believe this is a crater bug, since looking at the results manually shows them as passes. ↩