mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
a88354831b
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 |
||
---|---|---|
.. | ||
almost-supertrait-associated-type.rs | ||
almost-supertrait-associated-type.stderr | ||
assoc_const_bounds_sized.rs | ||
assoc_const_bounds.rs | ||
assoc_type_bounds2.rs | ||
assoc_type_bounds2.stderr | ||
assoc_type_bounds_implicit_sized.fixed | ||
assoc_type_bounds_implicit_sized.rs | ||
assoc_type_bounds_implicit_sized.stderr | ||
assoc_type_bounds_sized_others.rs | ||
assoc_type_bounds_sized_others.stderr | ||
assoc_type_bounds_sized_unnecessary.rs | ||
assoc_type_bounds_sized_unnecessary.stderr | ||
assoc_type_bounds_sized_used.rs | ||
assoc_type_bounds_sized_used.stderr | ||
assoc_type_bounds_sized.rs | ||
assoc_type_bounds.rs | ||
assoc_type_bounds.stderr | ||
avoid-ice-on-warning-2.new.stderr | ||
avoid-ice-on-warning-2.old.stderr | ||
avoid-ice-on-warning-2.rs | ||
avoid-ice-on-warning-3.new.stderr | ||
avoid-ice-on-warning-3.old.stderr | ||
avoid-ice-on-warning-3.rs | ||
avoid-ice-on-warning.new.stderr | ||
avoid-ice-on-warning.old.stderr | ||
avoid-ice-on-warning.rs | ||
bare-trait-dont-suggest-dyn.new.fixed | ||
bare-trait-dont-suggest-dyn.new.stderr | ||
bare-trait-dont-suggest-dyn.old.stderr | ||
bare-trait-dont-suggest-dyn.rs | ||
call-when-assoc-ty-is-sized.rs | ||
erroneous_signature.rs | ||
erroneous_signature.stderr | ||
issue-19538.rs | ||
issue-19538.stderr | ||
issue-102762.rs | ||
issue-102762.stderr | ||
issue-102933.rs | ||
issue-106247.rs | ||
item-bounds-can-reference-self.rs | ||
object-safety-associated-consts.curr.stderr | ||
object-safety-associated-consts.object_safe_for_dispatch.stderr | ||
object-safety-associated-consts.rs | ||
object-safety-bounds.rs | ||
object-safety-bounds.stderr | ||
object-safety-by-value-self-use.rs | ||
object-safety-by-value-self-use.stderr | ||
object-safety-by-value-self.rs | ||
object-safety-generics.curr.stderr | ||
object-safety-generics.object_safe_for_dispatch.stderr | ||
object-safety-generics.rs | ||
object-safety-issue-22040.rs | ||
object-safety-issue-22040.stderr | ||
object-safety-mentions-Self.curr.stderr | ||
object-safety-mentions-Self.object_safe_for_dispatch.stderr | ||
object-safety-mentions-Self.rs | ||
object-safety-no-static.curr.stderr | ||
object-safety-no-static.object_safe_for_dispatch.stderr | ||
object-safety-no-static.rs | ||
object-safety-phantom-fn.rs | ||
object-safety-sized-2.curr.stderr | ||
object-safety-sized-2.object_safe_for_dispatch.stderr | ||
object-safety-sized-2.rs | ||
object-safety-sized.curr.stderr | ||
object-safety-sized.object_safe_for_dispatch.stderr | ||
object-safety-sized.rs | ||
object-safety-supertrait-mentions-GAT.rs | ||
object-safety-supertrait-mentions-GAT.stderr | ||
object-safety-supertrait-mentions-Self.rs | ||
object-safety-supertrait-mentions-Self.stderr |