Support importing path-segment keyword with renaming#146972
Support importing path-segment keyword with renaming#146972mu001999 wants to merge 3 commits intorust-lang:mainfrom
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
93ec588 to
e2f18e7
Compare
|
🔔 This is now entering its final comment period, as per the review above. 🔔 |
e2f18e7 to
58f406d
Compare
This comment has been minimized.
This comment has been minimized.
|
Spurious failure |
58f406d to
b46c28e
Compare
This comment has been minimized.
This comment has been minimized.
|
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. |
|
@mu001999: Please be sure to see the comment in #146972 (comment). Let us know what you'd propose in rust-lang/reference#2136 for that, then mark that PR ready for review. When the Reference PR is approved, this PR can land. |
This comment has been minimized.
This comment has been minimized.
b46c28e to
6609e4b
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. |
Per what was discussed in rust-lang/rust#146972 (comment)
|
The documentation should be ready now. @petrochenkov Do you want to give this a final review? |
|
Yay, finally. |
…ate, r=petrochenkov Support importing path-segment keyword with renaming *[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/146972)* #### Reference PR - rust-lang/reference#2010 - rust-lang/reference#2136 #### Description 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 **`crate`** and **`$crate`**: - `use crate as name;` - `use crate::{self as name};` - `use $crate as name;` - `use $crate::{self as name};` For **`super`** (including chained `super::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: - **E0430**: Previously emitted for duplicate `self` imports like `std::fmt::{self, self}`. The existing E0252 ("name defined multiple times") provides sufficient guidance. - **E0431**: Previously emitted for `use {self [as name]};` and `use ::{self [as name]};`. These patterns are now allowed or denied but with new clearer errors. - For `use {self as name};` and `use ::{self as name};` (in edition 2015), they are allowed now and equivalent to `use crate as name`; - For `use {self};` and `use ::{self};` (in edition 2015) without renaming, they are equivalent to `use crate;`, the new clearer error suggests adding an explicit rename. - For `use ::{self [as name]};` after edition 2015, it is equivalent to `use ${extern-prelude} [as name];`, it is denied with new errors. ##### Future We plan to remove error [E0429](https://doc.rust-lang.org/stable/error_codes/E0429.html#error-code-e0429) and support `self` at the end of paths (rust-lang#146972 (comment)). This language extension and lint for redundant `::self` instead of hard error `E0429` will be landed separately in the future. --- Fixes rust-lang#29036 Fixes rust-lang#35612 Fixes rust-lang#37156 Fixes rust-lang#146967 Fixes rust-lang#149811 r? petrochenkov
View all comments
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]};. These patterns are now allowed or denied but with new clearer errors.use {self as name};anduse ::{self as name};(in edition 2015), they are allowed now and equivalent touse crate as name;use {self};anduse ::{self};(in edition 2015) without renaming, they are equivalent touse crate;, the new clearer error suggests adding an explicit rename.use ::{self [as name]};after edition 2015, it is equivalent touse ${extern-prelude} [as name];, it is denied with new errors.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