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

Valid const parameter types #34

Open
lcnr opened this issue Mar 23, 2022 · 0 comments
Open

Valid const parameter types #34

lcnr opened this issue Mar 23, 2022 · 0 comments
Labels
A-param-types Const parameter types C-design-docs Category: This is part of our design documentation K-behavior Document Kind: regarding user visible behavior P-necessary Priority: will be needed at some point S-active

Comments

@lcnr
Copy link
Contributor

lcnr commented Mar 23, 2022

What is this

This is a design document for const generics. Any discussions about its content should be on zulip. The conclusions of these discussions should then be edited back into this issue. Please do not post any comments directly in this issue.

Content

We have to decide which types may be used as a const parameter and whether there needs to be explicit opt-in.

Allowing a type to be used as a const parameter type adds additional stability guarantees.

Stability guarantees of const parameter types

These issues stem from the fact that const parameters rely on structural equality (#29).

If a type is used as a const parameter, one must not add a field to that type which does not have structural equality, e.g. raw pointers.

Const parameters also make it far easier to rely on the exact behavior of structural equality, meaning that changing something from structurally equal to merely semantically equal is far more likely to be breaking.

Possible ways forward

We could require const parameter types to only have public fields, meaning that there is no way to break their use for const parameters in a way which isn't already considered a breaking change. This isn't too great as it feels somewhat arbitrary doesn't easily extend to types like NonZeroUsize.

Require types to explicitly opt-in. Most likely by adding an explicit #[derive(StructuralEq)] which is recursively checked for all fields. Depending on the results of #29 we may also use a different name for this, but using a new trait which has to be explicitly added seems like the right step forward.

Previous discussions

@lcnr lcnr added C-design-docs Category: This is part of our design documentation K-behavior Document Kind: regarding user visible behavior P-necessary Priority: will be needed at some point S-active A-param-types Const parameter types labels Mar 23, 2022
@rust-lang rust-lang locked and limited conversation to collaborators Mar 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-param-types Const parameter types C-design-docs Category: This is part of our design documentation K-behavior Document Kind: regarding user visible behavior P-necessary Priority: will be needed at some point S-active
Projects
None yet
Development

No branches or pull requests

1 participant