-
Notifications
You must be signed in to change notification settings - Fork 14k
Support importing path-segment keyword with renaming #146972
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
base: main
Are you sure you want to change the base?
Conversation
|
Failed to set assignee to
|
The previous wording for this restriction was pretty confusing to me. I don't remember what I was thinking when I wrote it, and I can't find any historical explanation either. `use` paths can use `$crate` as long as they have more than one segment (`use $crate::foo` is obviously OK). I have rewritten this to make it clear it is specifically about `use $crate`. One could say that restriction is already covered by the previous point that says `use crate;` requires an `as`, but for some reason `use $crate as foo` doesn't work either. So I have left this as a separate rule for now. cc rust-lang/rust#146972 (comment) for context.
ce2578f to
49c425d
Compare
use $crate::{self} like use $crate
49c425d to
d0d3a9d
Compare
This comment has been minimized.
This comment has been minimized.
d0d3a9d to
c8526a5
Compare
This comment has been minimized.
This comment has been minimized.
c8526a5 to
db9bb42
Compare
This comment has been minimized.
This comment has been minimized.
df75a52 to
96820fa
Compare
This comment has been minimized.
This comment has been minimized.
96820fa to
1473c4c
Compare
This comment has been minimized.
This comment has been minimized.
1473c4c to
e0d5fa0
Compare
This comment has been minimized.
This comment has been minimized.
e0d5fa0 to
4c38159
Compare
This comment has been minimized.
This comment has been minimized.
4c38159 to
aca5e4e
Compare
This comment has been minimized.
This comment has been minimized.
aca5e4e to
30a19ad
Compare
e317ae4 to
b13c316
Compare
This comment has been minimized.
This comment has been minimized.
b13c316 to
3edfefd
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
5113fc0 to
42a9210
Compare
use $crate::{self} like use $crate|
@rustbot ready |
tests/ui/use/use-path-segment-kw.rs
Outdated
| use ::{super as _nested_super2}; //~ ERROR unresolved import `super` | ||
|
|
||
| use foobar::super; //~ ERROR imports need to be explicitly named | ||
| pub use foobar::super as _super3; // Good |
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.
This is not good, super is only supposed to be used in start position, or after another super.
super, super::super, super::super::super - ok, foobar::super - not ok, self::super - not ok even if accepted on stable.
It does have a reasonable meaning (technically we can support self and super in all positions in paths), but relaxing the rules here is probably a different issue than what this PR tries to address.
|
I've focused on the new tests for now. |
|
Reminder, once the PR becomes ready for a review, use |
42a9210 to
ef3a34e
Compare
This comment has been minimized.
This comment has been minimized.
ef3a34e to
9fb6326
Compare
… r=petrochenkov Add test for importing path-segment keyword Adding new test to make a snapshot of current compiler's behavior. See rust-lang#146972 (comment) r? `@petrochenkov`
Rollup merge of #149151 - mu001999-contrib:test/use-path-kw, r=petrochenkov Add test for importing path-segment keyword Adding new test to make a snapshot of current compiler's behavior. See #146972 (comment) r? `@petrochenkov`
9fb6326 to
c5bb3f1
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@rustbot ready |
Reference PR:
use $craterestriction reference#2010Description:
self/super/crate/$cratecan be imported with renaming nowuse self/super/crate/$crate as name;and alsouse super/crate/$crate::{self as name};use self/super/crate/$crate;and alsouse super/crate/$crate::{self};use ::self;,use ::{self};,use ::self as name;anduse ::{self as name};E0430andE0431are no longer emitted now[E0430]: self import can only appear once in an import listwas emitted before whenstd::fmt::{self, self}, but the emitted[E0252]: the name fmt is defined multiple timesis good enough[E0431]: self import can only appear in an import list with a non-empty prefixwas emiited before whenuse {self as name};, nowuse {self as name};is allowed; foruse {self};, it's denied because it lacks renaming and will emitimports need to be explicitly namedwith suggesting renaming.Fixes #146967
r? petrochenkov