Skip to content

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

Open
Dnreikronos wants to merge 1 commit into
rust-lang:mainfrom
Dnreikronos:orphan_auto_trait_free_alias_expansion
Open

expand free alias types in the auto-trait orphan check#157835
Dnreikronos wants to merge 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
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.

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

5 participants