Skip to content

Conversation

@fmease
Copy link
Member

@fmease fmease commented Jan 8, 2026

Under feature min_generic_const_args (mGCA) (#132980), render traits with non-parametrized type-level associated constants (i.e., #[type_const] ones) dyn compatible but force the user to specify all type-level associated consts in the trait object type via bindings (either directly, via supertrait bounds and/or behind trait aliases) just like associated types, their sibling.

Fixes #130300 (feature request).
Fixes #136063 (bug).
Fixes #137260 (bug).
Fixes #137514 (bug).

While I'm accounting for most illegal Self references via const projections & params, I'm intentionally ignoring RUST-123140 in this PR which is to be tackled some other time.

Blockers

  1. This PR basically sits atop PR RUST-150799 (but squashed) (rebased)
  2. Do a perf run (done)
  3. Merge RUST-150844 (split out of this PR) (rebased)
  4. Crate rustc-demangle needs to be updated first, mainly for v0 mangling
  5. Apart from v0 mangling, legacy mangling (no longer the default) ICEs on such dyn traits
    • we might want to address that
  6. There are some minor diagnostic tweaks I'd still like to perform (see FIXMEs)

@fmease fmease added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. S-blocked Status: Blocked on something else such as an RFC or other implementation work. T-types Relevant to the types team, which will review and decide on the PR/issue. F-associated_const_equality `#![feature(associated_const_equality)]` labels Jan 8, 2026
@fmease fmease added the F-min_generic_const_args `#![feature(min_generic_const_args)]` label Jan 8, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 8, 2026

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

This PR modifies tests/ui/issues/. If this PR is adding new tests to tests/ui/issues/,
please refrain from doing so, and instead add it to more descriptive subdirectories.

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-tidy Area: The tidy tool S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Jan 8, 2026
@fmease fmease moved this to In Progress in Associated Const Equality (ACE) Jan 8, 2026
@fmease

This comment was marked as outdated.

@rust-timer

This comment was marked as outdated.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Jan 8, 2026
mGCA: Make trait object types with type associated consts dyn compatible if the latter are specified via bindings
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 8, 2026
@rust-log-analyzer

This comment has been minimized.

@fmease

This comment was marked as outdated.

@rust-bors

This comment was marked as outdated.

@fmease

This comment was marked as outdated.

@rust-timer

This comment was marked as outdated.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Jan 8, 2026
mGCA: Make trait object types with type associated consts dyn compatible if the latter are specified via bindings
@rustbot
Copy link
Collaborator

rustbot commented Jan 8, 2026

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@rustbot rustbot added the T-clippy Relevant to the Clippy team. label Jan 8, 2026
@fmease fmease changed the title mGCA: Make trait object types with type associated consts dyn compatible if the latter are specified via bindings mGCA: Make trait object types with type-level associated consts dyn compatible if the latter are specified via bindings Jan 8, 2026
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (e81452f): comparison URL.

Overall result: ❌ regressions - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

@bors rollup=never
@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.0% [0.0%, 0.1%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary 1.0%, secondary 0.6%)

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

mean range count
Regressions ❌
(primary)
1.0% [1.0%, 1.0%] 1
Regressions ❌
(secondary)
1.7% [1.7%, 1.7%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.6% [-0.6%, -0.6%] 1
All ❌✅ (primary) 1.0% [1.0%, 1.0%] 1

Cycles

Results (secondary 0.0%)

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

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.7% [2.7%, 2.7%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.7% [-2.7%, -2.7%] 1
All ❌✅ (primary) - - 0

Binary size

Results (secondary 0.1%)

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

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.1% [0.0%, 0.1%] 9
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Bootstrap: 472.536s -> 473.075s (0.11%)
Artifact size: 391.23 MiB -> 391.29 MiB (0.01%)

@rust-bors

This comment has been minimized.

@fmease fmease force-pushed the dyn-ace branch 3 times, most recently from 19c584d to fb5b179 Compare January 11, 2026 18:44
rust-bors bot pushed a commit that referenced this pull request Jan 12, 2026
mGCA: Move tests for assoc const bindings (formerly ACE) into dedicated directory & replace more mentions of ACE

Split out of PR #150843.
As discussed.

Somewhat obvious underlying principle: If the test checks basic or core parts of assoc const bindings and nothing else, move it, otherwise leave it even if it contains ACEs.

Motivation: It makes a lot easier for me to continue working on ACE efficiently.

r? @BoxyUwU
github-actions bot pushed a commit to rust-lang/rust-analyzer that referenced this pull request Jan 15, 2026
mGCA: Move tests for assoc const bindings (formerly ACE) into dedicated directory & replace more mentions of ACE

Split out of PR rust-lang/rust#150843.
As discussed.

Somewhat obvious underlying principle: If the test checks basic or core parts of assoc const bindings and nothing else, move it, otherwise leave it even if it contains ACEs.

Motivation: It makes a lot easier for me to continue working on ACE efficiently.

r? @BoxyUwU
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Jan 15, 2026
mGCA: Move tests for assoc const bindings (formerly ACE) into dedicated directory & replace more mentions of ACE

Split out of PR rust-lang/rust#150843.
As discussed.

Somewhat obvious underlying principle: If the test checks basic or core parts of assoc const bindings and nothing else, move it, otherwise leave it even if it contains ACEs.

Motivation: It makes a lot easier for me to continue working on ACE efficiently.

r? @BoxyUwU
…ll assoc consts to be specified via bindings
We used to lower such bad defaulted const args in trait object types to
`{type error}`; now correctly lower them to `{const error}`.

The added tests used to ICE prior to this change.
…wise ref `Self`

The added test used to ICE prior to this change.
This fully rewords the diagnostic that was previously only emitted for assoc ty bindings.
That's because it incorrectly called trait aliases *type aliases* and didn't really
make it clear what the root cause is.

The added test used to ICE prior to this change.

I've double-checked that the preexisting test I've modified still ICEs in
nightly-2025-03-29.
// Collect all associated items that weren't specified and compute the list of projection
// bounds which we'll later turn into existential ones.
// For why we keep projections whose associated item has a `Self: Sized` bound,
// see <https://github.com/rust-lang/rust/pull/140684>.
Copy link
Member

Choose a reason for hiding this comment

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

can we say sth like "we keep them around so that we the resulting ty after HIR ty lowering still contains the user written types on the rhs of the assoc item binding, see https://github.com/...". clicking the link is annoying 😅

}

fn main() {
let _: dyn Trait; //~ ERROR the trait `Trait` is not dyn compatible
Copy link
Member

Choose a reason for hiding this comment

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

can you add another case with dyn Trait<K = 0> and check that errors

@@ -0,0 +1,27 @@
// Ensure that we can successfully mangle & demangle trait object types w/ assoc const bindings.

// FIXME(fmease): Legacy mangling still crashes.
Copy link
Member

Choose a reason for hiding this comment

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

FIXME(mgca)

i wanna know this when looking at mgca issues not jsut when looking at your FIXMEs :3


// This is a run-pass test to ensure that codegen can actually deal with such method instances
// (e.g., const projections normalize flawlessly to something concrete, symbols get mangled
// properly properly) and to ensure that the generated code "received" the correct values from
Copy link
Member

Choose a reason for hiding this comment

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

properly properly

// FIXME(fmease): Create `ty::AssocTag::descr`.
Descr::Tag(ty::AssocTag::Type) => "associated type",
Descr::Tag(ty::AssocTag::Const) => "associated constant",
_ => "associated item",
Copy link
Member

Choose a reason for hiding this comment

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

exhaustive match + unreachable arm for ty::AssocTag::Fn?

where_constraints.push(principal_span);
}

// FIXME(fmease): Get rid of this note outright, it is utter nonsense! Maybe mentioning
Copy link
Member

Choose a reason for hiding this comment

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

snarky!

Copy link
Member

@BoxyUwU BoxyUwU left a comment

Choose a reason for hiding this comment

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

I've looked over all the commits, got some nits and you've still got the other thing to fix with type consts' types having Self in them until approval though

View changes since this review

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

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-tidy Area: The tidy tool F-associated_const_equality `#![feature(associated_const_equality)]` F-min_generic_const_args `#![feature(min_generic_const_args)]` rla-silenced Silences rust-log-analyzer postings to the PR it's added on. S-blocked Status: Blocked on something else such as an RFC or other implementation work. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Projects

5 participants