Skip to content

Fix/issue 152607 supertrait assoc type bound#156593

Open
spirali wants to merge 3 commits into
rust-lang:mainfrom
spirali:fix/issue-152607-supertrait-assoc-type-bound
Open

Fix/issue 152607 supertrait assoc type bound#156593
spirali wants to merge 3 commits into
rust-lang:mainfrom
spirali:fix/issue-152607-supertrait-assoc-type-bound

Conversation

@spirali
Copy link
Copy Markdown
Contributor

@spirali spirali commented May 15, 2026

This tries to fix #152607.
This PR is based on #153518.

  • I have added revisions for tests.
  • The original fix does not cover the dyn case, so I have tried to fix it on my own, but I am not sure about the correctness of this fix.

r? lcnr

akhilesharora and others added 3 commits May 14, 2026 17:00
…ormedness

When forming a trait object like `dyn Sub<Assoc = String>` where
`trait Sub: Super<Assoc: Copy>`, the compiler was not verifying that
`String: Copy`. This allowed unsound code to compile, potentially
leading to use-after-free vulnerabilities.

The root cause was that both the old and new trait solvers used
`explicit_super_predicates_of` which only yields `Self: SuperTrait`
predicates, but not the associated type bounds from those supertraits.
For example, `trait Sub: Super<Assoc: Copy>` expands to both
`Self: Super` and `<Self as Super>::Assoc: Copy`, but only the first
was being checked.

This change switches to `explicit_implied_predicates_of` in both:
- The old solver's `confirm_object_candidate`
- The new solver's `predicates_for_object_candidate`

This ensures that associated type bounds from supertraits are properly
verified when constructing trait objects.
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 15, 2026

changes to the core type system

cc @lcnr

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels May 15, 2026
@rust-log-analyzer
Copy link
Copy Markdown
Collaborator

The job pr-check-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
   |
30 |     parser: Box<dyn JsonLinesParser<T>>,
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |             |
   |             the parameter type `T` must be valid for the static lifetime...
   |             ...so that the type `(dyn JsonLinesParser<T> + 'static)` will meet its required lifetime bounds
   |
help: consider adding an explicit lifetime bound
   |
29 | struct CommandActor<T: 'static> {
   |                      +++++++++

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Associated type bound from supertrait isn't checked for trait object

5 participants