-
Notifications
You must be signed in to change notification settings - Fork 584
Fix the grammar of function pointer types #2240
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
966c87c
abba355
9319118
400cb4b
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,23 +5,21 @@ r[type.fn-pointer.syntax] | |||||
| ```grammar,types | ||||||
| BareFunctionType -> | ||||||
| ForLifetimes? FunctionTypeQualifiers `fn` | ||||||
| `(` FunctionParametersMaybeNamedVariadic? `)` BareFunctionReturnType? | ||||||
| `(` MaybeNamedFunctionParameters? `)` BareFunctionReturnType? | ||||||
|
|
||||||
| FunctionTypeQualifiers -> `unsafe`? (`extern` Abi?)? | ||||||
| FunctionTypeQualifiers -> Safety? (`extern` Abi?)? | ||||||
|
|
||||||
| BareFunctionReturnType -> `->` TypeNoBounds | ||||||
|
|
||||||
| FunctionParametersMaybeNamedVariadic -> | ||||||
| MaybeNamedFunctionParameters | MaybeNamedFunctionParametersVariadic | ||||||
|
|
||||||
| MaybeNamedFunctionParameters -> | ||||||
| MaybeNamedParam ( `,` MaybeNamedParam )* `,`? | ||||||
| SelfParam `,`? | ||||||
| | (SelfParam `,`)? MaybeNamedParam ( `,` MaybeNamedParam )* `,`? | ||||||
|
|
||||||
| MaybeNamedParam -> | ||||||
| OuterAttribute* ( ( IDENTIFIER | `_` ) `:` )? Type | ||||||
| OuterAttribute* ( MaybeNamedPattern `:` )? ( Type | `...` ) | ||||||
|
|
||||||
| MaybeNamedFunctionParametersVariadic -> | ||||||
| ( MaybeNamedParam `,` )* MaybeNamedParam `,` OuterAttribute* `...` | ||||||
| MaybeNamedPattern -> | ||||||
| `mut`? IDENTIFIER | ( `&` | `&&` )? ( `_` | `false` | `true` ) | ||||||
|
Member
Author
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. Yes, indeed, that's the grammar! It's a tiny subset of patterns. Note that this subgrammar is also used for associated functions in traits in Rust 2015. I didn't know how I am meant to branch on editions, so I didn't update the corresponding function item grammar that currently only has I guess I could do sth. akin to "
Member
Author
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. TODO: Note somewhere (maybe in a footnote that semantically only identifiers and underscores are valid)
Contributor
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. This doesn't look quite right. My understanding is that this logic comes from I think it would look something closer to:
Suggested change
because ident can be preceded by & or &&. However, this seems to be getting close to the territory of unintentional behavior. I'm wondering if this really is a bug in the compiler, and the grammar should be something else. |
||||||
| ``` | ||||||
|
|
||||||
| r[type.fn-pointer.intro] | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.
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.
oops
View changes since the review