-
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
Fix issue: Global paths in use
directives can begin with super
or self
#32225
#32403
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pnkfelix (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
This should probably be checked after macro expansion and not in parser (due to macros) + for all paths and not only for imports. |
@petrochenkov Okay, would try to remake in near future |
@petrochenkov I believe this already checks macro expanded code since macro expanded code is parsed just like other code. |
@@ -1774,6 +1776,7 @@ impl<'a> Parser<'a> { | |||
}) | |||
} | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: There's no need for these added newlines
@vlastachu Thanks for the PR! I like this implementation. Could you squash the existing commits and add a
Also, the initial comment should be a summary of the PR (something like "This fixes #32225 by forbidding |
@alexcrichton could you grep through the crates.io code for |
r? @jseyfried |
A cursory grep yielded:
|
I meant something like
I'm not exactly sure if it's reparsed or not. (but |
@petrochenkov I can't reproduce successful compilation with macro. Looks like there is additional checking for keywords. Probably any way to cheat parser and give
I don't get it. May be I don't understand this sentence right. Anyway global |
done
When all discussions will completed and last changes reviewed. |
Good point. I believe the path from your example is re-parsed but it doesn't really matter given procedural macros. Also, I agree that this should be a semantic rather than a syntactic error. @vlastachu Reviewed all commits, the test looks good. I think it would be best to have the check here, in the Since it won't add much complexity, I think we should do a warning cycle. This commit is an example of starting a warning cycle. |
Can you explain more about this? Am I remove all checking from parser and write similiar to pointed function? Then I should write it in single style with At first I thought that it is necessary to make warnings and stopped on that I can't make similiar warning in parser session. If I should save current parser checking than could you help with |
Yeah, there should be no checking in the parser, only in I wouldn't write a helper function (I think this is what you mean by pointed function) but you can if you want. Also, I wouldn't bother with the Here is an example of a warning in |
@vlastachu would you like to work on moving the check to |
@jseyfried Yes, I would. Sory for silence. I was planning to do this at weekend. But for some reason I did not find the time. I will try to finish everything before the end of the week, or will notify you that I can not. |
Thanks, no hurry! |
@jseyfried here Comments says that this flag works as expected. |
Good point. I believe you can fix the flag by changing this line to let is_global = self.eat(&token::ModSep); and then replacing |
Without unusual loop.
|
declare_lint! { | ||
pub SUPER_OR_SELF_IN_GLOBAL_MODNAME, | ||
Warn, | ||
"detects super or self keywords in begin of global path" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "detects super or self keywords at the beginning of global paths"
@vlastachu Nice, looks good!
I would prefer the simpler checking you described, at least until the warning becomes a hard error.
Yeah. I would also squash all the commits into a single commit first, both for a cleaner history and for easier rebasing. |
3a9b0af
to
3982d07
Compare
2fbedc8
to
16c3662
Compare
@@ -179,6 +179,12 @@ declare_lint! { | |||
"lints that have been renamed or removed" | |||
} | |||
|
|||
declare_lint! { | |||
pub SUPER_OR_SELF_IN_GLOBAL_MODNAME, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: rename to SUPER_OR_SELF_IN_GLOBAL_PATH
@vlastachu Excellent! In your initial comment, could you change "forbidding" to "warning on" and "during parsing" to "in r=me with that edit and with the nit / tidy errors addressed. |
@@ -137,6 +141,18 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> { | |||
} | |||
}; | |||
|
|||
// Checking for special identifiers in path | |||
// prevent `self` or `supper` at beginning of global path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: .. or
super at ..
@jseyfried Complete. |
Fix issue: Global paths in `use` directives can begin with `super` or `self` rust-lang#32225 This PR fixes rust-lang#32225 by warning on `use ::super::...` and `use ::self::...` on `resolve`. Current changes is the most minimal and ad-hoc.
This PR fixes #32225 by warning on
use ::super::...
anduse ::self::...
onresolve
.Current changes is the most minimal and ad-hoc.