-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Can't import super #29036
Comments
@rust-lang/lang, what do you think about this? |
I vaguely expect This error message "error: unresolved import |
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
c.f. #39330 (comment) |
Any chance this being fixed in rust 2018? |
I stumbled on this today. This is clearly allowed by the grammar in reference, and either should work or the reference needs to be changed: UseDeclaration : UseTree : SimplePath : SimplePathSegment : |
Alternate perhaps simpler workaround:
|
I'm not sure if this falls into the realm of something needing an RFC or not, but I expected this to work:
but it gives
error: expected identifier, found keyword
super``.If I do it in an import list I get a different error:
error: unresolved import
super. There is no
superin
???``(I suppose this also applies to
self
, but I can't think of a reason to do that.)Edit: This seems to work as a substitute:
The text was updated successfully, but these errors were encountered: