Skip to content

Fix bound var resolution for trait aliases#152309

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
rynewang:fix/ice-152158-rtn-trait-alias
Feb 8, 2026
Merged

Fix bound var resolution for trait aliases#152309
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
rynewang:fix/ice-152158-rtn-trait-alias

Conversation

@rynewang
Copy link
Contributor

@rynewang rynewang commented Feb 7, 2026

Fixes #152158
Fixes #152244

@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. labels Feb 7, 2026
@rustbot

This comment was marked as outdated.

@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rynewang rynewang force-pushed the fix/ice-152158-rtn-trait-alias branch 2 times, most recently from 78141c3 to 6c244da Compare February 7, 2026 20:03
@fmease
Copy link
Member

fmease commented Feb 7, 2026

r? me

@rustbot rustbot assigned fmease and unassigned nnethercote Feb 7, 2026
Copy link
Member

@fmease fmease left a comment

Choose a reason for hiding this comment

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

Preliminary notes.

View changes since this review

Copy link
Member

Choose a reason for hiding this comment

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

Your simple patch does seem to fix #152244, too. I didn't expect it to be that simple… I'm still gonna investigate a bit more whether it truly fixes the reported issue at its core.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, now I see. I've missed that supertrait_hrtb_vars uses explicit_supertraits_containing_assoc_item under the hood which "expands" / deals with trait aliases just fine.

| DefKind::TyAlias
| DefKind::Trait,
| DefKind::Trait
| DefKind::TraitAlias,
Copy link
Member

@fmease fmease Feb 7, 2026

Choose a reason for hiding this comment

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

Adding TraitAlias to this list does constitute a behavioral change. Namely, it affects trait object lifetime defaulting. Namely, it makes trait alias refs eligible containers which would sort of fix #140710, too, except that there's still the same off-by-one error that would be fixed by my PR #129543.

I want to leave that error in for now since I hope that that PR will go into FCP soon. It just means that your PR leads us to reject certain programs that use the unstable feature trait_alias. E.g., it'll reject:

trait Trait<'a, T: ?Sized + 'a> = std::fmt::Debug;

type X<'r> = dyn Trait<'r, dyn std::fmt::Debug>;

That's fine by me. I'll get fixed by me soon anyway 🤞

@rynewang rynewang force-pushed the fix/ice-152158-rtn-trait-alias branch from 6c244da to 867b1a8 Compare February 7, 2026 22:18
Copy link
Member

@fmease fmease left a comment

Choose a reason for hiding this comment

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

Thanks! Could you please

  1. also add Fixes #152244 to the PR description
  2. generalize the PR title as it actually fixes the RBV trait alias issue as a whole (not just for RTNs but for all assoc item kinds)
  3. add the two reproducers from #152244 as test cases
  4. basically remove all sections from the PR description (Summary + Problem + Root Cause + Fix) and only leave the two Fixes #NNN
    • currently, the whole description is extremely verbose and its contents self-evident from the patch

Regarding (3), I'm thinking of something like

// Check that we're successfully collecting bound vars behind trait aliases.
// Regression test for <https://github.com/rust-lang/rust/issues/152244>.
//@ check-pass
//@ needs-rustc-debug-assertions
#![feature(trait_alias)]

trait A<'a> { type X; }
trait B: for<'a> A<'a> {}
trait C = B;

fn f<T>() where T: C<X: Copy> {}
fn g<T>() where T: C<X: for<'r> A<'r>> {}

Re. #140710, while your PR does render trait aliases eligible containers wrt. trait object lifetime defaulting (which the linked issue requests), it ultimately doesn't fix the provided snippet due to the preexisting off-by-one error that'll be fixed by me in #129543. Therefore, let's keep that open, I'll update it once this PR is merged and add the actual regression tests to PR #129543.

View changes since this review

@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 7, 2026
@rynewang rynewang force-pushed the fix/ice-152158-rtn-trait-alias branch from 867b1a8 to 9433d7b Compare February 7, 2026 23:05
@rynewang rynewang changed the title Fix ICE when using return type notation through trait alias Fix bound var resolution for trait aliases Feb 7, 2026
@rynewang
Copy link
Contributor Author

rynewang commented Feb 7, 2026

Updated PR description and title, fixed repro format and added new repro.

@fmease
Copy link
Member

fmease commented Feb 7, 2026

(You've linked to the wrong PRs but I've fixed it myself)

@bors r+ rollup

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 7, 2026

📌 Commit 9433d7b has been approved by fmease

It is now in the queue for this repository.

@rust-bors rust-bors bot 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 7, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 7, 2026
…alias, r=fmease

Fix bound var resolution for trait aliases

Fixes rust-lang#152158
Fixes rust-lang#152244
@rust-log-analyzer

This comment has been minimized.

@fmease
Copy link
Member

fmease commented Feb 7, 2026

Ah, my bad. The new test needs a fn main() {}

@bors r-

@rust-bors rust-bors bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 7, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 7, 2026

Commit 9433d7b has been unapproved.

This PR was contained in a rollup (#152312), which was also unapproved.

Handle DefKind::TraitAlias in resolve_bound_vars so that associated
item constraints and return type notation work through trait aliases.
@rynewang rynewang force-pushed the fix/ice-152158-rtn-trait-alias branch from 9433d7b to 7c5ea7f Compare February 8, 2026 02:43
@fmease
Copy link
Member

fmease commented Feb 8, 2026

@bors r+

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 8, 2026

📌 Commit 7c5ea7f has been approved by fmease

It is now in the queue for this repository.

@rust-bors rust-bors bot 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 8, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 8, 2026
…alias, r=fmease

Fix bound var resolution for trait aliases

Fixes rust-lang#152158
Fixes rust-lang#152244
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 8, 2026
…alias, r=fmease

Fix bound var resolution for trait aliases

Fixes rust-lang#152158
Fixes rust-lang#152244
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 8, 2026
…alias, r=fmease

Fix bound var resolution for trait aliases

Fixes rust-lang#152158
Fixes rust-lang#152244
rust-bors bot pushed a commit that referenced this pull request Feb 8, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - #151455 (Fix `SourceFile::normalized_byte_pos`)
 - #152250 (Remove support for slugs in diagnostic messages)
 - #152322 (Replace some `feature(core_intrinsics)` with stable hints)
 - #152328 (Fix a few diagnostics)
 - #151640 (Cleanup offload datatransfer)
 - #152212 (Port some attributes to the attr parser)
 - #152309 (Fix bound var resolution for trait aliases)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 8, 2026
…alias, r=fmease

Fix bound var resolution for trait aliases

Fixes rust-lang#152158
Fixes rust-lang#152244
rust-bors bot pushed a commit that referenced this pull request Feb 8, 2026
…uwer

Rollup of 8 pull requests

Successful merges:

 - #151455 (Fix `SourceFile::normalized_byte_pos`)
 - #152250 (Remove support for slugs in diagnostic messages)
 - #152322 (Replace some `feature(core_intrinsics)` with stable hints)
 - #151640 (Cleanup offload datatransfer)
 - #152212 (Port some attributes to the attr parser)
 - #152309 (Fix bound var resolution for trait aliases)
 - #152339 (diagnostics: fix ICE in closure signature mismatch)
 - #152341 (`cfg_select!`: allow optional comma after `{ /* ... */ }`)
rust-bors bot pushed a commit that referenced this pull request Feb 8, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - #151455 (Fix `SourceFile::normalized_byte_pos`)
 - #152250 (Remove support for slugs in diagnostic messages)
 - #152322 (Replace some `feature(core_intrinsics)` with stable hints)
 - #152328 (Fix a few diagnostics)
 - #151640 (Cleanup offload datatransfer)
 - #152212 (Port some attributes to the attr parser)
 - #152309 (Fix bound var resolution for trait aliases)
 - #152339 (diagnostics: fix ICE in closure signature mismatch)
 - #152341 (`cfg_select!`: allow optional comma after `{ /* ... */ }`)
@rust-bors rust-bors bot merged commit 6521fcf into rust-lang:main Feb 8, 2026
11 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Feb 8, 2026
rust-timer added a commit that referenced this pull request Feb 8, 2026
Rollup merge of #152309 - rynewang:fix/ice-152158-rtn-trait-alias, r=fmease

Fix bound var resolution for trait aliases

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

Labels

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.

Projects

None yet

5 participants