Skip to content

Allow associated const equality constraints with GCA - #159506

Merged
rust-bors[bot] merged 9 commits into
rust-lang:mainfrom
bit-aloo:2026-07-14-dyn-compatible-non-typeconsts-in-GCA
Aug 6, 2026
Merged

Allow associated const equality constraints with GCA#159506
rust-bors[bot] merged 9 commits into
rust-lang:mainfrom
bit-aloo:2026-07-14-dyn-compatible-non-typeconsts-in-GCA

Conversation

@bit-aloo

@bit-aloo bit-aloo commented Jul 18, 2026

Copy link
Copy Markdown
Member

@rustbot

rustbot commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

HIR ty lowering was modified

cc @fmease

Some changes occurred in compiler/rustc_sanitizers

cc @rcvalle

@rustbot rustbot added PG-exploit-mitigations Project group: Exploit mitigations 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 18, 2026
@rustbot

rustbot commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

BoxyUwU is currently at their maximum review capacity.
They may take a while to respond.

Comment thread compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_trait.rs Outdated
if !tcx.generics_of(item.def_id).is_own_empty() {
errors.push(AssocConstViolation::Generic);
} else if !is_type_const {
errors.push(AssocConstViolation::NonType);

@fmease fmease Jul 18, 2026

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.

Isn't NonType now dead code and can be removed?

View changes since the review

@bit-aloo bit-aloo Jul 20, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks, removed here: b464ecb, we need this for mgca, reverted the removal

Comment thread compiler/rustc_middle/src/ty/assoc.rs
.filter(|item| item.is_type() || item.is_type_const())
// Only associated items that support equality constraints can
// be constrained in a trait object type via a binding.
.filter(|item| item.can_have_equality_constraint(tcx))

@fmease fmease Jul 18, 2026

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.

Note that this change means that stabilizing mGCA will break stable code like tests/ui/type-alias/lack-of-wfcheck.rs.

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

does that mean we can't stablize this? not sure how to go about this..

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.

this change is supposed to be for generic_const_args not min_generic_const_args since mgca doesn't support const items in the type system but full GCA does. once you change that this'll go back to mgca being backwards compatible but with GCA being backwards incompatible (which is OK)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah! thanks, my bad 🥲 . Just made changes specific to GCA

@bit-aloo
bit-aloo requested a review from fmease July 20, 2026 14:01
@bit-aloo bit-aloo changed the title Allow associated const equality constraints with MGCA Allow associated const equality constraints with GCA Jul 21, 2026
@bit-aloo
bit-aloo requested a review from BoxyUwU July 22, 2026 02:45
if !tcx.generics_of(item.def_id).is_own_empty() {
errors.push(AssocConstViolation::Generic);
} else if !is_type_const {
} else if !is_type_const && !tcx.features().generic_const_args() {

@BoxyUwU BoxyUwU Jul 22, 2026

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.

@fmease do you know if you added a test that type const FOO<const N: usize> makes a trait dyn incompatible? (because its a GAT)

regardless, @Shourya742 can you add a test that cosnt ASSOC<const N: usize>: usize makes a trait dyn incompatible under feature(generic_const_args)

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added here: 6497008

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

hell yeah :) very cool thx for working on this. no worries about the mgca vs gca mixup, the feature names are confusing ✨

View changes since this review

@BoxyUwU

BoxyUwU commented Jul 22, 2026

Copy link
Copy Markdown
Member

Ah can you also add a variant of tests/ui/type-alias/lack-of-wfcheck.rs that breaks when generic_const_args is enabled so that it's obvious that this is a breaking change ✨

@BoxyUwU

BoxyUwU commented Jul 22, 2026

Copy link
Copy Markdown
Member

@rustbot author

@rustbot rustbot 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 Jul 22, 2026
@rust-cloud-vms
rust-cloud-vms Bot force-pushed the 2026-07-14-dyn-compatible-non-typeconsts-in-GCA branch from 79271ed to 0e7d4e2 Compare July 23, 2026 12:58
@bit-aloo

Copy link
Copy Markdown
Member Author

[0e7d4e2](/rust-lang/rust/pull/159506/commits/0e7d4e2819cf01929968701e9c6af6f7e12afa4b)

Added here: 0e7d4e2

@bit-aloo
bit-aloo requested a review from BoxyUwU July 23, 2026 12:59
@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 Jul 23, 2026

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

test looks good just some nits about it

View changes since this review


// * dyn incompatible due to GAT
// * `'a: 'static`, `String: Copy` and `[u8]: Sized` unsatisfied, `loop {}` diverging
type Several<'a> = dyn HasGenericAssocType<Type<'a, String, { loop {} }> = [u8]>;

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.

can you split this into a separate test, it's also not actually showing an error right now

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added the variant for this, here: 2191fc1


type DynIncompat0 = dyn Sized; // `Sized` axiomatically dyn incompatible
// issue: <https://github.com/rust-lang/rust/issues/153731>
type DynIncompat1 = dyn HasAssocConst;

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.

this part of the test would ideally be revisioned so that it shows the behaviour with and without generic_const_args enabled :3 (to demonstrate the breaking nature of stabilization)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

TIL, we have this pretty cool thing called revisions that helps feature gate compile tests, so I used it here. Added in 2191fc1.

@rust-cloud-vms
rust-cloud-vms Bot force-pushed the 2026-07-14-dyn-compatible-non-typeconsts-in-GCA branch from 0e7d4e2 to 2191fc1 Compare July 25, 2026 06:23
@bit-aloo
bit-aloo requested a review from BoxyUwU July 25, 2026 06:28
@BoxyUwU

BoxyUwU commented Aug 6, 2026

Copy link
Copy Markdown
Member

@bors r+

@rust-bors

rust-bors Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 2191fc1 has been approved by BoxyUwU

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-review Status: Awaiting review from the assignee but also interested parties. labels Aug 6, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 6, 2026
…-non-typeconsts-in-GCA, r=BoxyUwU

Allow associated const equality constraints with GCA

closes: rust-lang/project-const-generics#77

r? @BoxyUwU
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 6, 2026
…-non-typeconsts-in-GCA, r=BoxyUwU

Allow associated const equality constraints with GCA

closes: rust-lang/project-const-generics#77

r? @BoxyUwU
rust-bors Bot pushed a commit that referenced this pull request Aug 6, 2026
…uwer

Rollup of 17 pull requests

Successful merges:

 - #159530 (Cap socket send length to c_int::MAX on Apple targets)
 - #159506 (Allow associated const equality constraints with GCA)
 - #160006 (Account for desugaring in method call move errors)
 - #160415 (Split `aarch64-apple{,-macos-26}` => `aarch64-apple{,-macos-26}-{1,2}` jobs)
 - #160464 (fix: Check the fallback map before queueing child in `visible_parent_map` breadth-first search)
 - #160555 (Split `apply_primary_terminator_effect`)
 - #160592 (Suggest if-let chain continuation on unclosed delimiter)
 - #160600 (Avoid the std DLL copy alongside rustc)
 - #160156 (check_consts: exhaustively match on CastKind)
 - #160211 (Rename `#[unroll]` => `#[rustc_unroll]` to mitigate nameres ambiguity)
 - #160304 (Add tests for fixed new solver issues)
 - #160398 (rustc_abi: Add `LayoutData::is_variant_uninhabited` method)
 - #160546 (Update error message in documentation comments)
 - #160568 (Use `VisitorResult` helper macros)
 - #160571 (Add regression test for array type recovery in generic arguments)
 - #160588 (add a test showing polonius alpha is not a subset of datalog polonius)
 - #160617 (Add a suggestion to MissingUnsafeOnExtern diagnostic)
@rust-bors
rust-bors Bot merged commit 237d7aa into rust-lang:main Aug 6, 2026
13 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Aug 6, 2026
rust-timer added a commit that referenced this pull request Aug 6, 2026
Rollup merge of #159506 - bit-aloo:2026-07-14-dyn-compatible-non-typeconsts-in-GCA, r=BoxyUwU

Allow associated const equality constraints with GCA

closes: rust-lang/project-const-generics#77

r? @BoxyUwU
@bit-aloo
bit-aloo deleted the 2026-07-14-dyn-compatible-non-typeconsts-in-GCA branch August 6, 2026 14:42
@JonathanBrouwer

Copy link
Copy Markdown
Contributor

@rust-timer build e1373c7

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (e1373c7): 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.

@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.4% [-0.5%, -0.2%] 6
All ❌✅ (primary) - - 0

Max RSS (memory usage)

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

Cycles

Results (primary 2.3%, secondary -5.3%)

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

mean range count
Regressions ❌
(primary)
2.3% [2.2%, 2.5%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-5.3% [-5.3%, -5.3%] 1
All ❌✅ (primary) 2.3% [2.2%, 2.5%] 2

Binary size

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

Bootstrap: 458.35s -> 474.78s (3.58%)
Artifact size: 398.64 MiB -> 398.61 MiB (-0.01%)

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

Labels

PG-exploit-mitigations Project group: Exploit mitigations 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.

[Work Item]: dyn compatible non-typeconsts in GCA

6 participants