Skip to content

Conversation

@mu001999
Copy link
Contributor

@mu001999 mu001999 commented Sep 24, 2025

Reference PR:

Description:

  • Make imports consistent, self/super/crate/$crate can be imported with renaming now
    • Allow use self/super/crate/$crate as name; and also use super/crate/$crate::{self as name};
    • Deny use self/super/crate/$crate; and also use super/crate/$crate::{self};
    • Deny use ::self;, use ::{self};, use ::self as name; and use ::{self as name};
  • Proper error messages, and E0430 and E0431 are no longer emitted now
    • [E0430]: self import can only appear once in an import list was emitted before when std::fmt::{self, self}, but the emitted [E0252]: the name fmt is defined multiple times is good enough
    • [E0431]: self import can only appear in an import list with a non-empty prefix was emiited before when use {self as name};, now use {self as name}; is allowed; for use {self};, it's denied because it lacks renaming and will emit imports need to be explicitly named with suggesting renaming.

Fixes #146967

r? petrochenkov

@rustbot
Copy link
Collaborator

rustbot commented Sep 24, 2025

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.

@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
ehuss added a commit to ehuss/reference that referenced this pull request Sep 24, 2025
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.
@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.

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

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

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

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

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

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

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

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

This comment has been minimized.

@mu001999 mu001999 force-pushed the fix/use-dollar-crate branch from 30a19ad to e181d80 Compare October 26, 2025 14:26
@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the fix/use-dollar-crate branch from e181d80 to 3ea33a4 Compare October 28, 2025 15:52
@rust-log-analyzer

This comment has been minimized.

@traviscross traviscross added T-lang Relevant to the language team needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. labels Oct 28, 2025
@mu001999 mu001999 force-pushed the fix/use-dollar-crate branch from 3ea33a4 to 8b21630 Compare October 31, 2025 14:50
@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the fix/use-dollar-crate branch from 8b21630 to dad31aa Compare November 1, 2025 08:17
@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the fix/use-dollar-crate branch from dad31aa to e317ae4 Compare November 1, 2025 10:58
@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the fix/use-dollar-crate branch from e317ae4 to b13c316 Compare November 1, 2025 13:27
@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the fix/use-dollar-crate branch from b13c316 to 3edfefd Compare November 1, 2025 14:53
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the fix/use-dollar-crate branch 2 times, most recently from 6d5ea32 to 3edfefd Compare November 1, 2025 18:00
@mu001999 mu001999 force-pushed the fix/use-dollar-crate branch from 5113fc0 to 42a9210 Compare November 1, 2025 18:06
@mu001999 mu001999 changed the title Disable use $crate::{self} like use $crate Support importing path-segment keyword with renaming Nov 2, 2025
@mu001999 mu001999 marked this pull request as ready for review November 2, 2025 05:16
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 2, 2025
@mu001999
Copy link
Contributor Author

mu001999 commented Nov 2, 2025

@rustbot ready

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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. 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. T-lang Relevant to the language team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

use $crate::{self}; should not be accepted

6 participants