-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
|
cc @rust-lang/fls |
|
@rfcbot resolve consistent-axioms |
|
🔔 This is now entering its final comment period, as per the review above. 🔔 |
|
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🎉 Experiment
Footnotes
|
|
Why did craterbot remove @rustbot label +S-waiting-on-documentation |
|
Blocked on rust-lang/reference#2136. |
internal: Add tests for rust-lang/rust#146972
|
I haven't seen it mentioned here, but I just wanted to note a confusing inconsistency with mod m {
fn f() {}
mod inner {
// OK: imports f
use self::super::f;
// Ok
use super as m_alias;
// Error: `super` in paths can only be used in start position or after another `super`
// Error message is confusing, because `self::super::f` was allowed.
use self::super as m_alias2;
// Same error as above.
use self::super;
}
}Is the rule something like this?
Is this intentional, or is there some issue for this? |
|
Not mentioned in the description is that the following is now allowed in 2015: use ::{self as other}; // imports the crate root as otherBefore this PR it was an error ( It makes sense to me, but I haven't seen much edition-specific differences noted here. |
The rule is " |
|
I was contrasting it with
What I'm getting at is that the error message says "it can only be used after another super", but that seems to be missing "possibly after an initial |
This is intentional in current impl of this PR (#146972 (comment)).
There are some usages of I think supporting this for importing |
Oh, yes, this is missed in the description. I will update the PR description. (Updated) |
internal: Add tests for rust-lang#146972
Reference PR
use $craterestriction reference#2010Description
This PR unifies and extends the behavior of importing path-segment keywords (
crate/$crate/super/self), resolving several long-standing inconsistencies.Previously, Rust only allowed
use crate as name;without renaming support for other path keywords. This PR enables importing these keywords with explicit renaming. And it also denies importing these keywords without renaming.What's now allowed
For
crateand$crate:use crate as name;use crate::{self as name};use $crate as name;use $crate::{self as name};For
super(including chainedsuper::super):use super as name;use super::{self as name};use super::super as name;use super::super::{self as name};For
self:use self as name;use self::{self as name};Removed error codes
Two error codes are no longer emitted:
selfimports likestd::fmt::{self, self}. The existing E0252 ("name defined multiple times") provides sufficient guidance.use {self as name};anduse ::{self as name};(in edition 2015). These patterns are now explicitly allowed. Foruse {self};anduse ::{self}(in edition 2015) without renaming, the new clearer error suggests adding an explicit rename.Future
We plan to remove error E0429 and support
selfat the end of paths (#146972 (comment)). This language extension and lint for redundant::selfinstead of hard errorE0429will be landed separately in the future.Fixes #29036
Fixes #35612
Fixes #37156
Fixes #146967
Fixes #149811
r? petrochenkov