Skip to content

Document trailing self in paths#2237

Open
traviscross wants to merge 1 commit intomasterfrom
TC/trailing-self-in-paths
Open

Document trailing self in paths#2237
traviscross wants to merge 1 commit intomasterfrom
TC/trailing-self-in-paths

Conversation

@traviscross
Copy link
Copy Markdown
Contributor

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.

cc @ehuss @mu001999

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.
@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Apr 20, 2026
@traviscross traviscross added the S-waiting-on-stabilization Waiting for a stabilization PR to be merged in the main Rust repository label Apr 20, 2026
Copy link
Copy Markdown
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@traviscross traviscross removed the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Apr 22, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 27, 2026
…trochenkov

Allow trailing `self` in more contexts

Reference PR:

- rust-lang/reference#2237

As a follow-up PR to rust-lang#152996, after this PR:
1. Trailing `self` can appear in paths
2. [E0429](https://doc.rust-lang.org/stable/error_codes/E0429.html#error-code-e0429) will be no longer emitted, `use ...::self [as target];` will be equivalent to `use ...::{self [as target]};`

r? petrochenkov
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 27, 2026
…trochenkov

Allow trailing `self` in more contexts

Reference PR:

- rust-lang/reference#2237

As a follow-up PR to rust-lang#152996, after this PR:
1. Trailing `self` can appear in paths
2. [E0429](https://doc.rust-lang.org/stable/error_codes/E0429.html#error-code-e0429) will be no longer emitted, `use ...::self [as target];` will be equivalent to `use ...::{self [as target]};`

r? petrochenkov
rust-timer added a commit to rust-lang/rust that referenced this pull request Apr 28, 2026
Rollup merge of #155137 - mu001999-contrib:self-at-end, r=petrochenkov

Allow trailing `self` in more contexts

Reference PR:

- rust-lang/reference#2237

As a follow-up PR to #152996, after this PR:
1. Trailing `self` can appear in paths
2. [E0429](https://doc.rust-lang.org/stable/error_codes/E0429.html#error-code-e0429) will be no longer emitted, `use ...::self [as target];` will be equivalent to `use ...::{self [as target]};`

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

Labels

S-waiting-on-stabilization Waiting for a stabilization PR to be merged in the main Rust repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants