Skip to content
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

docs: Missing grammar for functions. #9022

Closed
toqueteos opened this issue Sep 6, 2013 · 5 comments
Closed

docs: Missing grammar for functions. #9022

toqueteos opened this issue Sep 6, 2013 · 5 comments
Labels
A-grammar Area: The grammar of Rust

Comments

@toqueteos
Copy link
Contributor

Hard to define well but still required.

@toqueteos
Copy link
Contributor Author

My suggested grammar:
fn_decl: "fn" ident [ generic_decl ] ? "(" args ")" "->" [ arg | "(" args ")" ] block ;
generic_decl: "<" type [ "," type ] + ">" ;
args: arg [ "," arg ] + ;
arg: pat [ ":" type ] ;

I defined my own generic_decl because of #9023.

@huonw
Copy link
Member

huonw commented Sep 6, 2013

I think your proposed grammar is incorrect? "->" [arg | "(" args ")"] should probably be "->" type, since it's just the return type of the function.

@toqueteos
Copy link
Contributor Author

@huonw You are right, my bad.

New proposal:

fn_decl: "fn" ident [ generic_decl ] ? "(" args * ")" "->" type block ;
generic_decl: "<" type [ "," type ] * ">" ;
args: arg [ "," arg ] * ;
arg: pat [ ":" type ] ;

I changed:

  • generic_decl from +to *, 1 or more types.
  • args so it accepts functions without arguments and 1 argument functions (using * instead of +).

@steveklabnik
Copy link
Member

triage: still don't have a grammar here.

@steveklabnik
Copy link
Member

We now have a grammar as part of #19278 , so I'm giving this a close.

Aaron1011 added a commit to Aaron1011/rust that referenced this issue Mar 7, 2021
Output of `git log --oneline  c68432f1e..970bc67c3`:

970bc67c3 (HEAD, origin/master, origin/auto-cargo, origin/HEAD) Auto merge of rust-lang#9243 - wickerwaka:configurable-env-doc, r=ehuss
4d7a29b75 Document the configurable-env usntable option
f7a7a3f91 Auto merge of rust-lang#9229 - alexcrichton:fix-borrow-mut, r=ehuss
3f2ece7a9 Fix a `BorrowMut` error when stdout is closed
7441e8c23 Auto merge of rust-lang#8825 - Aaron1011:feature/report-future-incompat, r=ehuss
139ed73f5 Add future-incompat tracking issue number.
9ea350368 Fix some minor formatting issues.
f03d47ce4 Address review comments
6177c6584 Implement future incompatibility report support
c69409658 Auto merge of rust-lang#9022 - nagisa:nagisa/manifest_path, r=alexcrichton
548300b20 Add the path to the manifest in json output
99e714c05 Auto merge of rust-lang#9230 - kornelski:nobinaries, r=alexcrichton
61a31bc5f Auto merge of rust-lang#9236 - kornelski:track-assert, r=Eh2406
3f7f0942c track_caller on custom assert functions
6977dee10 Explain `cargo install` is not for libraries
e4aebf0a0 Auto merge of rust-lang#9231 - joshtriplett:clear-to-eol-if-color, r=alexcrichton
b219f0eb7 Auto merge of rust-lang#9181 - jyn514:computer-says-no, r=ehuss
0b1816578 Remove unhelpful link to Cargo book
ea46f5ce3 Use ANSI clear-to-EOL if color is force-enabled
a6394bcc1 Remove unnecessary `config` argument to `Features::add`
3a86ecf2d Fix TODO about nightly features
09677c83c Be less unix-centric in error messages
ecfdced0d Fix test that assumed tests always were run on the stable channel
eba541994 Update comment in build_script_env
a5720117f Make `nightly_features_allowed` a field instead of a function
169b09ce7 Compute `enable_nightly_features` once instead of on each call
8fc86e155 Remove unused thread_locals
4b096beae Fix `masquerade_as_nightly_cargo` in work threads
e56417c8c Suggest RUSTC_BOOTSTRAP=crate instead of RUSTC_BOOTSTRAP=1
418129dae Downgrade error to a warning when `RUSTC_BOOTSTRAP` is set or this is the nightly channel
6c422a2c0 Restrict RUSTC_BOOTSTRAP in build.rs
m-ou-se added a commit to m-ou-se/rust that referenced this issue Mar 9, 2021
Update Cargo

Output of `git log --oneline  c68432f1e..970bc67c3`:

970bc67c3 (HEAD, origin/master, origin/auto-cargo, origin/HEAD) Auto merge of rust-lang#9243 - wickerwaka:configurable-env-doc, r=ehuss
4d7a29b75 Document the configurable-env usntable option
f7a7a3f91 Auto merge of rust-lang#9229 - alexcrichton:fix-borrow-mut, r=ehuss
3f2ece7a9 Fix a `BorrowMut` error when stdout is closed
7441e8c23 Auto merge of rust-lang#8825 - Aaron1011:feature/report-future-incompat, r=ehuss
139ed73f5 Add future-incompat tracking issue number.
9ea350368 Fix some minor formatting issues.
f03d47ce4 Address review comments
6177c6584 Implement future incompatibility report support
c69409658 Auto merge of rust-lang#9022 - nagisa:nagisa/manifest_path, r=alexcrichton
548300b20 Add the path to the manifest in json output
99e714c05 Auto merge of rust-lang#9230 - kornelski:nobinaries, r=alexcrichton
61a31bc5f Auto merge of rust-lang#9236 - kornelski:track-assert, r=Eh2406
3f7f0942c track_caller on custom assert functions
6977dee10 Explain `cargo install` is not for libraries
e4aebf0a0 Auto merge of rust-lang#9231 - joshtriplett:clear-to-eol-if-color, r=alexcrichton
b219f0eb7 Auto merge of rust-lang#9181 - jyn514:computer-says-no, r=ehuss
0b1816578 Remove unhelpful link to Cargo book
ea46f5ce3 Use ANSI clear-to-EOL if color is force-enabled
a6394bcc1 Remove unnecessary `config` argument to `Features::add`
3a86ecf2d Fix TODO about nightly features
09677c83c Be less unix-centric in error messages
ecfdced0d Fix test that assumed tests always were run on the stable channel
eba541994 Update comment in build_script_env
a5720117f Make `nightly_features_allowed` a field instead of a function
169b09ce7 Compute `enable_nightly_features` once instead of on each call
8fc86e155 Remove unused thread_locals
4b096beae Fix `masquerade_as_nightly_cargo` in work threads
e56417c8c Suggest RUSTC_BOOTSTRAP=crate instead of RUSTC_BOOTSTRAP=1
418129dae Downgrade error to a warning when `RUSTC_BOOTSTRAP` is set or this is the nightly channel
6c422a2c0 Restrict RUSTC_BOOTSTRAP in build.rs
flip1995 pushed a commit to flip1995/rust that referenced this issue Jul 18, 2022
…e_docs, r=Jarcho

`NEEDLESS_OPTION_TAKE` doc improvements

changelog: More info on `NEEDLESS_OPTION_TAKE`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-grammar Area: The grammar of Rust
Projects
None yet
Development

No branches or pull requests

3 participants