1
Fork 0

Rollup merge of #33041 - petrochenkov:path, r=nrc,Manishearth

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 https://github.com/rust-lang/rust/issues/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 https://github.com/rust-lang/rust/issues/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 https://github.com/rust-lang/rust/issues/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
This commit is contained in:
Manish Goregaokar 2016-04-25 00:45:16 +05:30
commit a31658de51
No known key found for this signature in database
GPG key ID: 3BBF4D3E2EF79F98
111 changed files with 807 additions and 867 deletions

View file

@ -13,9 +13,7 @@ use ast::{self, Ident, Generics, Expr, BlockCheckMode, UnOp, PatKind};
use attr;
use codemap::{Span, respan, Spanned, DUMMY_SP, Pos};
use ext::base::ExtCtxt;
use parse::token::special_idents;
use parse::token::InternedString;
use parse::token;
use parse::token::{self, keywords, InternedString};
use ptr::P;
// Transitional reexports so qquote can find the paths it is looking for
@ -606,7 +604,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
self.expr_path(self.path_ident(span, id))
}
fn expr_self(&self, span: Span) -> P<ast::Expr> {
self.expr_ident(span, special_idents::self_)
self.expr_ident(span, keywords::SelfValue.ident())
}
fn expr_binary(&self, sp: Span, op: ast::BinOpKind,
@ -1153,7 +1151,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
vis: ast::Visibility, vp: P<ast::ViewPath>) -> P<ast::Item> {
P(ast::Item {
id: ast::DUMMY_NODE_ID,
ident: special_idents::invalid,
ident: keywords::Invalid.ident(),
attrs: vec![],
node: ast::ItemKind::Use(vp),
vis: vis,