Initial docs for const generics#2677
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.
| ```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.
| ```rust | ||
| type Alias<const B: bool> = [u8; B]; | ||
| //~^ ERROR: | ||
| ``` |
There was a problem hiding this comment.
I have a question.
The code compiles when I only define it without using Alias. Is this intended?
There was a problem hiding this comment.
no 😔 realised this while writing this section. i wrote ERROR: then opened playground to get the error message and realised it was broken then didnt update the section. need to fix this in the compiler rust-lang/rust#149774
Fix ambig-unambig-ty-and-consts link cc: rust-lang/rustc-dev-guide#2677
Rollup merge of #150666 - reddevilmidzy:fix-link, r=BoxyUwU Fix ambig-unambig-ty-and-consts link cc: rust-lang/rustc-dev-guide#2677
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