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

use super :: A does not parse #14109

Closed
alexcrichton opened this issue May 11, 2014 · 5 comments · Fixed by #33041
Closed

use super :: A does not parse #14109

alexcrichton opened this issue May 11, 2014 · 5 comments · Fixed by #33041
Labels
A-grammar Area: The grammar of Rust

Comments

@alexcrichton
Copy link
Member

pub struct A;

mod test {
    use super :: A;
}
foo.rs:4:9: 4:14 error: found `super` in ident position                               
foo.rs:4     use super :: A;                                                          
                 ^~~~~                                                                
error: aborting due to previous error                                                 
@frewsxcv
Copy link
Member

frewsxcv commented Feb 3, 2015

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)

@steveklabnik
Copy link
Member

/cc @rust-lang/lang is this something we want to accept?

@pnkfelix
Copy link
Member

pnkfelix commented Feb 4, 2016

one reason to hypothetically accept it: this form is sometimes produced by the pretty printer, I believe. :)

@nrc
Copy link
Member

nrc commented Feb 4, 2016

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.).

@alexcrichton
Copy link
Member Author

@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;
}

Manishearth added a commit to Manishearth/rust that referenced this issue Apr 24, 2016
 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
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

Successfully merging a pull request may close this issue.

5 participants