rust-lang / wg-grammar

Where the work of WG-grammar, aiming to provide a canonical grammar for Rust, resides
Apache License 2.0
100 stars 20 forks source link

Handle IDENT restrictions #39

Open ehuss opened 5 years ago

ehuss commented 5 years ago

Currently the grammar allows restricted identifiers in IDENT. However, libsyntax does not. parse_ident_common

The following are examples rejected by libsyntax:

mod _ {}
mod as {}
mod abstract {}
mod self {}

The restriction should include all strong and reserved keywords, and _.

_ is special, it is allowed in a few places:

Where Example
const item const _: i32 = 0;
extern crate as alias extern crate c as _;
use aliases use x as _;
extern block function parameter names extern { fn f(_: i32); }
function pointer type fn(_: i32)

self is allowed for extern crate self as foo;

Paths allow several keywords: super, self, Self, and crate.