Skip to content

rustdoc: Render impl restriction#157310

Open
CoCo-Japan-pan wants to merge 2 commits into
rust-lang:mainfrom
CoCo-Japan-pan:render-impl-restriction
Open

rustdoc: Render impl restriction#157310
CoCo-Japan-pan wants to merge 2 commits into
rust-lang:mainfrom
CoCo-Japan-pan:render-impl-restriction

Conversation

@CoCo-Japan-pan
Copy link
Copy Markdown
Contributor

@CoCo-Japan-pan CoCo-Japan-pan commented Jun 2, 2026

According to the Zulip conversation, this PR implements the rendering of impl restrictions.
Following the pattern used for #[rustc_must_implement_one_of], this adds an information note saying, "This trait cannot be implemented outside <crate-name>".
When --document-private-items is passed, the note instead says, "This trait cannot be implemented outside <path-to-module>".
The screenshots show the generated documentation for the following code:

pub mod inner {
    pub impl(self) trait Bar {}
}

in a crate c. The latter image corresponds to the case where --document-private-items is passed.
Tracking issue: #105077

r? @Urgau
cc @jhpratt

screenshot document-private-screenshot

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Jun 2, 2026
@Urgau
Copy link
Copy Markdown
Member

Urgau commented Jun 2, 2026

cc @GuillaumeGomez

Comment thread src/librustdoc/html/render/print_item.rs Outdated
Comment thread src/librustdoc/html/render/print_item.rs
Copy link
Copy Markdown
Member

@GuillaumeGomez GuillaumeGomez left a comment

Choose a reason for hiding this comment

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

Apart from from my two comments, looks all good to me, well done!

View changes since this review

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

rustbot commented Jun 2, 2026

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

Comment thread src/librustdoc/html/render/print_item.rs Outdated
@CoCo-Japan-pan CoCo-Japan-pan force-pushed the render-impl-restriction branch from f4e407f to 5358c2f Compare June 2, 2026 15:23
@GuillaumeGomez
Copy link
Copy Markdown
Member

Thanks! r=me once CI is happy.

@bors delegate

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Jun 2, 2026

✌️ @CoCo-Japan-pan, you can now approve this pull request!

If @GuillaumeGomez told you to "r=me" after making some further change, then please make that change and post @bors r=GuillaumeGomez.

View changes since this delegation.

@Urgau
Copy link
Copy Markdown
Member

Urgau commented Jun 2, 2026

@bors r=GuillaumeGomez,jhpratt,Urgau

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Jun 2, 2026

📌 Commit 5358c2f has been approved by GuillaumeGomez,jhpratt,Urgau

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 5. This pull request will be tested once the tree is reopened.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 2, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 2, 2026
…tion, r=GuillaumeGomez,jhpratt,Urgau

rustdoc: Render `impl` restriction

According to the [Zulip conversation](https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/Documenting.20.60impl.60.20restrictions/with/598960498), this PR implements the rendering of `impl` restrictions.
Following the pattern used for `#[rustc_must_implement_one_of]`, this adds an information note saying, "This trait cannot be implemented outside \<crate-name\>".
When `--document-private-items` is passed, the note instead says, "This trait cannot be implemented outside \<path-to-module\>".
The screenshots show the generated documentation for the following code:
```rust
pub mod inner {
    pub impl(self) trait Bar {}
}
```
in a crate `c`. The latter image corresponds to the case where `--document-private-items` is passed.
Tracking issue: rust-lang#105077

r? @Urgau
cc @jhpratt

<img width="920" height="309" alt="screenshot" src="https://github.com/user-attachments/assets/586c97d6-0f41-41de-9673-eaf12b96c4a1" />
<img width="902" height="316" alt="document-private-screenshot" src="https://github.com/user-attachments/assets/56aedc38-bd05-4ece-885a-8d928a59089c" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants