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 const mem::discriminant #69821

Closed
3 tasks done
lcnr opened this issue Mar 8, 2020 · 23 comments
Closed
3 tasks done

Tracking Issue for const mem::discriminant #69821

lcnr opened this issue Mar 8, 2020 · 23 comments
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. Libs-Small Libs issues that are considered "small" or self-contained Libs-Tracked Libs issues that are tracked on the team's project board. relnotes Marks issues that should be documented in the release notes of the next release. S-tracking-ready-to-stabilize Status: This is ready to stabilize; it may need a stabilization report and a PR T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@lcnr
Copy link
Contributor

lcnr commented Mar 8, 2020

The feature gate for the issue is #![feature(const_discriminant)].

History

Unresolved issues

@RalfJung
Copy link
Member

RalfJung commented Mar 8, 2020

The intrinsic is already implemented in Miri, you can copy that to rustc if you want.

If you do, please also submit a PR to Miri to remove the implementation there.

@jonas-schievink jonas-schievink added A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. C-feature-request Category: A feature request, i.e: not implemented / a PR. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Mar 8, 2020
@oli-obk

This comment has been minimized.

@RalfJung

This comment has been minimized.

@lcnr

This comment has been minimized.

@RalfJung

This comment has been minimized.

Centril added a commit to Centril/rust that referenced this issue Mar 11, 2020
make `mem::discriminant` const

implements rust-lang#69821, which could be used as a tracking issue for `const_discriminant`.

Should this be added to the meta tracking issue rust-lang#57563?
@Lokathor
Centril added a commit to Centril/rust that referenced this issue Mar 11, 2020
make `mem::discriminant` const

implements rust-lang#69821, which could be used as a tracking issue for `const_discriminant`.

Should this be added to the meta tracking issue rust-lang#57563?
@Lokathor
@lcnr lcnr changed the title Constify mem::discriminant Tracking Issue for const mem::discriminant Mar 12, 2020
@RalfJung RalfJung added C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. and removed C-feature-request Category: A feature request, i.e: not implemented / a PR. labels Mar 12, 2020
@jonas-schievink jonas-schievink added the B-unstable Blocker: Implemented in the nightly compiler and unstable. label Apr 14, 2020
@KodrAus KodrAus added Libs-Small Libs issues that are considered "small" or self-contained Libs-Tracked Libs issues that are tracked on the team's project board. labels Jul 29, 2020
@stephanemagnenat
Copy link

It seems that mem::discriminant is now const, as the doc shows. Shouldn't this issue be closed?

@memoryruins
Copy link
Contributor

memoryruins commented Jun 24, 2021

@stephanemagnenat the const part of it is still unstable.

#[stable(feature = "discriminant_value", since = "1.21.0")]
#[rustc_const_unstable(feature = "const_discriminant", issue = "69821")]
pub const fn discriminant<T>(v: &T) -> Discriminant<T> {
Discriminant(intrinsics::discriminant_value(v))
}

If you view nightly docs, it is much clearer, showing (const: unstable) next to the function. It will take a couple of releases before that rustdoc feature is part of stable docs.

image

@stephanemagnenat
Copy link

stephanemagnenat commented Jun 25, 2021

Thank you for the clarification!

@stephanemagnenat
Copy link

stephanemagnenat commented Jun 25, 2021

Btw, I saw on the PR (#69825) that people were asking for use cases to decide whether to stabilise this feature. I believe I have such a use case: I am making a parser for a DSL that must match existing data structures, and these can have members of various types. I thus have a custom Value type, and would like these data structures to return a description of themselves that contains which variant of Value they accept. I was planning to use the Discriminant<Value> type, but as I cannot have const values of this type in stable, I'll probably use the enum-kinds crate for now.

@aleokdev

This comment was marked as off-topic.

@oli-obk

This comment was marked as off-topic.

@aleokdev

This comment was marked as off-topic.

@oli-obk

This comment was marked as off-topic.

@joshtriplett joshtriplett added the S-tracking-ready-to-stabilize Status: This is ready to stabilize; it may need a stabilization report and a PR label Jul 13, 2022
@joshtriplett
Copy link
Member

We reviewed this in today's @rust-lang/lang meeting. It looks like there are mentions of wanting a use case to justify making this available in const. Leaving aside that there appear to have been mentions of use cases, in general we feel that if a function exists as non-const and it can be written as const then we should make it available in const.

@stephanemagnenat
Copy link

stephanemagnenat commented Jul 14, 2022

I have another use case (currently I ended up using the strum and num_traits packages), in addition to the one I mentioned on June 25 last year. I have a block-based visual programming language (see https://cand.li for a screenshot). Each block has possibly parameters (e.g. speed vector), and all blocks together are joined in a union. Sometimes, we want configurations where only a subset of blocks can be used (e.g. simple mode). It would be convenient to have such configurations const, so that they can be used in const contexts (as a global configuration for example). Ideally that feature would use the macro evoked by @aleokdev but even without it, there could be a const prototype for each block type (e.g. the one we show on the block palette) out of which the discriminant can be extracted in a const way.

@dtolnay
Copy link
Member

dtolnay commented Sep 27, 2023

@rfcbot fcp merge

Adds const on the following function, which has been stable since Rust 1.21:

// core::mem

pub const fn discriminant<T>(v: &T) -> Discriminant<T>

Example use cases benefiting from const: #69821 (comment), #69821 (comment)

@rfcbot
Copy link

rfcbot commented Sep 27, 2023

Team member @dtolnay has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Sep 27, 2023
@traviscross
Copy link
Contributor

@rustbot labels +I-lang-nominated

@rustbot rustbot added the I-lang-nominated Nominated for discussion during a lang team meeting. label Oct 18, 2023
@nikomatsakis
Copy link
Contributor

@rfcbot reviewed

@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Oct 18, 2023
@rfcbot
Copy link

rfcbot commented Oct 18, 2023

🔔 This is now entering its final comment period, as per the review above. 🔔

@traviscross
Copy link
Contributor

@rustbot labels -I-lang-nominated

@rustbot rustbot removed the I-lang-nominated Nominated for discussion during a lang team meeting. label Oct 18, 2023
@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Oct 28, 2023
@rfcbot
Copy link

rfcbot commented Oct 28, 2023

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

bors added a commit to rust-lang-ci/rust that referenced this issue Oct 28, 2023
Const stabilize mem::discriminant

Tracking issue: rust-lang#69821.

This PR is a rebase of rust-lang#103893 to resolve conflicts in library/core/src/lib.rs (against rust-lang#102470 and rust-lang#110393).
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 28, 2023
Const stabilize mem::discriminant

Tracking issue: rust-lang#69821.

This PR is a rebase of rust-lang#103893 to resolve conflicts in library/core/src/lib.rs (against rust-lang#102470 and rust-lang#110393).
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Nov 9, 2023
@joshtriplett joshtriplett added the relnotes Marks issues that should be documented in the release notes of the next release. label Feb 11, 2024
@Dylan-DPC
Copy link
Member

Closing this as it has been stabilised.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. Libs-Small Libs issues that are considered "small" or self-contained Libs-Tracked Libs issues that are tracked on the team's project board. relnotes Marks issues that should be documented in the release notes of the next release. S-tracking-ready-to-stabilize Status: This is ready to stabilize; it may need a stabilization report and a PR T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.