-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
self
and super
behave inconsistently in use
statements and as module names
#35612
Comments
I'd be happy to take a shot at fixing these issues, but I'd like some feedback on my summary of what's going on before I do. |
Why do you say this? Judging by the errors, |
This is similar to #29036 |
This is not true, try to experiment more. Keywords in identifier positions do the next things: 1) report a non-fatal error, 2) define an identifier with keyword name - this is a part of error recovery in parser. So,
|
I'm not sure what action should be taken here. @petrochenkov do we need to change any behaviour or should we just improve diagnostics? |
In general, the behavior needs to be changed. use crate as name; // OK
use crate; // ERROR, needs the "as name" part For the examples in the issue it will only result in diagnostic changes though, because they are all erroneous. |
Handling of
self
andsuper
inuse
andmod
statements is inconsistent. Playpen:There are probably several (related) issues here.
self
andsuper
as module names: if we add amod self { }
to the above, we get the two "expected identifier, found keyword" errors we'd expect -- and no other output. It appears thatmod self { }
causes an immediate "aborting due to previous error", whilemod super { }
does not.use super::{self, ...};
doesn't special-case theself
keyword as a keyword likeuse foo::bar::{self, ...};
does.use super;
doesn't special-case thesuper
keyword as a keyword.use self;
does do some special-casing so it can produce "error:self
imports are only allowed within a { } list [E0429]", but it then continues by attempting to resolveself
as an ident.The text was updated successfully, but these errors were encountered: