Skip to content

Conversation

@camelid
Copy link
Member

@camelid camelid commented Jan 8, 2026

This is meant to be the interim successor to generic const expressions.
Essentially, const item RHS's will be allowed to do arbitrary const
operations using generics. The limitation is that these const items will
be treated opaquely, like ADTs in nominal typing, such that uses of them
will only be equal if the same const item is referenced. In other words,
two const items with the exact same RHS will not be considered equal.

I also added some logic to check feature gates that depend on others
being enabled (like oGCA depending on mGCA).

r? @BoxyUwU

@rustbot rustbot added 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. labels Jan 8, 2026
@camelid
Copy link
Member Author

camelid commented Jan 8, 2026

TODO:

  • only use AnonConstKind::OGCA for const item RHS's
  • add tests
  • (less urgent:) don't normalize opaque const items (those with OGCA RHS)
  • (once we don't normalize:) handle coherence correctly (ambiguous if not definitionally equal)

@camelid camelid added the A-const-generics Area: const generics (parameters and arguments) label Jan 8, 2026
@rust-log-analyzer

This comment has been minimized.

@BoxyUwU
Copy link
Member

BoxyUwU commented Jan 8, 2026

When we avoid normalizing type consts to opaque anon consts we need to make sure that the normalization is ambiguous in coherence instead of NoSolution:

#![feature(min_generic_const_args, opaque_generic_const_args)]

#[type_const]
const FOO<const N: usize>: usize = const { N + 1 };

#[type_const]
const BAR<const N: usize>: usize = const { N + 1 };

trait Trait {}

impl Trait for [(); FOO::<1>] {}
impl Trait for [(); BAR::<1>] {}

ie we don't want this code to pass due to the two opaque anon consts being unequal.

@camelid
Copy link
Member Author

camelid commented Jan 8, 2026

Ooh good point 👍

This is meant to be the interim successor to generic const expressions.
Essentially, const item RHS's will be allowed to do arbitrary const
operations using generics. The limitation is that these const items will
be treated opaquely, like ADTs in nominal typing, such that uses of them
will only be equal if the same const item is referenced. In other words,
two const items with the exact same RHS will not be considered equal.

I also added some logic to check feature gates that depend on others
being enabled (like oGCA depending on mGCA).
@rust-log-analyzer

This comment has been minimized.

@camelid camelid marked this pull request as ready for review January 16, 2026 03:37
@rustbot
Copy link
Collaborator

rustbot commented Jan 16, 2026

HIR ty lowering was modified

cc @fmease

@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 Jan 16, 2026
@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-llvm-20-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
fmt: checked 6650 files
tidy check
tidy [rustdoc_json (src)]: `rustdoc-json-types` modified, checking format version
tidy: Skipping binary file check, read-only filesystem
tidy [style (compiler)]: /checkout/compiler/rustc_feature/src/unstable.rs:603: TODO is used for tasks that should be done before merging a PR; If you want to leave a message in the codebase use FIXME
tidy [style (compiler)]: FAIL
tidy [features]: /checkout/compiler/rustc_feature/src/unstable.rs:604: no tracking issue for feature opaque_generic_const_args
tidy [features]: FAIL
tidy: The following checks failed: features, style (compiler)
Command `/checkout/obj/build/aarch64-unknown-linux-gnu/stage1-tools-bin/rust-tidy /checkout /checkout/obj/build/aarch64-unknown-linux-gnu/stage0/bin/cargo /checkout/obj/build 4 yarn` failed with exit code 1
Created at: src/bootstrap/src/core/build_steps/tool.rs:1612:23
Executed at: src/bootstrap/src/core/build_steps/test.rs:1357:29

Command has failed. Rerun with -v to see more details.
Bootstrap failed while executing `--stage 2 test --skip tests --skip coverage-map --skip coverage-run --skip library --skip tidyselftest`
Build completed unsuccessfully in 0:00:51
  local time: Fri Jan 16 03:42:39 UTC 2026
  network time: Fri, 16 Jan 2026 03:42:40 GMT
##[error]Process completed with exit code 1.

diag.span_note(impl_.self_ty.span, "not a concrete type");
}
}
if !self.tcx.features().opaque_generic_const_args() {
Copy link
Member

Choose a reason for hiding this comment

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

in theory this means we'll suggest the feature gate on stable right? as we use this codepath also for forbidding uses of generic parameters on stable for cases that nameres cant catch

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed it locally to require mgca but forgot to push apparently haha

@BoxyUwU
Copy link
Member

BoxyUwU commented Jan 16, 2026

also need to add the coherence test :3

@BoxyUwU BoxyUwU 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 Jan 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-const-generics Area: const generics (parameters and arguments) 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

None yet

Development

Successfully merging this pull request may close these issues.

4 participants