7

Don't document impossible to call default trait items on impls by compiler-error...

 2 years ago
source link: https://github.com/rust-lang/rust/pull/100221
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Conversation

Member

@compiler-errors compiler-errors commented 13 days ago

edited

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.

jder reacted with heart emoji All reactions

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

13 days ago

Collaborator

rust-highfive commented 13 days ago

r? @lcnr

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

rust-highfive

added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label

13 days ago

Member

Author

compiler-errors commented 13 days ago

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

Contributor

lcnr commented 13 days ago

the impl looks good, leaving the final review to rustdoc

r? rustdoc

Contributor

notriddle commented 12 days ago

edited

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.

compiler-errors and camelid reacted with thumbs up emoji All reactions

Member

@camelid camelid left a comment

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.

All reactions

Member

camelid commented 12 days ago

@bors r=lcnr,notriddle,camelid

compiler-errors reacted with heart emoji All reactions

Contributor

bors commented 12 days ago

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

It is now in the queue for this repository.

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

12 days ago

Member

camelid commented 12 days ago

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 reacted with thumbs up emoji All reactions

Member

Author

compiler-errors commented 12 days ago

edited

@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
camelid reacted with thumbs up emoji All reactions

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

Milestone

1.65.0

Development

Successfully merging this pull request may close these issues.

8 participants

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK