-
Notifications
You must be signed in to change notification settings - Fork 563
Initial docs for const generics #2677
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
Conversation
|
Thanks for the PR. If you have write access, feel free to merge this PR if it does not need reviews. You can request a review using |
| ```rust | ||
| fn foo<T: Sized>() { | ||
| let a = [1_u8; size_of::<*mut T>()]; | ||
| } | ||
| ``` | ||
|
|
||
| The one exception to all of the above is repeat counts of array expressions. As a *backwards compatibility hack* we allow the repeat count const argument to use generic parameters. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ```rust | |
| fn foo<T: Sized>() { | |
| let a = [1_u8; size_of::<*mut T>()]; | |
| } | |
| ``` | |
| The one exception to all of the above is repeat counts of array expressions. As a *backwards compatibility hack* we allow the repeat count const argument to use generic parameters. | |
| The one exception to all of the above is repeat counts of array expressions. As a *backwards compatibility hack* we allow the repeat count const argument to use generic parameters. | |
| ```rust | |
| fn foo<T: Sized>() { | |
| let a = [1_u8; size_of::<*mut T>()]; | |
| } | |
| ``` |
example is surprising when reading this, also, maybe use a sub-header here
| // There is no way to specify the const argument to `M` | ||
| foo::<N, { [1_u8; N] }>(); | ||
| } | ||
| ``` |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
This is a fairly minimal set of const generics docs. It doesn't talk much about
min_generic_const_argsbut definitely should. It also doesn't talk much aboutadt_const_paramsbut definitely should :3 though we mostly already have docs for that living in hackmd for one of the lang meetings. Just need to upstream those which I intend to do as part of drafting an RFC for adt_const_paramscc @lcnr added a new type system invariant for the whole const eval determinism thing, in some sense this is a more specific version of other stuff like "normalizing assoc types should yield a single type" but it feels interesting enough to list it independently.
cc #2663