diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-07-26 00:57:20 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-26 00:57:20 +0200 |
| commit | a88354831b88a88575fd2139876cd062c775bc40 (patch) | |
| tree | addecb596d6251ebb1acce281bd5087c46da49d7 /tests/codegen/patchable-function-entry/patchable-function-entry-both-flags.rs | |
| parent | 7120fdac7a6e55a5e4b606256042890b36067052 (diff) | |
| parent | 172cf9bef3411d479a0be98827647150cce48afd (diff) | |
| download | rust-a88354831b88a88575fd2139876cd062c775bc40.tar.gz rust-a88354831b88a88575fd2139876cd062c775bc40.zip | |
Rollup merge of #126090 - compiler-errors:supertrait-assoc-ty-unsoundness, r=lcnr
Fix supertrait associated type unsoundness ### What? Object safety allows us to name `Self::Assoc` associated types in certain positions if they come from our trait or one of our supertraits. When this check was implemented, I think it failed to consider that supertraits can have different args, and it was only checking def-id equality. This is problematic, since we can sneak different implementations in by implementing `Supertrait<NotActuallyTheSupertraitSubsts>` for a `dyn` type. This can be used to implement an unsound transmute function. See the committed test. ### How do we fix it? We consider the whole trait ref when checking for supertraits. Right now, this is implemented using equality *without* normalization. We erase regions since those don't affect trait selection. This is a limitation that could theoretically affect code that should be accepted, but doesn't matter in practice -- there are 0 crater regression. We could make this check stronger, but I would be worried about cycle issues. I assume that most people are writing `Self::Assoc` so they don't really care about the trait ref being normalized. --- ### What is up w the stacked commit This is built on top of https://github.com/rust-lang/rust/pull/122804 though that's really not related, it's just easier to make this modification with the changes to the object safety code that I did in that PR. The only thing is that PR may make this unsoundness slightly easier to abuse, since there are more positions that allow self-associated-types -- I am happy to stall that change until this PR merges. --- Fixes #126079 r? lcnr
Diffstat (limited to 'tests/codegen/patchable-function-entry/patchable-function-entry-both-flags.rs')
0 files changed, 0 insertions, 0 deletions
