Skip to content

Conversation

@camelid
Copy link
Member

@camelid camelid commented Apr 8, 2025

tracking issue: #132980
fixes #131046
fixes #134641

As part of implementing min_generic_const_args, we need to distinguish const items that can be used in the type system, such as in associated const equality projections, from const items containing arbitrary const code, which must be kept out of the type system. Specifically, all "type consts" must be either concrete (no generics) or generic with a trivial expression like N or a path to another type const item.

To syntactically distinguish these cases, we require, for now at least, that users annotate all type consts with the #[type_const] attribute. Then, we validate that the const's right-hand side is indeed eligible to be a type const and represent it differently in the HIR.

We accomplish this representation using a new ConstItemRhs enum in the HIR, and a similar but simpler enum in the AST. When #[type_const] is not applied to a const (e.g. on stable), we represent const item right-hand sides (rhs's) as HIR bodies, like before. However, when the attribute is applied, we instead lower to a hir::ConstArg. This syntactically distinguishes between trivial const args (paths) and arbitrary expressions, which are represented using AnonConsts. Then in generics_of, we can take advantage of the existing machinery to bar the AnonConst rhs's from using parent generics.

@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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Apr 8, 2025
@camelid camelid 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 Apr 8, 2025
@rust-log-analyzer

This comment has been minimized.

@camelid camelid force-pushed the mgca-const-items branch from fa42f86 to 6054bd5 Compare April 9, 2025 16:14
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@camelid camelid force-pushed the mgca-const-items branch from 4f6c9ab to a46aa4c Compare May 15, 2025 12:37
@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) label May 15, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@camelid camelid added A-const-generics Area: const generics (parameters and arguments) F-min_generic_const_args `#![feature(min_generic_const_args)]` labels May 17, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented May 21, 2025

☔ The latest upstream changes (presumably #141343) made this pull request unmergeable. Please resolve the merge conflicts.

@BoxyUwU
Copy link
Member

BoxyUwU commented May 23, 2025

@oli-obk I've assigned you to this PR alongside me because I'd definitely want you to review it before it lands since its so CTFE involved 🤔 I don't think it needs reviewing rn though, things are so up in the air and we're not bootstrapping yet :3

@camelid camelid changed the title [WIP] mgca: Add ConstArg representation for const items mgca: Add ConstArg representation for const items Nov 1, 2025
@camelid camelid marked this pull request as ready for review November 1, 2025 18:54
@rustbot
Copy link
Collaborator

rustbot commented Nov 1, 2025

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann

HIR ty lowering was modified

cc @fmease

Some changes occurred to constck

cc @fee1-dead

This PR changes a file inside tests/crashes. If a crash was fixed, please move into the corresponding ui subdir and add 'Fixes #' to the PR description to autoclose the issue upon merge.

@BoxyUwU
Copy link
Member

BoxyUwU commented Nov 1, 2025

(rustfmt changes seem to have been accidental and have since been removed)

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. label Nov 3, 2025
@rust-log-analyzer

This comment has been minimized.

Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

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

r=me with rustdoc and some cleanups and docs

View changes since this review

camelid and others added 12 commits November 6, 2025 23:01
When mgca is enabled, const rhs's that are paths may have false
negatives with the lints in non_copy_const.rs. But these should probably
be using the trait solver anyway, and it only happens under mgca.
Also removed a test that was literally a duplicate of the one I kept.
@oli-obk
Copy link
Contributor

oli-obk commented Nov 7, 2025

r=me with the oli-review commit git absorbed

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

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-const-generics Area: const generics (parameters and arguments) F-min_generic_const_args `#![feature(min_generic_const_args)]` S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ICE]: Associated const projection not yet supported access outside the bounds for given AllocRange

6 participants