Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking Issue for more complex const parameter types: feature(adt_const_params) #95174

Open
3 of 8 tasks
lcnr opened this issue Mar 21, 2022 · 14 comments
Open
3 of 8 tasks
Labels
A-const-generics Area: const generics (parameters and arguments) C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. F-adt_const_params `#![feature(adt_const_params)]` T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@lcnr
Copy link
Contributor

lcnr commented Mar 21, 2022

This is a tracking issue for allowing more const parameter types.
The feature gate for this issue is #![feature(adt_const_params)].

About tracking issues

Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.

Steps

Most of the work here will be coordinated in the #project-const-generics stream on zulip.

Unresolved Questions

cc @rust-lang/project-const-generics

@lcnr lcnr added C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. A-const-generics Area: const generics (parameters and arguments) F-adt_const_params `#![feature(adt_const_params)]` labels Mar 21, 2022
@lcnr lcnr changed the title Tracking Issue for more complex const parameter types (adt_const_params) Tracking Issue for more complex const parameter types: feature(adt_const_params) Mar 21, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 21, 2022
…e, r=Dylan-DPC

move `adt_const_params`  to its own tracking issue

the new tracking issue is  rust-lang#95174

r? `@rust-lang/project-const-generics`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 21, 2022
…e, r=Dylan-DPC

move `adt_const_params`  to its own tracking issue

the new tracking issue is  rust-lang#95174

r? ``@rust-lang/project-const-generics``
github-actions bot pushed a commit to rust-lang/glacier that referenced this issue Jun 30, 2022
=== stdout ===
=== stderr ===
warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /home/runner/work/glacier/glacier/ices/97047-1.rs:1:12
  |
1 | #![feature(adt_const_params, generic_const_exprs)]
  |            ^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #95174 <rust-lang/rust#95174> for more information

warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /home/runner/work/glacier/glacier/ices/97047-1.rs:1:30
  |
1 | #![feature(adt_const_params, generic_const_exprs)]
  |                              ^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #76560 <rust-lang/rust#76560> for more information

warning: field `changes` is never read
 --> /home/runner/work/glacier/glacier/ices/97047-1.rs:7:5
  |
3 | pub struct Changes<const CHANGES: &'static [&'static str]>
  |            ------- field in this struct
...
7 |     changes: [usize; CHANGES.len()],
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: 3 warnings emitted

==============
github-actions bot pushed a commit to rust-lang/glacier that referenced this issue Jun 30, 2022
=== stdout ===
=== stderr ===
warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /home/runner/work/glacier/glacier/ices/97047-2.rs:1:12
  |
1 | #![feature(adt_const_params, generic_const_exprs)]
  |            ^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #95174 <rust-lang/rust#95174> for more information

warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /home/runner/work/glacier/glacier/ices/97047-2.rs:1:30
  |
1 | #![feature(adt_const_params, generic_const_exprs)]
  |                              ^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #76560 <rust-lang/rust#76560> for more information

warning: unused variable: `other`
  --> /home/runner/work/glacier/glacier/ices/97047-2.rs:14:31
   |
14 |     pub fn combine(&mut self, other: &Self) {
   |                               ^^^^^ help: if this is intentional, prefix it with an underscore: `_other`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: 3 warnings emitted

==============
github-actions bot pushed a commit to rust-lang/glacier that referenced this issue Jul 12, 2022
=== stdout ===
=== stderr ===
warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /home/runner/work/glacier/glacier/ices/98813.rs:1:12
  |
1 | #![feature(adt_const_params)]
  |            ^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #95174 <rust-lang/rust#95174> for more information

error[E0741]: `f64` is forbidden as the type of a const generic parameter
 --> /home/runner/work/glacier/glacier/ices/98813.rs:5:25
  |
5 | pub struct Foo<const X: f64> {}
  |                         ^^^
  |
  = note: floats do not derive `Eq` or `Ord`, which are required for const parameters

error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0741`.
==============
github-actions bot pushed a commit to rust-lang/glacier that referenced this issue Jul 28, 2022
=== stdout ===
=== stderr ===
warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes
 --> <anon>:2:12
  |
2 | #![feature(adt_const_params)]
  |            ^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #95174 <rust-lang/rust#95174> for more information

error[E0741]: using function pointers as const generic parameters is forbidden
 --> <anon>:5:35
  |
5 |     pub struct Color<const WHITE: (fn(),)>;
  |                                   ^^^^^^^

error[E0741]: using function pointers as const generic parameters is forbidden
 --> <anon>:7:23
  |
7 |     impl<const WHITE: (fn(),)> Color<WHITE> {
  |                       ^^^^^^^

error: aborting due to 2 previous errors; 1 warning emitted

For more information about this error, try `rustc --explain E0741`.
==============
@jhpratt jhpratt moved this from Implemented to Incomplete in Upcoming & recently stabilized features Jul 31, 2022
@griffi-gh
Copy link

I think at least simple enums without assigned values should be allowed for now

@tarcieri
Copy link
Contributor

@griffi-gh I agree. However, in the meantime if you have an e.g. repr(u64) C-style enum, you can cast it with as u64 (or whatever integer type) to sort of fake being const generic around an enum, and that works fine even in const contexts, while also hopefully being trivially upgradable to adt_const_params in the future.

@jhpratt
Copy link
Member

jhpratt commented Oct 15, 2022

For what it's worth, I am currently hacking around this in time by encoding a struct into a u128, passing as a const generic, and decoding it back to the original struct. All at compile time, as the values are then associated constants. This approach is tedious, but it works for everything up to 16 bytes in size.

@mqudsi

This comment was marked as off-topic.

@eminence
Copy link
Contributor

Once place where adt_const_params really shines is in diagnostics. Consider the following stable code, which casts a repr(u8) enum, to be used in a const generic:

#[repr(u8)]
pub enum Facing {
    Up,
    Down,
}

pub struct Card<const FACING: u8> {
    // would normally have a "suit" and "number" field
}

pub fn foo(card: Card<{Facing::Up as u8}>) {
    let _: Card<{Facing::Down as u8}> = card;
}
   |
12 |     let _: Card<{Facing::Down as u8}> = card;
   |            --------------------------   ^^^^ expected `1`, found `0`
   |            |
   |            expected due to this
   |
   = note: expected struct `Card<1>`
              found struct `Card<0>`

But with a real enum and adt_const_params, the error message is much clearer:

   |
14 |     let _: Card<{Facing::Down}> = card;
   |            --------------------   ^^^^ expected `Facing::Down`, found `Facing::Up`
   |            |
   |            expected due to this
   |
   = note: expected struct `Card<Facing::Down>`
              found struct `Card<Facing::Up>`

@rust-lang rust-lang unlocked this conversation Apr 15, 2024
@BoxyUwU BoxyUwU added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Jul 21, 2024
@jhpratt jhpratt moved this from Incomplete to Implemented in Upcoming & recently stabilized features Aug 1, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Aug 9, 2024
Remove `try_from_lit` from `from_anon_const`

This PR tries to fix rust-lang#116308.

TODO:
- [ ] write up the reason why `try_from_lit` should be removed from `from_anon_const`
- [ ] write up the reason why it is safe to do this
- [ ] do a perf run and see if doing this affect performance

ui tests changes:
- [ ] failed run-pass/check-pass (`const-arg-in-const-arg.rs#full`, `abstract-const-as-cast-4.rs`, `no_dependence.rs`, `issue-94293.rs`)
- [ ] symbol mangling affected (`symbol-names/*`)
- [ ] different error report (`const-projection-err.rs#gce`, `abstract-const-as-cast-3.rs`, `type_mismatch.rs`)
- [x] misc
    - error report reordering
    - same error, but different const type reprs

This PR is related to two unstable features (`adt_const_params`: rust-lang#95174, `generic_const_exprs`: rust-lang#76560). r? `@BoxyUwU`
@clarfonthey
Copy link
Contributor

It seems that the main blocker to stabilising this is:

Author an RFC explaining the current state of the feature since it has significantly diverged from original RFC

Although I'm not exactly sure what exactly these differences are, and whether it's needed based after rust-lang/rfcs#3535 has clarified the details on constant patterns. Would someone be willing to update the description to clarify the details on this, and which RFC it's referring to for the original details?

(I know that there are other open issues for this feature, although it feels like the semantic clarification is the most difficult to resolve.)

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Aug 16, 2024
Special-case alias ty during the delayed bug emission in `try_from_lit`

This PR tries to fix rust-lang#116308.

A delayed bug in `try_from_lit` will not be emitted so that the compiler will not ICE when it sees the pair `(ast::LitKind::Int, ty::TyKind::Alias)` in `lit_to_const` (called from `try_from_lit`).

This PR is related to an unstable feature `adt_const_params` (rust-lang#95174).

r? `@BoxyUwU`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Aug 16, 2024
Special-case alias ty during the delayed bug emission in `try_from_lit`

This PR tries to fix rust-lang#116308.

A delayed bug in `try_from_lit` will not be emitted so that the compiler will not ICE when it sees the pair `(ast::LitKind::Int, ty::TyKind::Alias)` in `lit_to_const` (called from `try_from_lit`).

This PR is related to an unstable feature `adt_const_params` (rust-lang#95174).

r? ``@BoxyUwU``
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Aug 16, 2024
Rollup merge of rust-lang#129042 - Jaic1:fix-116308, r=BoxyUwU

Special-case alias ty during the delayed bug emission in `try_from_lit`

This PR tries to fix rust-lang#116308.

A delayed bug in `try_from_lit` will not be emitted so that the compiler will not ICE when it sees the pair `(ast::LitKind::Int, ty::TyKind::Alias)` in `lit_to_const` (called from `try_from_lit`).

This PR is related to an unstable feature `adt_const_params` (rust-lang#95174).

r? ``@BoxyUwU``
jieyouxu added a commit to jieyouxu/rust that referenced this issue Aug 18, 2024
Fix order of normalization and recursion in const folding.

Fixes rust-lang#126831.

Without this patch, type normalization is not always idempotent, which leads to all sorts of bugs in places that assume that normalizing a normalized type does nothing.

Tracking issue: rust-lang#95174

r? BoxyUwU
tgross35 added a commit to tgross35/rust that referenced this issue Aug 19, 2024
Fix order of normalization and recursion in const folding.

Fixes rust-lang#126831.

Without this patch, type normalization is not always idempotent, which leads to all sorts of bugs in places that assume that normalizing a normalized type does nothing.

Tracking issue: rust-lang#95174

r? BoxyUwU
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Aug 19, 2024
Rollup merge of rust-lang#129208 - veluca93:adt_const_fix, r=BoxyUwU

Fix order of normalization and recursion in const folding.

Fixes rust-lang#126831.

Without this patch, type normalization is not always idempotent, which leads to all sorts of bugs in places that assume that normalizing a normalized type does nothing.

Tracking issue: rust-lang#95174

r? BoxyUwU
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Aug 20, 2024
Fix order of normalization and recursion in const folding.

Fixes #126831.

Without this patch, type normalization is not always idempotent, which leads to all sorts of bugs in places that assume that normalizing a normalized type does nothing.

Tracking issue: rust-lang/rust#95174

r? BoxyUwU
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Sep 23, 2024
Handle unsized consts with type `str`  in v0 symbol mangling

This PR fixes rust-lang#116303 by handling consts with type `str` in v0 symbol mangling as partial support for unsized consts.

This PR is related to `#![feature(adt_const_params)]` (rust-lang#95174) and `#![feature(unsized_const_params)]` (rust-lang#128028).

r? `@BoxyUwU`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Sep 23, 2024
Handle unsized consts with type `str`  in v0 symbol mangling

This PR fixes rust-lang#116303 by handling consts with type `str` in v0 symbol mangling as partial support for unsized consts.

This PR is related to `#![feature(adt_const_params)]` (rust-lang#95174) and `#![feature(unsized_const_params)]` (rust-lang#128028).

r? ``@BoxyUwU``
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Sep 23, 2024
Rollup merge of rust-lang#130344 - Jaic1:fix-116306, r=BoxyUwU

Handle unsized consts with type `str`  in v0 symbol mangling

This PR fixes rust-lang#116303 by handling consts with type `str` in v0 symbol mangling as partial support for unsized consts.

This PR is related to `#![feature(adt_const_params)]` (rust-lang#95174) and `#![feature(unsized_const_params)]` (rust-lang#128028).

r? ``@BoxyUwU``
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Sep 30, 2024
…8179, r=compiler-errors

Fix `adt_const_params` leaking `{type error}` in error msg

Fixes the confusing diagnostic described in rust-lang#118179. (users would see `{type error}` in some situations, which is pretty weird)

`adt_const_params` tracking issue: rust-lang#95174
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Sep 30, 2024
Rollup merge of rust-lang#131038 - onkoe:fix/adt_const_params_leak_118179, r=compiler-errors

Fix `adt_const_params` leaking `{type error}` in error msg

Fixes the confusing diagnostic described in rust-lang#118179. (users would see `{type error}` in some situations, which is pretty weird)

`adt_const_params` tracking issue: rust-lang#95174
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) C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. F-adt_const_params `#![feature(adt_const_params)]` T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests