GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Support importing path-segment keyword with renaming by mu001999 · Pull Request #146972 · rust-lang/rust

Conversation

@mu001999

@mu001999 mu001999 commented Sep 24, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

View all comments

Reference PR

  • Clarify use $crate restriction reference#2010
  • Document importing path-segment keyword reference#2136

What was FCP'd by lang (up to date)

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};
What is denied after this PR

Importing $crate without renaming, i.e. use $crate::{self};, is now no longer permitted (#146967).

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 self as name; and use crate as name;
    • For use {self}; and use ::{self}; (in edition 2015) without renaming, they are equivalent to use self; and 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 and support self at the end of paths (#146972 (comment)). This language extension and lint for redundant ::self instead of hard error E0429 will be landed separately in the future.


Fixes #29036
Fixes #35612
Fixes #37156
Fixes #146967
Fixes #149811

r? petrochenkov

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

teor2345 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@rustbot

rustbot commented Sep 24, 2025

Copy link
Copy Markdown
Collaborator

Failed to set assignee to [petrochenkov]: invalid assignee

Note: Only org members with at least the repository "read" role, users with write permissions, or people who have commented on the PR may be assigned.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 24, 2025
@rustbot rustbot assigned petrochenkov Sep 24, 2025
ehuss
ehuss reviewed Sep 24, 2025
View reviewed changes
Comment thread compiler/rustc_resolve/messages.ftl Resolved

Uh oh!

There was an error while loading. Please reload this page.

ehuss added a commit to ehuss/reference that referenced this pull request Sep 24, 2025
@ehuss
Clarify use $crate restriction
01e93ed
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.
@ehuss ehuss mentioned this pull request Sep 24, 2025
Clarify use $crate restriction rust-lang/reference#2010
Closed
@mu001999
mu001999 force-pushed the fix/use-dollar-crate branch from ce2578f to 49c425d Compare September 25, 2025 01:54
@mu001999 mu001999 changed the title Emit error UnnamedCrateRootImport also for DollarCrate Disable use $crate::{self} like use $crate Sep 25, 2025
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 26, 2025
@mu001999
mu001999 marked this pull request as draft October 8, 2025 06:43
@mu001999
mu001999 force-pushed the fix/use-dollar-crate branch from 49c425d to d0d3a9d Compare October 9, 2025 03:40
@rust-log-analyzer

This comment has been minimized.

Sign in to view
@mu001999
mu001999 force-pushed the fix/use-dollar-crate branch from d0d3a9d to c8526a5 Compare October 13, 2025 15:10
@rust-log-analyzer

This comment has been minimized.

Sign in to view
@mu001999
mu001999 force-pushed the fix/use-dollar-crate branch from c8526a5 to db9bb42 Compare October 14, 2025 14:40
@rust-log-analyzer

This comment has been minimized.

Sign in to view
@mu001999
mu001999 force-pushed the fix/use-dollar-crate branch 2 times, most recently from df75a52 to 96820fa Compare October 16, 2025 13:28
@rust-log-analyzer

This comment has been minimized.

Sign in to view
@mu001999
mu001999 force-pushed the fix/use-dollar-crate branch from 96820fa to 1473c4c Compare October 16, 2025 15:47
@rust-log-analyzer

This comment has been minimized.

Sign in to view
@mu001999
mu001999 force-pushed the fix/use-dollar-crate branch from 1473c4c to e0d5fa0 Compare October 23, 2025 14:50
@rust-log-analyzer

This comment has been minimized.

Sign in to view
@mu001999
mu001999 force-pushed the fix/use-dollar-crate branch from e0d5fa0 to 4c38159 Compare October 23, 2025 15:42
@rust-log-analyzer

This comment has been minimized.

Sign in to view
@mu001999
mu001999 force-pushed the fix/use-dollar-crate branch from 4c38159 to aca5e4e Compare October 24, 2025 14:49
@rust-log-analyzer

This comment has been minimized.

Sign in to view
@mu001999
mu001999 force-pushed the fix/use-dollar-crate branch from aca5e4e to 30a19ad Compare October 24, 2025 17:22
@mu001999

mu001999 commented Feb 5, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

let me know when the implementation is aligned with this (and please point to the relevant tests)

@traviscross Aligned now and you can see the changed test and result in the last commit (e2f18e7)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rust-log-analyzer

This comment has been minimized.

Sign in to view
traviscross
traviscross reviewed Feb 6, 2026
View reviewed changes
Comment thread compiler/rustc_resolve/src/build_reduced_graph.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread compiler/rustc_resolve/src/build_reduced_graph.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@traviscross

traviscross commented Feb 6, 2026

Copy link
Copy Markdown
Contributor

Thanks for the update.

@rfcbot resolve self-super-behavior

Note that in the Reference PR, we need to somehow capture what @ehuss said here:

What would be the rules after this PR? Given the PR as it is now, I'm thinking adding a new restriction like:

  • :: as the extern prelude cannot be imported.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rust-rfcbot

rust-rfcbot commented Feb 6, 2026

Copy link
Copy Markdown
Collaborator

🔔 This is now entering its final comment period, as per the review above. 🔔

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rust-log-analyzer

This comment has been minimized.

Sign in to view
@mu001999

mu001999 commented Feb 6, 2026

Copy link
Copy Markdown
Member Author

Spurious failure

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rustbot

This comment has been minimized.

Sign in to view
@rust-rfcbot

rust-rfcbot commented Feb 16, 2026

Copy link
Copy Markdown
Collaborator

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 reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@traviscross

traviscross commented Feb 16, 2026

Copy link
Copy Markdown
Contributor

@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.

mu001999 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rust-bors

This comment has been minimized.

Sign in to view
mu001999 added 3 commits February 20, 2026 10:58
@mu001999
Rewrite build_reduced_graph_for_use_tree
58e5475
@mu001999
Recover supporting use std::{io::self}
a348051
@mu001999
Support use self::super as name;
6609e4b
@rustbot

rustbot commented Feb 20, 2026

Copy link
Copy Markdown
Collaborator

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ehuss

ehuss commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

The documentation should be ready now.

@petrochenkov Do you want to give this a final review?

mu001999 reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@petrochenkov

petrochenkov commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

Yay, finally.
@bors r+

mu001999 reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rust-bors

rust-bors Bot commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 6609e4b has been approved by petrochenkov

It is now in the queue for this repository.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JonathanBrouwer JonathanBrouwer mentioned this pull request Feb 20, 2026
Rollup of 9 pull requests #152924
Merged
@mu001999 mu001999 mentioned this pull request Feb 23, 2026
Replacing self overwriting with proper resolution #152996
Merged
@theemathas theemathas mentioned this pull request Feb 23, 2026
super used in the middle of path is incorrectly accepted #152997
Closed
@theemathas theemathas mentioned this pull request Mar 14, 2026
1.95 beta regression: "imports need to be explicitly named" #153851
Closed
@theemathas theemathas mentioned this pull request Mar 24, 2026
[ICE]: reachable Public > nominal Restricted #154295
Closed
@BoxyUwU BoxyUwU mentioned this pull request Apr 2, 2026
Draft release notes for 1.95 #154711
Closed
@mu001999 mu001999 mentioned this pull request Apr 13, 2026
Allow trailing self in more contexts #155137
Merged
@tshepang tshepang mentioned this pull request May 6, 2026
document missing import restrictions rust-lang/fls#694
Merged
@petrochenkov petrochenkov mentioned this pull request May 9, 2026
resolve: Set correct parent and expansion for self declarations #156353
Merged
@AhoyISki AhoyISki mentioned this pull request May 13, 2026
[Bug]: cargo run fails on stable Rust 1.94 with $crate import errors in txt! AhoyISki/duat#58
Closed
1 task done
@github-actions github-actions Bot mentioned this pull request Sep 14, 2026
Toolchain upgrade to nightly-2026-08-21 flux-rs/flux#1759
Merged
@ioquatix ioquatix mentioned this pull request Nov 9, 2026
Declare Rust 1.88 as the minimum supported version and check it in CI. base-rs/bake-releases-cargo#11
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@traviscross traviscross traviscross left review comments
@petrochenkov petrochenkov petrochenkov approved these changes
+1 more reviewer
@ehuss ehuss ehuss left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@petrochenkov petrochenkov

Labels

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team to-announce Announce this issue on triage meeting

Projects

None yet

Milestone

1.95.0

Development

Successfully merging this pull request may close these issues.

Restrictions on imports of $crate are illogical use $crate::{self}; should not be accepted Should use super::{self, ...} work? self and super behave inconsistently in use statements and as module names Can't import super

Uh oh!

There was an error while loading. Please reload this page.

12 participants

@mu001999 @rustbot @rust-log-analyzer @petrochenkov @craterbot @bors @traviscross @rust-rfcbot @tmandry @nikomatsakis @joshtriplett @ehuss
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.