Skip to content

trait_sel: sizedness goals prefer alias candidates #144064

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

davidtwco
Copy link
Member

@davidtwco davidtwco commented Jul 17, 2025

Fixes #143992

  • abd07de: Reverts trait_sel: MetaSized always holds temporarily #144016 so that MetaSized bounds are checked properly, and updates all the tests accordingly, including making tests/ui/sized-hierarchy/incomplete-inference-issue-143992.rs fail when it shouldn't
  • 90e61db: Prefer alias candidates over parameter environment candidates for sizedness, auto and default traits. tests/ui/sized-hierarchy/incomplete-inference-issue-143992.rs passes again, but tests/ui/generic-associated-types/issue-93262.rs starts failing when it shouldn't
  • e412062: No longer require that predicates of aliases hold in well-formedness checking of the alias. tests/ui/generic-associated-types/issue-93262.rs passes again

Each commit updates all the tests to their new output so it should be easy enough to see what the impact of each change individually is. After all of the changes, tests that pass when they didn't before or vice versa:

This had a crater run in #142712 (comment) alongside some other changes.

r? @lcnr
cc #142712 (this extracts part of that change)

@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 Jul 17, 2025
@rustbot

This comment has been minimized.

@davidtwco davidtwco added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Jul 17, 2025
For sizedness, default and auto trait predicates, now prefer non-param
candidates if any exist. As these traits do not have generic parameters,
it never makes sense to prefer an non-alias candidate, as there can
never be a more permissive candidate.
No longer require that we prove that the predicates of aliases hold when
checking the well-formedness of the alias. This permits more uses of GATs
and changes the output of yet more tests.
@lcnr lcnr added beta-nominated Nominated for backporting to the compiler in the beta channel. and removed beta-nominated Nominated for backporting to the compiler in the beta channel. labels Jul 17, 2025
@lcnr
Copy link
Contributor

lcnr commented Jul 17, 2025

wrt 6aa3732 it's not that we stop to normalize the predicates of projections, it's that when comfirming alias-bound/Projection candidates, we required that the alias is well-formed. While we need to normalize these obligations before proving them, the normalize isn't the relevant part, the "we need to prove them at all" is.

wrt tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.rs see https://rust-lang.zulipchat.com/#narrow/channel/144729-t-types/topic/sizedness.20bounds.20in.20explicit_implied_predicates_of.20.28.23142712.29/near/526987384. It's intended that this test changes to be ambiguous.

tests/ui/generic-associated-types/issue-92096.rs fails to prove C::Connecting<'placeholder>: Send which is required when proving that the generator is Send. This is 'just' an instance of #110338

Did you already crater run this behavior?

Comment on lines 477 to 479
let is_sizedness_or_auto_or_default_predicate = self.tcx().is_sizedness_trait(did)
|| self.tcx().trait_is_auto(did)
|| self.tcx().is_default_trait(did);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dislike this as is 🤔 maybe have a shared used by both old and new solver (with comments)

enum CandidatePreferenceMode {
    Default,
    Marker,
}

impl CandidatePreferenceMode {
    fn compute<I: Interner>(cx: I, trait_def_id: I::DefId) -> CandidatePreferenceMode;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this, introduced a CandidatePreferenceMode and used it in both solvers

@davidtwco
Copy link
Member Author

Did you already crater run this behavior?

We did a crater run in #142712 (comment), which had all of these changes and included implying MetaSized on associated types.

@davidtwco davidtwco force-pushed the prefer-alias-over-env-for-sizedness branch from 6aa3732 to e412062 Compare July 17, 2025 13:02
@davidtwco
Copy link
Member Author

Updated the README and corrected the descriptions of everything per your comment

davidtwco added a commit to davidtwco/rust that referenced this pull request Jul 17, 2025
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. T-types Relevant to the types 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.

where bounds regression in beta+nightly
3 participants