-
Notifications
You must be signed in to change notification settings - Fork 537
Document inferred const args (feature(generic_arg_infer)
)
#1835
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -227,6 +227,28 @@ fn generic<const B: bool>() { | |
} | ||
``` | ||
|
||
r[items.generics.const.inferred] | ||
|
||
r[items.generics.const.inferred.syntax] | ||
```grammar,const | ||
InferredConst -> | ||
`_` | ||
| `(` InferredConst `)` | ||
``` | ||
|
||
r[items.generics.const.inferred.intro] | ||
The inferred const asks the compiler to infer the const argument if possible | ||
based on the surrounding information available. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a semi-realistic looking example here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah yeah sure |
||
|
||
```rust | ||
fn make_buf() -> [u8; 1024] { | ||
[0x1; _] | ||
} | ||
``` | ||
|
||
r[items.generics.const.inferred.constraint] | ||
It cannot be used in item signatures. | ||
Comment on lines
+249
to
+250
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not quite following this. If we are defining this as a new form allowed in generic args, why would there be a rule that it is not allowed in item signatures? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't allow type inference in signatures in general, not just as a restriction on const arguments. For example this is an error on stable: struct Foo<T>(T);
fn bar(param: Foo<_>) {} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this already stated in type.inferred.constraint (inferred.md)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah we state that for |
||
|
||
r[items.generics.where] | ||
## Where clauses | ||
|
||
|
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'm not sure I fully understand this grammar since it isn't referred to anywhere.
Am I understanding correctly that this is added for GenericArgsConst? Or is it somewhere else? That is, should it be:
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.
Yep exactly 👍 It's a little bit funny because it means that InferredType and InferredConst share the same grammar but I'm not sure that matters too much for this?