Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 9, 2022

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Aug 7, 2022

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.

@rustbot rustbot 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
Collaborator

r? @lcnr

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

@rust-highfive rust-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
Member Author

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

@lcnr
Copy link
Contributor

lcnr commented Aug 7, 2022

the impl looks good, leaving the final review to rustdoc

r? rustdoc

@rust-highfive rust-highfive assigned GuillaumeGomez and unassigned lcnr Aug 7, 2022
@notriddle
Copy link
Contributor

notriddle commented Aug 7, 2022

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.

Copy link
Member

@camelid camelid left a comment

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
Member

camelid commented Aug 8, 2022

@bors r=lcnr,notriddle,camelid

@bors
Copy link
Contributor

bors commented Aug 8, 2022

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

It is now in the queue for this repository.

@bors bors 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
Member

camelid commented Aug 8, 2022

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:

pub struct Bar([u8]);

impl Bar {
    fn needs_sized(&self) where Self: 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
Copy link
Member Author

compiler-errors commented Aug 8, 2022

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

trait Foo {
  fn needs_sized() where Self: Sized;
}

struct Unsized([u8]);

impl Foo for Unsized {
  fn needs_sized() where Self: 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

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:master Aug 9, 2022
@rustbot rustbot 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 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-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.
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