Skip to content

Document trailing self in paths#2237

Merged
ehuss merged 1 commit intomasterfrom
TC/trailing-self-in-paths
Apr 30, 2026
Merged

Document trailing self in paths#2237
ehuss merged 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
@ehuss ehuss enabled auto-merge April 30, 2026 02:40
@ehuss ehuss added this pull request to the merge queue Apr 30, 2026
Merged via the queue into master with commit 581920f Apr 30, 2026
10 of 12 checks passed
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request May 4, 2026
Update books

## rust-lang/reference

4 commits in 8c88f9d0bdd75ffdc0691676d83212ae22a18cee..581920f9109f141b88b860b3e1e8359e3896a150
2026-04-30 02:40:57 UTC to 2026-04-28 16:48:51 UTC

- Document trailing `self` in paths (rust-lang/reference#2237)
- add trailing comma (to follow style guidelines) (rust-lang/reference#2244)
- Doc: Add the LoongArch stabilized target features (rust-lang/reference#2217)
- typo (rust-lang/reference#2241)
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request May 5, 2026
Update books

## rust-lang/reference

4 commits in 8c88f9d0bdd75ffdc0691676d83212ae22a18cee..581920f9109f141b88b860b3e1e8359e3896a150
2026-04-30 02:40:57 UTC to 2026-04-28 16:48:51 UTC

- Document trailing `self` in paths (rust-lang/reference#2237)
- add trailing comma (to follow style guidelines) (rust-lang/reference#2244)
- Doc: Add the LoongArch stabilized target features (rust-lang/reference#2217)
- typo (rust-lang/reference#2241)
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