Skip to content

Fix for implementing built-in traits for checked alias types - #158707

Draft
josetorrs wants to merge 13 commits into
rust-lang:mainfrom
josetorrs:fix-copy-drop-trait-for-alias-types
Draft

josetorrs wants to merge 13 commits into
rust-lang:mainfrom
josetorrs:fix-copy-drop-trait-for-alias-types

Conversation

@josetorrs

@josetorrs josetorrs commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #157755
Fixes #159264

r? @fmease

@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 Jul 2, 2026
@rust-log-analyzer

This comment has been minimized.

@fmease fmease added the F-checked_type_aliases `#![feature(checked_type_aliases)]` (formerly: `lazy_type_alias`) label Sep 19, 2026
@fmease

fmease commented Oct 23, 2026

Copy link
Copy Markdown
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

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

Fix for implementing copy and drop trait for free alias types
@rust-bors

This comment has been minimized.

@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.

I'm so sorry for the delay! Thanks for working on this!

View changes since this review

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.

Issue #157755 doesn't only concern Copy & Drop, those were only the ones I mentioned. I'm relatively sure that most if not all traits listed in rustc_hir_analysis::coherence::builtin::check_trait don't work well with free alias types.

At the time of writing that function checks Drop, AsyncDrop, Copy, Unpin, ConstParamTy, CoerceUnpin, Reborrow, CoerceShared, DispatchFromDyn, CoercePointeeValidated. Note that maybe we don't need to expand_free_alias_tys for all of them, needs investigation, maybe they already normalize the self type or we shouldn't expand for whatever reason..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Small update but yeah I went through a few of them just now and got the ICE in #159264. I'll go through the others and investigate in the coming days

@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 Oct 23, 2026
@rust-bors

rust-bors Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 4db5f4d (4db5f4d859dbd83749a296d74009f450d08984e5)
Base parent: fe2b43d (fe2b43dd212769ef40ae2e32e5c5f5364642b82b)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown

Finished benchmarking commit (4db5f4d): comparison URL.

Overall result: ✅ improvements - no action needed

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

@bors rollup=iffy rustc-perf
@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
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.2% [-0.4%, -0.0%] 11
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary 0.5%, secondary 1.3%)

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

mean range count
Regressions ❌
(primary)
0.7% [0.4%, 1.3%] 4
Regressions ❌
(secondary)
1.3% [0.4%, 7.0%] 9
Improvements ✅
(primary)
-0.7% [-0.7%, -0.7%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.5% [-0.7%, 1.3%] 5

Cycles

Results (primary 0.1%, 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)
0.9% [0.4%, 2.0%] 10
Regressions ❌
(secondary)
0.8% [0.4%, 1.5%] 6
Improvements ✅
(primary)
-0.9% [-1.7%, -0.5%] 9
Improvements ✅
(secondary)
-1.4% [-1.4%, -1.4%] 1
All ❌✅ (primary) 0.1% [-1.7%, 2.0%] 19

Binary size

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

Bootstrap: 488.459s -> 488.836s (0.08%)
Artifact size: 406.24 MiB -> 406.31 MiB (0.02%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 23, 2026
@josetorrs
josetorrs force-pushed the fix-copy-drop-trait-for-alias-types branch from 9a6c2d7 to 91abb11 Compare October 30, 2026 03:13
@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@fmease fmease moved this to In Progress in Checked Type Aliases (CTA) Nov 12, 2026
@fmease fmease mentioned this pull request Nov 12, 2026
2 of 6 tasks
@josetorrs josetorrs changed the title Fix for implementing copy and drop trait for free alias types Fix for implementing built-in traits for checked alias types Nov 18, 2026
@josetorrs
josetorrs force-pushed the fix-copy-drop-trait-for-alias-types branch from b4f5ae8 to 230cd59 Compare November 19, 2026 19:17
@rustbot

rustbot commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main 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.

Comment on lines +36 to +37
pub struct AsyncDropLocal;
pub type AsyncDropAlias = AsyncDropLocal;

@josetorrs josetorrs Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried removing pub here and above to follow the rest of the file but I got the below error

Stack trace
warning: type alias `AsyncDropAlias` is more private than the item `<impl AsyncDrop for AsyncDropAlias>::drop`
  --> /rust/tests/ui/checked-type-aliases/builtin-trait-impls.rs:32:5
   |
LL |     async fn drop(self: Pin<&mut Self>) {}
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ method `<impl AsyncDrop for AsyncDropAlias>::drop` is reachable at visibility `pub`
   |
note: but type alias `AsyncDropAlias` is only usable at visibility `pub(crate)`
  --> /rust/tests/ui/checked-type-aliases/builtin-trait-impls.rs:29:1
   |
LL | type AsyncDropAlias = AsyncDropLocal;
   | ^^^^^^^^^^^^^^^^^^^
   = note: `#[warn(private_interfaces)]` on by default

which leads me to here but not sure if it's an issue

PrivateInterfacesOrBoundsLint {
item_span: span,
item_kind: self.tcx.def_descr(self.item_def_id.to_def_id()),
item_descr: (&LazyDefPathStr {
def_id: self.item_def_id.to_def_id(),
tcx: self.tcx,
})
.into(),
item_vis_descr: &reachable_at_vis.to_string(self.item_def_id, self.tcx),
ty_span: vis_span,
ty_kind: kind,
ty_descr: descr.into(),
ty_vis_descr: &vis.to_string(local_def_id, self.tcx),

View changes since the review

@josetorrs
josetorrs marked this pull request as draft November 19, 2026 20:30

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-checked_type_aliases `#![feature(checked_type_aliases)]` (formerly: `lazy_type_alias`) S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

Status: In Progress

5 participants