-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
use super :: A
does not parse
#14109
Comments
Can confirm this is still an issue with the latest rust $ rustc hi.rs
hi.rs:4:13: 4:18 error: expected identifier, found keyword `super`
hi.rs:4 use super :: A;
^~~~~
error: aborting due to previous error $ rustc --version
rustc 1.0.0-nightly (1d00c545e 2015-01-30 19:56:34 +0000) |
/cc @rust-lang/lang is this something we want to accept? |
one reason to hypothetically accept it: this form is sometimes produced by the pretty printer, I believe. :) |
To be clear, this is not accepted solely because of the whitespace? If so, then I think we should fix this - having the parser rely on whitespace seems very bad (unless there is good reason, or for error recovery heuristics, etc.). |
@nrc I believe so, yes. For example this compiles (whereas the example in the issue does not) pub struct A;
mod test {
use super:: A;
} |
Paths are mostly parsed without taking whitespaces into account, e.g. `std :: vec :: Vec :: new ()` parses successfully, however, there are some special cases involving keywords `super`, `self` and `Self`. For example, `self::` is considered a path start only if there are no spaces between `self` and `::`. These restrictions probably made sense when `self` and friends weren't keywords, but now they are unnecessary. The first two commits remove this special treatment of whitespaces by removing `token::IdentStyle` entirely and therefore fix rust-lang#14109. This change also affects naked `self` and `super` (which are not tightly followed by `::`, obviously) they can now be parsed as paths, however they are still not resolved correctly in imports (cc @jseyfried, see `compile-fail/use-keyword.rs`), so rust-lang#29036 is not completely fixed. The third commit also makes `super`, `self`, `Self` and `static` keywords nominally (before this they acted as keywords for all purposes) and removes most of remaining \"special idents\". The last commit (before tests) contains some small improvements - some qualified paths with type parameters are parsed correctly, `parse_path` is not used for parsing single identifiers, imports are sanity checked for absence of type parameters - such type parameters can be generated by syntax extensions or by macros when rust-lang#10415 is fixed (~~soon!~~already!). This patch changes some pretty basic things in `libsyntax`, like `token::Token` and the keyword list, so it's a plugin-[breaking-change]. r? @eddyb
The text was updated successfully, but these errors were encountered: