Uh oh!
There was an error while loading. Please reload this page.
Support importing path-segment keyword with renaming - #146972
Conversation
rustbot
commented
Sep 24, 2025
Failed to set assignee to
|
Uh oh!
There was an error while loading. Please reload this page.
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
49c425dCompareuse $crate::{self} like use $crate49c425d to
d0d3a9dCompare
This comment has been minimized.
This comment has been minimized.
d0d3a9d to
c8526a5Compare
This comment has been minimized.
This comment has been minimized.
c8526a5 to
db9bb42Compare
This comment has been minimized.
This comment has been minimized.
df75a52 to
96820faCompare
This comment has been minimized.
This comment has been minimized.
96820fa to
1473c4cCompare
This comment has been minimized.
This comment has been minimized.
1473c4c to
e0d5fa0Compare
This comment has been minimized.
This comment has been minimized.
e0d5fa0 to
4c38159Compare
This comment has been minimized.
This comment has been minimized.
4c38159 to
aca5e4eCompare
This comment has been minimized.
This comment has been minimized.
aca5e4e to
30a19adCompare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@traviscross Aligned now and you can see the changed test and result in the last commit (e2f18e7) |
This comment has been minimized.
This comment has been minimized.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
traviscross
commented
Feb 6, 2026
rust-rfcbot
commented
Feb 6, 2026
🔔 This is now entering its final comment period, as per the review above. 🔔 |
This comment has been minimized.
This comment has been minimized.
mu001999
commented
Feb 6, 2026
Spurious failure |
This comment has been minimized.
This comment has been minimized.
rust-rfcbot
commented
Feb 16, 2026
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. |
traviscross
commented
Feb 16, 2026
@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.
rustbot
commented
Feb 20, 2026
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. |
ehuss
commented
Feb 20, 2026
The documentation should be ready now. @petrochenkov Do you want to give this a final review? |
petrochenkov
commented
Feb 20, 2026
Yay, finally. |
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};What is denied after this PR
Importing
$cratewithout renaming, i.e.use $crate::{self};, is now no longer permitted (#146967).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 self as name;anduse crate as name;use {self};anduse ::{self};(in edition 2015) without renaming, they are equivalent touse self;anduse 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