Remove HR subtyping and replace them with coercions - #160461
Conversation
|
Some changes occurred in cc @BoxyUwU changes to the core type system cc @lcnr This PR modifies Some changes occurred in match checking cc @Nadrieril |
|
|
@bors try @rust-timer queue |
|
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
This comment has been minimized.
This comment has been minimized.
0dd23cc to
46133a8
Compare
|
@bors try @rust-timer queue |
|
This pull request is already queued and waiting for a try build to finish. |
This comment has been minimized.
This comment has been minimized.
Remove HR subtyping and replace them with coercions
|
@craterbot check |
|
🚨 Error: missing start toolchain 🆘 If you have any trouble with Crater please ask in t-infra on Zulip |
Ok, need to wait for the try build to finish. |
This comment has been minimized.
This comment has been minimized.
|
💔 Test for 2c2a830 failed: CI. Failed job:
|
This comment has been minimized.
This comment has been minimized.
46133a8 to
2895a40
Compare
|
The job Click to see the possible cause of the failure (guessed by this bot)Important For more information how to resolve CI failures of this job, visit this link. |
We currently treat, to give an example
for<'a> fn(&'a ())as a subtype offn(&'static ())and that relation propagates through type constructors via variance. These are genuinely different types, with different TypeId, trait impls, associated types. Letting subtyping silently interconvert them (e.g.Foo<for<'a> fn(&'a ())>->Foo<fn(&'static ())>is a long-standing soundness hole (#97156, #134407, #85863, #148821, #25860).This PR, requires HR binders to relate by equality in the type-relating code, and re adds the legitimate HR -> non-HR conversions as a coercion that only applies at coercion sites (so it can no longer leak through type constructors).
What's in the PR:
dyn for<'a> Trait<'a>->dyn Trait<'static>at coercion sites.There's intended breakage (HR conversions through type constructors) is now rejected; direct conversions at coercion sites still compile. Full tests/ui suite green. A wrapped raw-pointer cast (cast_away_higher_ranked_wrap) is left as a FIXME, entangled with #141402.
This is best read commit by commit, after each commit all tests passes, so for instance in one of the first commits, we remove subtyping and tests show what regresses there marking tests as
known-bug. In subsequent commits, we see how after each commit tests start to work again.At the end, over the entire changes, looking at the test changes together is a good idea to see the final state of things.
r? lcnr
cc @rust-lang/types
This is still WIP as: