Skip to content

Don't document impossible to call default trait items on impls - #100221

Merged
bors merged 1 commit into
rust-lang:masterfrom
compiler-errors:impossible-trait-items
Aug 9, 2022
Merged

Don't document impossible to call default trait items on impls#100221
bors merged 1 commit into
rust-lang:masterfrom
compiler-errors:impossible-trait-items

Conversation

@compiler-errors

@compiler-errorscompiler-errors commented Aug 7, 2022

Copy link
Copy Markdown
Contributor

Closes#100176

This only skips documenting default trait items on impls, not ones that are written inside the impl block. This is a conservative approach, since I think we should document all items written in an impl block (I guess unless hidden or whatever), but the existence of this new query I added makes this easy to extend to other rustdoc cases.

@rustbotrustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Aug 7, 2022
@rust-highfive

Copy link
Copy Markdown
Contributor

r? @lcnr

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 7, 2022
@compiler-errors

Copy link
Copy Markdown
ContributorAuthor

cc @notriddle, would appreciate a review on the rustdoc part!

Comment threadcompiler/rustc_trait_selection/src/traits/mod.rs Outdated
@lcnr

lcnr commented Aug 7, 2022

Copy link
Copy Markdown
Contributor

the impl looks good, leaving the final review to rustdoc

r? rustdoc

@notriddle

notriddle commented Aug 7, 2022

Copy link
Copy Markdown
Contributor

The code seems fine to me, but I’d like confirmation from at least one other rustdoc team member that this is the right solution at all. That we actually want to hide these methods, instead of doing something else, like slapping a label on them.

@camelidcamelid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems like the right approach to me. From the user's perspective, it's as if the method doesn't exist for that type. I think still displaying the method but adding a label would be more confusing.

@camelid

Copy link
Copy Markdown
Member

@bors r=lcnr,notriddle,camelid

@bors

bors commented Aug 8, 2022

Copy link
Copy Markdown
Collaborator

📌 Commit b3b23aa has been approved by lcnr,notriddle,camelid

It is now in the queue for this repository.

@borsbors 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-review Status: Awaiting review from the assignee but also interested parties. labels Aug 8, 2022
@camelid

Copy link
Copy Markdown
Member

This only skips documenting default trait items on impls, not ones that are written inside the impl block.

Inherent methods with impossible bounds (e.g. Self: Sized) seem to be disallowed by rustc:

pubstructBar([u8]);implBar{fnneeds_sized(&self)whereSelf:Sized{}}
error[[E0277]](https://doc.rust-lang.org/stable/error-index.html#E0277): the size for values of type `[u8]` cannot be known at compilation time
--> src/lib.rs:4:33
|
4 | fn needs_sized(&self) where Self: Sized {}
| ^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: within `Bar`, the trait `Sized` is not implemented for `[u8]`
note: required because it appears within the type `Bar`
--> src/lib.rs:1:12
|
1 | pub struct Bar([u8]);
| ^^^
= help: see issue #48214

@compiler-errors

compiler-errors commented Aug 8, 2022

Copy link
Copy Markdown
ContributorAuthor

@camelid: I actually meant trait items provided by an impl explicitly, like:

traitFoo{fnneeds_sized()whereSelf:Sized;}structUnsized([u8]);implFooforUnsized{fnneeds_sized()whereSelf:Sized{}}

But that's also impossible to write currently, lol

error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> src/lib.rs:8:26
|
8 | fn needs_sized() where Self: Sized {}
| ^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: within `Unsized`, the trait `Sized` is not implemented for `[u8]`
note: required because it appears within the type `Unsized`
--> src/lib.rs:5:8
|
5 | struct Unsized([u8]);
| ^^^^^^^
= help: see issue #48214
= help: [add `#![feature(trivial_bounds)]`](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#) to the crate attributes to enable

@Dylan-DPCDylan-DPC mentioned this pull request Aug 9, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 9, 2022
Rollup of 7 pull requests
Successful merges:
- rust-lang#96478 (Implement `#[rustc_default_body_unstable]`)
- rust-lang#99787 (Rustdoc-Json: Document HRTB's on DynTrait)
- rust-lang#100181 (add method to get the mutability of an AllocId)
- rust-lang#100221 (Don't document impossible to call default trait items on impls)
- rust-lang#100228 (Don't ICE while suggesting updating item path.)
- rust-lang#100301 (Avoid `&str` to `String` conversions)
- rust-lang#100305 (Suggest adding an appropriate missing pattern excluding comments)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit d910e53 into rust-lang:masterAug 9, 2022
@rustbotrustbot added this to the 1.65.0 milestone Aug 9, 2022
@compiler-errors
compiler-errors deleted the impossible-trait-items branch August 11, 2023 20:03
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trait methods with bounds on Self are shown on types that do not fulfill those bounds

8 participants

@compiler-errors@rust-highfive@lcnr@notriddle@camelid@bors@GuillaumeGomez@rustbot