Skip to content

Conversation

@davidtwco
Copy link
Member

@davidtwco davidtwco commented Jun 19, 2025

Depends on #144064

Default sizedness bounds were not being added to explicit_super_predicates_of and explicit_implied_predicates_of which meant that a trait bound added to a associated type projection would be missing the implied predicate of the default sizedness supertrait of that trait.

An unexpected consequence of this change was that the check for multiple principals was now finding an additional MetaSized principal when eagerly expanding trait aliases - which is fixed by skipping MetaSized when elaborating trait aliases in lowering dyn TraitAlias.

@rustbot
Copy link
Collaborator

rustbot commented Jun 19, 2025

r? @petrochenkov

rustbot has assigned @petrochenkov.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Jun 19, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 19, 2025

HIR ty lowering was modified

cc @fmease

@rust-log-analyzer

This comment has been minimized.

@davidtwco
Copy link
Member Author

Wasn't expecting that failure, looking into it.

@davidtwco
Copy link
Member Author

davidtwco commented Jun 19, 2025

A smaller example of one of the failing crates (which happens with a stage two build):

#![crate_type = "lib"]

use std::marker::PhantomData;

pub trait ZeroMapKV<'a> {
    type Container;
}

pub trait ZeroFrom<'zf, C: ?Sized> {}

pub struct ZeroMap<'a, K: ZeroMapKV<'a>>(PhantomData<&'a K>);

impl<'zf, 's, K> ZeroFrom<'zf, ZeroMap<'s, K>> for ZeroMap<'zf, K>
where
    K: for<'b> ZeroMapKV<'b>,
    <K as ZeroMapKV<'zf>>::Container: ZeroFrom<'zf, <K as ZeroMapKV<'s>>::Container>,
{
}
error[E0308]: mismatched types
  --> f.rs:16:39
   |
16 |     <K as ZeroMapKV<'zf>>::Container: ZeroFrom<'zf, <K as ZeroMapKV<'s>>::Container>,
   |                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
   |
   = note: expected trait `<<K as ZeroMapKV<'s>>::Container as MetaSized>`
              found trait `<<K as ZeroMapKV<'zf>>::Container as MetaSized>`
note: the lifetime `'zf` as defined here...
  --> f.rs:13:6
   |
13 | impl<'zf, 's, K> ZeroFrom<'zf, ZeroMap<'s, K>> for ZeroMap<'zf, K>
   |      ^^^
note: ...does not necessarily outlive the lifetime `'s` as defined here
  --> f.rs:13:11
   |
13 | impl<'zf, 's, K> ZeroFrom<'zf, ZeroMap<'s, K>> for ZeroMap<'zf, K>
   |           ^^

error[E0308]: mismatched types
  --> f.rs:16:39
   |
16 |     <K as ZeroMapKV<'zf>>::Container: ZeroFrom<'zf, <K as ZeroMapKV<'s>>::Container>,
   |                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
   |
   = note: expected trait `<<K as ZeroMapKV<'s>>::Container as MetaSized>`
              found trait `<<K as ZeroMapKV<'zf>>::Container as MetaSized>`
note: the lifetime `'s` as defined here...
  --> f.rs:13:11
   |
13 | impl<'zf, 's, K> ZeroFrom<'zf, ZeroMap<'s, K>> for ZeroMap<'zf, K>
   |           ^^
note: ...does not necessarily outlive the lifetime `'zf` as defined here
  --> f.rs:13:6
   |
13 | impl<'zf, 's, K> ZeroFrom<'zf, ZeroMap<'s, K>> for ZeroMap<'zf, K>
   |      ^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.

@petrochenkov
Copy link
Contributor

r? types

@rustbot rustbot added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Jun 19, 2025
@rustbot rustbot assigned jackh726 and unassigned petrochenkov Jun 19, 2025
@compiler-errors
Copy link
Member

I'd like to think about this...

Can you remind me, is trait Foo {} actually trait Foo: MetaSized {}?

@davidtwco
Copy link
Member Author

I'd like to think about this...

Can you remind me, is trait Foo {} actually trait Foo: MetaSized {}?

Yes, it is

@compiler-errors
Copy link
Member

compiler-errors commented Jun 27, 2025

I think this highlights a problematic interaction with trait aliases, and I'm tempted to say that trait aliases should have their behavior reworked to stop expanding into their bounds in dyn types. This would, for example, also fix dyn TraitAlias when trait TraitAlias = A + B, but that's a bigger change to advocate for I guess.

FOr now, I think it's inconsistent to not add MetaSized to trait aliases but add them to traits, and I think instead, to preserve/fix the tests, we should probably filter out MetaSized when we elaborate trait aliases when lowering dyn TraitAlias. This behavior should probably be tagged with a FIXME though.

@davidtwco davidtwco force-pushed the sized-hierarchy-missing-default-bounds branch from 60d5044 to 7684842 Compare June 27, 2025 16:09
@davidtwco
Copy link
Member Author

I think this highlights a problematic interaction with trait aliases, and I'm tempted to say that trait aliases should have their behavior reworked to stop expanding into their bounds in dyn types. This would, for example, also fix dyn TraitAlias when trait TraitAlias = A + B, but that's a bigger change to advocate for I guess.

FOr now, I think it's inconsistent to not add MetaSized to trait aliases but add them to traits, and I think instead, to preserve/fix the tests, we should probably filter out MetaSized when we elaborate trait aliases when lowering dyn TraitAlias. This behavior should probably be tagged with a FIXME though.

Changed to this, thanks.


Still hitting the stage two failure, though I've added a UI test with my reproduction so that will fail first, not had much progress on working out what's going wrong with it.

@rust-log-analyzer

This comment has been minimized.

@davidtwco davidtwco force-pushed the sized-hierarchy-missing-default-bounds branch from 7684842 to eac7da1 Compare July 3, 2025 14:18
@davidtwco
Copy link
Member Author

See discussion on Zulip (#t-types > relaxing associated type bounds @ 💬) for background behind the last commit's changes.

davidtwco added a commit to davidtwco/rust that referenced this pull request Jul 3, 2025
@davidtwco
Copy link
Member Author

@bors try

@bors
Copy link
Collaborator

bors commented Jul 7, 2025

⌛ Trying commit eac7da1 with merge 7df376b...

bors added a commit that referenced this pull request Jul 7, 2025
…nds, r=<try>

hir_analysis: add missing sizedness bounds

Default sizedness bounds were not being added to `explicit_super_predicates_of` and `explicit_implied_predicates_of` which meant that a trait bound added to a associated type projection would be missing the implied predicate of the default sizedness supertrait of that trait.

An unexpected consequence of this change was that the check for multiple principals was now finding an additional `MetaSized` principal when eagerly expanding trait aliases - this required modifying lowering to no longer add default bounds to trait aliases.
@bors
Copy link
Collaborator

bors commented Jul 7, 2025

☀️ Try build successful - checks-actions
Build commit: 7df376b (7df376b035b3d12ff0386ad8b45b76dbe020257b)

@davidtwco
Copy link
Member Author

@craterbot check

@davidtwco davidtwco force-pushed the sized-hierarchy-missing-default-bounds branch from fde350a to 3901931 Compare October 16, 2025 09:23
@davidtwco davidtwco marked this pull request as ready for review October 16, 2025 09:24
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 16, 2025
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Oct 18, 2025
…, r=lcnr

prefer alias candidates for sizedness + auto trait goals

Fixes rust-lang/rust#143992

- abd07dec44437554520453f929c2b12d4eb8b11e: Reverts rust-lang/rust#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
- 90e61db9745f53d9aef21e3ebce0df19cc1389d7: 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
- e412062171925d0b40fdbeb5765c45087bdf0fe7: 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:

- `tests/ui/extern/extern-types-size_of_val.rs`
    - Previously passing, but only because of rust-lang/rust#144016, now correctly errors
- `tests/ui/sized-hierarchy/incomplete-inference-issue-143992.rs`
    - Previously failing on next solver, only because rust-lang/rust#144016 only applied to the old solver, passing now with 90e61db9745f53d9aef21e3ebce0df19cc1389d7
- `tests/ui/sized-hierarchy/overflow.rs`
    - Previously passing, but only because of rust-lang/rust#144016, now correctly errors
- `tests/ui/generic-associated-types/issue-92096.rs`
    - Previously passing, due to e412062171925d0b40fdbeb5765c45087bdf0fe7
    - Fails to prove `C::Connecting<'placeholder>: Send` which is required when proving that the generator is `Send`. This is an instance of rust-lang/rust#110338.
- `tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.rs`
    - Previously passing, now failing in the next solver, due to 03e0fdab6196e81b44356f42f03b6a0a224cf451
    - Expected that this test now fails as ambigious, see [Zulip](https://rust-lang.zulipchat.com/#narrow/channel/144729-t-types/topic/sizedness.20bounds.20in.20explicit_implied_predicates_of.20.28.23142712.29/near/526987384)

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

r? `@lcnr`
cc rust-lang/rust#142712 (this extracts part of that change)
@bors

This comment was marked as resolved.

@davidtwco davidtwco force-pushed the sized-hierarchy-missing-default-bounds branch from 3901931 to c4cf6ba Compare October 21, 2025 10:57
@rustbot

This comment has been minimized.

@davidtwco davidtwco force-pushed the sized-hierarchy-missing-default-bounds branch from c4cf6ba to 4440b69 Compare October 21, 2025 11:00
Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

final nits, then r=me

View changes since this review

Default sizedness bounds were not being added to
`explicit_super_predicates_of` and `explicit_implied_predicates_of`
which meant that a trait bound added to a associated type projection
would be missing the implied predicate of the default sizedness
supertrait of that trait.

An unexpected consequence of this change was that the check for multiple
principals was now finding an additional `MetaSized` principal when
eagerly expanding trait aliases. Instead of special-casing trait aliases
as different from traits and not adding a `MetaSized` supertrait to trait
aliases, filter out `MetaSized` when lowering `dyn Trait`.
@davidtwco davidtwco force-pushed the sized-hierarchy-missing-default-bounds branch from 4440b69 to 82a4049 Compare October 24, 2025 14:28
@rustbot
Copy link
Collaborator

rustbot commented Oct 24, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@davidtwco
Copy link
Member Author

@bors r=lcnr

@bors
Copy link
Collaborator

bors commented Oct 24, 2025

📌 Commit 82a4049 has been approved by lcnr

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 24, 2025
@bors
Copy link
Collaborator

bors commented Oct 24, 2025

⌛ Testing commit 82a4049 with merge f435972...

@bors
Copy link
Collaborator

bors commented Oct 25, 2025

☀️ Test successful - checks-actions
Approved by: lcnr
Pushing f435972 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Oct 25, 2025
@bors bors merged commit f435972 into rust-lang:master Oct 25, 2025
12 checks passed
@rustbot rustbot added this to the 1.92.0 milestone Oct 25, 2025
@github-actions
Copy link
Contributor

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 2aaa62b (parent) -> f435972 (this PR)

Test differences

Show 10 test diffs

Stage 1

  • [ui] tests/ui/sized-hierarchy/bound-on-assoc-type-projection.rs: [missing] -> pass (J1)
  • [ui] tests/ui/sized-hierarchy/elaboration-simple.rs: [missing] -> pass (J1)
  • [ui] tests/ui/sized-hierarchy/trait-alias-elaboration.rs: [missing] -> pass (J1)

Stage 2

  • [ui] tests/ui/sized-hierarchy/bound-on-assoc-type-projection.rs: [missing] -> pass (J0)
  • [ui] tests/ui/sized-hierarchy/elaboration-simple.rs: [missing] -> pass (J0)
  • [ui] tests/ui/sized-hierarchy/trait-alias-elaboration.rs: [missing] -> pass (J0)

Additionally, 4 doctest diffs were found. These are ignored, as they are noisy.

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard f435972085b697a1ece8ee6a1ac76efff8d1df7b --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. pr-check-1: 1906.0s -> 1450.5s (-23.9%)
  2. x86_64-gnu-llvm-20-1: 3860.5s -> 3057.2s (-20.8%)
  3. i686-gnu-nopt-1: 8086.4s -> 6853.6s (-15.2%)
  4. i686-gnu-1: 8231.8s -> 7004.7s (-14.9%)
  5. dist-apple-various: 3589.4s -> 3058.1s (-14.8%)
  6. x86_64-gnu-llvm-20: 2808.3s -> 2409.8s (-14.2%)
  7. dist-powerpc64le-linux-musl: 5759.8s -> 6551.3s (13.7%)
  8. i686-gnu-2: 6243.6s -> 5461.7s (-12.5%)
  9. x86_64-gnu-gcc: 3525.8s -> 3107.3s (-11.9%)
  10. x86_64-rust-for-linux: 2903.0s -> 2575.0s (-11.3%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (f435972): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.8% [0.1%, 3.6%] 72
Regressions ❌
(secondary)
0.5% [0.0%, 1.6%] 63
Improvements ✅
(primary)
-0.1% [-0.1%, -0.1%] 1
Improvements ✅
(secondary)
-0.3% [-0.4%, -0.1%] 23
All ❌✅ (primary) 0.8% [-0.1%, 3.6%] 73

Max RSS (memory usage)

Results (primary 0.4%, secondary -0.5%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
1.7% [0.7%, 2.6%] 2
Regressions ❌
(secondary)
1.0% [0.7%, 1.3%] 2
Improvements ✅
(primary)
-2.3% [-2.3%, -2.3%] 1
Improvements ✅
(secondary)
-3.6% [-3.6%, -3.6%] 1
All ❌✅ (primary) 0.4% [-2.3%, 2.6%] 3

Cycles

Results (primary 2.4%, secondary 2.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.4% [2.0%, 2.5%] 7
Regressions ❌
(secondary)
2.9% [1.1%, 3.5%] 8
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-5.3% [-5.3%, -5.3%] 1
All ❌✅ (primary) 2.4% [2.0%, 2.5%] 7

Binary size

Results (primary 0.3%, secondary 0.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.3% [0.0%, 1.4%] 69
Regressions ❌
(secondary)
0.1% [0.1%, 0.2%] 10
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.0% [-0.0%, -0.0%] 1
All ❌✅ (primary) 0.3% [0.0%, 1.4%] 69

Bootstrap: 475.049s -> 474.979s (-0.01%)
Artifact size: 390.50 MiB -> 390.46 MiB (-0.01%)

@rustbot rustbot added the perf-regression Performance regression. label Oct 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.