Skip to content

Allow trailing self in more contexts#155137

Open
mu001999 wants to merge 5 commits intorust-lang:mainfrom
mu001999-contrib:self-at-end
Open

Allow trailing self in more contexts#155137
mu001999 wants to merge 5 commits intorust-lang:mainfrom
mu001999-contrib:self-at-end

Conversation

@mu001999
Copy link
Copy Markdown
Member

@mu001999 mu001999 commented Apr 11, 2026

Reference PR:

View all comments

As a follow-up PR to #152996, after this PR:

  1. Trailing self can appear in paths
  2. E0429 will be no longer emitted, use ...::self [as target]; will be equivalent to use ...::{self [as target]};

r? petrochenkov

@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 Apr 11, 2026
Comment thread compiler/rustc_resolve/src/build_reduced_graph.rs
Comment thread compiler/rustc_resolve/src/ident.rs Outdated
@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 Apr 13, 2026
@mu001999
Copy link
Copy Markdown
Member Author

@rustbot review

@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 Apr 13, 2026
@petrochenkov
Copy link
Copy Markdown
Contributor

@mu001999 could you write a change description for lang team for this PR, like in the previous PRs?
I'll nominate it once it's written and the other comments are addressed.
@rustbot author

@rustbot rustbot 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 Apr 13, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 13, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@mu001999
Copy link
Copy Markdown
Member Author

Description for lang team

This PR implements the last part of the lang team guidance from #146972 (comment).
It relaxes the rules to allow trailing self in more context.

Concretely, after this PR

  1. use foo::self [as bar]; would be accepted and is resolved the same way as use foo::{self [as bar]};, instead of being rejected with E0429.
  2. In non-import paths, trailing self would be accepted as well. This will make things like type E = path::to::Enum::self; and pub(in path::to::Mod::self) accepted.

And technically, this PR will not break existing code.

@mu001999
Copy link
Copy Markdown
Member Author

@rustbot review

@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 Apr 13, 2026
@petrochenkov petrochenkov added S-waiting-on-t-lang Status: Awaiting decision from T-lang I-lang-nominated Nominated for discussion during a lang team meeting. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 14, 2026
@traviscross traviscross added P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang T-lang Relevant to the language team labels Apr 15, 2026
@traviscross
Copy link
Copy Markdown
Contributor

Makes sense to me. Thanks @mu001999 for pushing this along. Let's propose to do it.

@rfcbot fcp merge lang

@rust-rfcbot
Copy link
Copy Markdown
Collaborator

rust-rfcbot commented Apr 15, 2026

Team member @traviscross has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@rust-rfcbot rust-rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Apr 15, 2026
@tmandry
Copy link
Copy Markdown
Member

tmandry commented Apr 15, 2026

@rfcbot reviewed

@traviscross traviscross added I-lang-radar Items that are on lang's radar and will need eventual work or consideration. and removed I-lang-nominated Nominated for discussion during a lang team meeting. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang labels Apr 15, 2026
@rust-bors

This comment has been minimized.

@rustbot

This comment was marked as resolved.

@rustbot

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot

This comment has been minimized.

traviscross added a commit to rust-lang/reference that referenced this pull request Apr 20, 2026
The Reference says that `self` can only appear as the first segment of
a path.  Further, the `use` chapter describes `{self}` brace syntax as
the way to bind the parent entity of a `use` path under its own name.

In rust-lang/rust#155137, we're relaxing these restrictions: `self`
may now also appear as the last segment of a path (preceded by `::`)
as long as the preceding path resolves to a module, enumeration,
or trait.  In a `use` path, `use P::self [as name]` is equivalent
to `use P::{self [as name]}`.  In non-`use` paths, forms such as
`type Ty = P::self` and `pub(in P::self)` are now accepted.

Let's update the Reference to reflect this.
@traviscross
Copy link
Copy Markdown
Contributor

Reference PR:

cc @rust-lang/lang-docs @rust-lang/fls

@rust-bors

This comment has been minimized.

@rustbot

This comment has been minimized.

@rust-rfcbot rust-rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Apr 25, 2026
@rust-rfcbot
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 mu001999 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-t-lang Status: Awaiting decision from T-lang labels Apr 26, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 27, 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.

@rust-log-analyzer

This comment has been minimized.

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

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. 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 to-announce Announce this issue on triage meeting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants