Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Function pointer should not allow full patterns. #58

Open
ehuss opened this issue Jun 28, 2019 · 4 comments
Open

Function pointer should not allow full patterns. #58

ehuss opened this issue Jun 28, 2019 · 4 comments
Labels
grammar Issues with the definition of the rust grammar restrictions Issues related to the permissiveness of the grammar

Comments

@ehuss
Copy link
Contributor

ehuss commented Jun 28, 2019

For example, the following should be rejected as a type:

fn((a, b): (i32, i32))

Instead of "pat", I think it should be IDENT | _.

Beware, don't alter FnSigInput for FnArg.

@ehuss ehuss added the grammar Issues with the definition of the rust grammar label Jun 28, 2019
@eddyb eddyb added restrictions Issues related to the permissiveness of the grammar and removed restrictions Issues related to the permissiveness of the grammar labels Jul 1, 2019
@Centril
Copy link
Contributor

Centril commented Mar 29, 2020

This seems like a semantic restriction, not a syntactic one (this is checked in AST validation).

@CAD97
Copy link
Contributor

CAD97 commented Mar 29, 2020

Rustc does disallow this with #[cfg(FALSE)], though, emitting E642.

error[E0642]: patterns aren't allowed in methods without bodies
 --> src/lib.rs:2:13
  |
2 | type x = fn((a, b): (i32, i32));
  |             ^^^^^^
  |
help: give this argument a name or use an underscore to ignore it
  |
2 | type x = fn(_: (i32, i32));
  |             ^

@Centril
Copy link
Contributor

Centril commented Mar 29, 2020

@CAD97 Oh yes. That's a question of precedence though in the parser, not disallowing per se; see rust-lang/reference#781 (comment) for the actual grammar here.

@Centril
Copy link
Contributor

Centril commented Mar 29, 2020

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
grammar Issues with the definition of the rust grammar restrictions Issues related to the permissiveness of the grammar
Projects
None yet
Development

No branches or pull requests

4 participants