-
Notifications
You must be signed in to change notification settings - Fork 571
document const generics #901
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
|
Its merged in rust-lang/rust#79135 |
Co-authored-by: est31 <[email protected]>
ehuss
left a comment
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.
Maybe I'm confused, but it seems like the grammar for GenericArgs needs to be updated for expressions?
Also, overall I feel like this is missing a lot of content. There seems to be a large amount of information in the stabilization report that would be good to carry over. There are a lot of details that seem to be missing (like const parameters don't have to be used unlike types and lifetimes). I also see a number of things in the RFC that don't seem to be mentioned.
I appreciate the effort for adding this documentation, but I would like to see a bit more detail if possible.
| > | ( _LifetimeParam_ `,` )<sup>\*</sup> _TypeParams_\ | ||
| > | ( _LifetimeParam_ `,` )<sup>\*</sup> ( _TypeParam_ `,` )<sup>\*</sup> _ConstParams_ |
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.
I believe this grammar is no longer correct (see #785). The order of the parameters doesn't matter syntactically.
You don't have to fix it if you don't want to (although that would be nice), I just wanted to make a note of it.
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.
won't do this in that PR, as I don't know what it's expected to look like now.
src/items/generics.md
Outdated
| Const parameters may only be be used as standalone arguments inside | ||
| of [types] and [repeat expressions]. | ||
| They can be used freely outside of [const contexts]. |
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.
I find these sentences a little difficult to understand. Can you add more detail, along with some examples?
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.
extended this a bit, it feels weird to go more in depth here as the explanation for types and lifetimes are also fairly short
Co-authored-by: Eric Huss <[email protected]>
Co-authored-by: Eric Huss <[email protected]>
Co-authored-by: Eric Huss <[email protected]>
|
there is still a lot we could add about const generics or generics in general. I am not able to spend a lot of time on rust in the near future so I would prefer merging this without adding too much more |
src/paths.md
Outdated
| > _GenericArgsConsts_ :\ | ||
| > [_Expression_] (`,` [_Expression_])<sup>\*</sup> |
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.
I don't think this is the actual grammar for arguments is it? According to parse_generic_arg I believe it is something like this:
diff --git a/src/paths.md b/src/paths.md
index 9126e5b..47a14ee 100644
--- a/src/paths.md
+++ b/src/paths.md
@@ -70,7 +70,13 @@ mod m {
> [_Type_] (`,` [_Type_])<sup>\*</sup>
>
> _GenericArgsConsts_ :\
-> [_Expression_] (`,` [_Expression_])<sup>\*</sup>
+> _GenericArgsConst_ (`,` _GenericArgsConst_)<sup>\*</sup>
+>
+> _GenericArgsConst_ :\
+> [_BlockExpression_]\
+> | [_LiteralExpression_]\
+> | `-` [_LiteralExpression_]\
+> | [_SimplePathSegment_]
>
> _GenericArgsBindings_ :\
> _GenericArgsBinding_ (`,` _GenericArgsBinding_)<sup>\*</sup>
@@ -375,10 +381,13 @@ mod without { // ::without
# fn main() {}
```
+[_BlockExpression_]: expressions/block-expr.md
+[_Expression_]: expressions.md
[_GenericArgs_]: #paths-in-expressions
[_Lifetime_]: trait-bounds.md
+[_LiteralExpression_]: expressions/literal-expr.md
+[_SimplePathSegment_]: #simple-paths
[_Type_]: types.md#type-expressions
-[_Expression_]: expressions.md
[literal]: expressions/literal-expr.md
[item]: items.md
[variable]: variables.mdIs that correct?
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.
yeah, that looks right to me
No worries, if you can confirm the comment above about the grammar, I can probably merge this and work on extending it. |
| ``` | ||
|
|
||
| Const arguments must be surrounded by braces unless they are a | ||
| [literal] or a single segment path. |
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.
in this case this section might not be needed
ehuss
left a comment
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.
I went ahead and pushed the fix for the grammar. I'll follow up with other PRs.
blocked on the stabilization of
min_const_generics.