Skip to content

expand free alias types in the auto-trait orphan check#157835

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Dnreikronos:orphan_auto_trait_free_alias_expansion
Jul 5, 2026
Merged

expand free alias types in the auto-trait orphan check#157835
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Dnreikronos:orphan_auto_trait_free_alias_expansion

Conversation

@Dnreikronos

@Dnreikronos Dnreikronos commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

fixes #157756.

auto-trait impls are only allowed on nominal types. the check for that looked at the self type as written, without expanding it, so a lazy type alias got rejected even when it pointed straight at a type that's fine on its own:

#![feature(lazy_type_alias)]
struct Local;
type Alias = Local;
unsafe impl Sync for Alias {} // used to be E0321

the locality check right above it already normalizes the self type, so the two were looking at different things. imo the cleanest fix is to expand free aliases first, with the same expand_free_alias_tys coherence already calls in a couple of other spots. anything that should still be rejected (trait objects, opaque types, bare type params) survives the expansion and errors like before.

one thing worth a second look: impl_for_weak_alias.rs used type Alias = (impl Sized, u8) and expected an error. idk if that was deliberate, but the alias expands to a tuple, and a tuple is fine for a local auto trait if you write it by hand, so it passes now and i made it check-pass. lmk if i'm missing why it should still be rejected.

The auto-trait branch of the orphan check inspected the unexpanded self
type, so an impl whose self type was a free (lazy) type alias was
rejected even when the alias resolved to an otherwise valid nominal
type, e.g. `unsafe impl Sync for Alias {}` with `type Alias = Local;`.

Expand free alias types before classifying the self type, mirroring the
locality check above. Expansion still reveals genuinely problematic self
types (trait objects, opaque types, type parameters), so those keep
being rejected.
@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 Jun 12, 2026
@rustbot

rustbot commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 19 candidates

@fmease

fmease commented Jun 13, 2026

Copy link
Copy Markdown
Member

r? me

@rustbot rustbot assigned fmease and unassigned petrochenkov Jun 13, 2026
@fmease

fmease commented Jun 13, 2026

Copy link
Copy Markdown
Member

Shouldn't affect perf but better be certain:

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 13, 2026
rust-bors Bot pushed a commit that referenced this pull request Jun 13, 2026
…nsion, r=<try>

expand free alias types in the auto-trait orphan check
@rust-bors

rust-bors Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 7e108df (7e108df05a7548d79f478037d58030aca9dbaefe, parent: edff07ce1a97f3eb39d438852ace6c57dd97605e)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (7e108df): comparison URL.

Overall result: ❌ regressions - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@rustbot label: -S-waiting-on-perf -perf-regression

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
Regressions ❌
(secondary)
0.2% [0.2%, 0.2%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary 4.8%)

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

mean range count
Regressions ❌
(primary)
4.8% [4.6%, 5.0%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 4.8% [4.6%, 5.0%] 2

Cycles

Results (primary 1.6%, secondary 22.7%)

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

mean range count
Regressions ❌
(primary)
1.6% [1.0%, 2.2%] 2
Regressions ❌
(secondary)
22.7% [19.4%, 24.4%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.6% [1.0%, 2.2%] 2

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 519.155s -> 516.812s (-0.45%)
Artifact size: 400.88 MiB -> 401.47 MiB (0.15%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 13, 2026
@Dnreikronos

Copy link
Copy Markdown
Contributor Author

@fmease, wassup!
i need to do any adjustment here?
first time that i got this "perf" workflow here.

@fmease fmease left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! The perf regression looks spurious @bors r+

View changes since this review

@rust-bors

rust-bors Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

📌 Commit b2d604c has been approved by fmease

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 10. This pull request will be tested once the tree is reopened.

@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-review Status: Awaiting review from the assignee but also interested parties. labels Jul 3, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 3, 2026
…_alias_expansion, r=fmease

expand free alias types in the auto-trait orphan check

fixes rust-lang#157756.

auto-trait impls are only allowed on nominal types. the check for that looked at the self type as written, without expanding it, so a lazy type alias got rejected even when it pointed straight at a type that's fine on its own:

```rust
#![feature(lazy_type_alias)]
struct Local;
type Alias = Local;
unsafe impl Sync for Alias {} // used to be E0321
```

the locality check right above it already normalizes the self type, so the two were looking at different things. imo the cleanest fix is to expand free aliases first, with the same `expand_free_alias_tys` coherence already calls in a couple of other spots. anything that should still be rejected (trait objects, opaque types, bare type params) survives the expansion and errors like before.

one thing worth a second look: `impl_for_weak_alias.rs` used `type Alias = (impl Sized, u8)` and expected an error. idk if that was deliberate, but the alias expands to a tuple, and a tuple is fine for a local auto trait if you write it by hand, so it passes now and i made it check-pass. lmk if i'm missing why it should still be rejected.
rust-bors Bot pushed a commit that referenced this pull request Jul 5, 2026
Rollup of 18 pull requests

Successful merges:

 - #158692 (Add release notes for 1.96.1)
 - #134021 (Implement `IntoIterator` for `[&[mut]] Box<[T; N], A>`)
 - #152860 (Port the `without_debuginfo` test from `backtrace-rs` to the testsuite)
 - #155932 (MIR Call terminator: evaluate destination place before arguments)
 - #156777 (Add -Zautodiff_post_passes flag to limit which llvm passes to run after enzyme to make autodiff tests more robust)
 - #157151 (JSON target specs: remove 'x86-softfloat' compatibility alias)
 - #157835 (expand free alias types in the auto-trait orphan check)
 - #158377 (add `-Zforce-intrinsic-fallback` flag)
 - #158434 (delegation: refactor AST -> HIR lowering)
 - #158552 (make some tidy errors around python easier to understand)
 - #158624 (borrowck: Introduce BlameConstraint::to_obligation_cause_from_path())
 - #158704 (Optimize `ArrayChunks::try_rfold` with `DoubleEndedIterator::next_chunk_back`)
 - #158711 (library: Comment on libtest's dicey internal soundness)
 - #158539 (Move `SizeHint` and `IoHandle` to `core::io`)
 - #158659 (refactor the normalization in `coerce_shared_info`)
 - #158689 (resolver: don't use `Finalize` when resolving visibilities during AST expansion)
 - #158698 (Update TypeVisitable implementation)
 - #158706 (Tweaks to MIR building scope API)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 5, 2026
…_alias_expansion, r=fmease

expand free alias types in the auto-trait orphan check

fixes rust-lang#157756.

auto-trait impls are only allowed on nominal types. the check for that looked at the self type as written, without expanding it, so a lazy type alias got rejected even when it pointed straight at a type that's fine on its own:

```rust
#![feature(lazy_type_alias)]
struct Local;
type Alias = Local;
unsafe impl Sync for Alias {} // used to be E0321
```

the locality check right above it already normalizes the self type, so the two were looking at different things. imo the cleanest fix is to expand free aliases first, with the same `expand_free_alias_tys` coherence already calls in a couple of other spots. anything that should still be rejected (trait objects, opaque types, bare type params) survives the expansion and errors like before.

one thing worth a second look: `impl_for_weak_alias.rs` used `type Alias = (impl Sized, u8)` and expected an error. idk if that was deliberate, but the alias expands to a tuple, and a tuple is fine for a local auto trait if you write it by hand, so it passes now and i made it check-pass. lmk if i'm missing why it should still be rejected.
rust-bors Bot pushed a commit that referenced this pull request Jul 5, 2026
…uwer

Rollup of 20 pull requests

Successful merges:

 - #158692 (Add release notes for 1.96.1)
 - #134021 (Implement `IntoIterator` for `[&[mut]] Box<[T; N], A>`)
 - #155932 (MIR Call terminator: evaluate destination place before arguments)
 - #155989 (Update `transmute_copy` to ub_checks and `?Sized`)
 - #156777 (Add -Zautodiff_post_passes flag to limit which llvm passes to run after enzyme to make autodiff tests more robust)
 - #157151 (JSON target specs: remove 'x86-softfloat' compatibility alias)
 - #157835 (expand free alias types in the auto-trait orphan check)
 - #157857 (Stabilize `#[my_macro] mod foo;` (part of `proc_macro_hygiene`))
 - #158377 (add `-Zforce-intrinsic-fallback` flag)
 - #158434 (delegation: refactor AST -> HIR lowering)
 - #158552 (make some tidy errors around python easier to understand)
 - #158624 (borrowck: Introduce BlameConstraint::to_obligation_cause_from_path())
 - #158704 (Optimize `ArrayChunks::try_rfold` with `DoubleEndedIterator::next_chunk_back`)
 - #158711 (library: Comment on libtest's dicey internal soundness)
 - #158751 (rustdoc: Fix crash when trying to inline foreign item which cannot have attributes)
 - #158539 (Move `SizeHint` and `IoHandle` to `core::io`)
 - #158659 (refactor the normalization in `coerce_shared_info`)
 - #158689 (resolver: don't use `Finalize` when resolving visibilities during AST expansion)
 - #158698 (Update TypeVisitable implementation)
 - #158706 (Tweaks to MIR building scope API)
rust-bors Bot pushed a commit that referenced this pull request Jul 5, 2026
…uwer

Rollup of 19 pull requests

Successful merges:

 - #158692 (Add release notes for 1.96.1)
 - #134021 (Implement `IntoIterator` for `[&[mut]] Box<[T; N], A>`)
 - #155932 (MIR Call terminator: evaluate destination place before arguments)
 - #155989 (Update `transmute_copy` to ub_checks and `?Sized`)
 - #156777 (Add -Zautodiff_post_passes flag to limit which llvm passes to run after enzyme to make autodiff tests more robust)
 - #157151 (JSON target specs: remove 'x86-softfloat' compatibility alias)
 - #157835 (expand free alias types in the auto-trait orphan check)
 - #157857 (Stabilize `#[my_macro] mod foo;` (part of `proc_macro_hygiene`))
 - #158434 (delegation: refactor AST -> HIR lowering)
 - #158552 (make some tidy errors around python easier to understand)
 - #158624 (borrowck: Introduce BlameConstraint::to_obligation_cause_from_path())
 - #158704 (Optimize `ArrayChunks::try_rfold` with `DoubleEndedIterator::next_chunk_back`)
 - #158711 (library: Comment on libtest's dicey internal soundness)
 - #158751 (rustdoc: Fix crash when trying to inline foreign item which cannot have attributes)
 - #158539 (Move `SizeHint` and `IoHandle` to `core::io`)
 - #158659 (refactor the normalization in `coerce_shared_info`)
 - #158689 (resolver: don't use `Finalize` when resolving visibilities during AST expansion)
 - #158698 (Update TypeVisitable implementation)
 - #158706 (Tweaks to MIR building scope API)
@rust-bors rust-bors Bot merged commit 09300b8 into rust-lang:main Jul 5, 2026
13 checks passed
@rustbot rustbot added this to the 1.98.0 milestone Jul 5, 2026
rust-timer added a commit that referenced this pull request Jul 5, 2026
Rollup merge of #157835 - Dnreikronos:orphan_auto_trait_free_alias_expansion, r=fmease

expand free alias types in the auto-trait orphan check

fixes #157756.

auto-trait impls are only allowed on nominal types. the check for that looked at the self type as written, without expanding it, so a lazy type alias got rejected even when it pointed straight at a type that's fine on its own:

```rust
#![feature(lazy_type_alias)]
struct Local;
type Alias = Local;
unsafe impl Sync for Alias {} // used to be E0321
```

the locality check right above it already normalizes the self type, so the two were looking at different things. imo the cleanest fix is to expand free aliases first, with the same `expand_free_alias_tys` coherence already calls in a couple of other spots. anything that should still be rejected (trait objects, opaque types, bare type params) survives the expansion and errors like before.

one thing worth a second look: `impl_for_weak_alias.rs` used `type Alias = (impl Sized, u8)` and expected an error. idk if that was deliberate, but the alias expands to a tuple, and a tuple is fine for a local auto trait if you write it by hand, so it passes now and i made it check-pass. lmk if i'm missing why it should still be rejected.
@theemathas theemathas modified the milestones: 1.98.0, 1.99.0 Jul 6, 2026
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

Development

Successfully merging this pull request may close these issues.

Cannot impl auto traits for free alias types that expand to otherwise legal self type

6 participants