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

rustdoc: Add support for #[rustc_must_implement_one_of] #99235

Conversation

WaffleLapkin
Copy link
Member

This PR adds support for #[rustc_must_implement_one_of] attribute added in #92164. There is a desire to eventually use this attribute of Read, so making it show up in docs is a good thing.

I "stole" the styling from cfg notes, not sure what would be a proper styling. Currently it looks like this:
2022-07-14_15-00

Code to reproduce

#![feature(rustc_attrs)]

#[rustc_must_implement_one_of(a, b)]
pub trait Trait {
    fn req();
    fn a(){ Self::b() }
    fn b(){ Self::a() }
}

@rustbot
Copy link
Collaborator

rustbot commented Jul 14, 2022

Some changes occurred in HTML/CSS themes.

cc @GuillaumeGomez

Some changes occurred in src/librustdoc/clean/types.rs

cc @camelid

Some changes occurred in HTML/CSS/JS.

cc @GuillaumeGomez, @Folyd, @jsha

A change occurred in the Ayu theme.

cc @Cldfire

@rustbot rustbot added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Jul 14, 2022
@rust-highfive
Copy link
Collaborator

r? @GuillaumeGomez

(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 Jul 14, 2022
@@ -216,6 +216,7 @@ pub(crate) fn build_external_trait(cx: &mut DocContext<'_>, did: DefId) -> clean
let (generics, supertrait_bounds) = separate_supertrait_bounds(generics);
let is_auto = cx.tcx.trait_is_auto(did);
clean::Trait {
def_id: did,
Copy link
Member

Choose a reason for hiding this comment

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

I wonder: if we have the trait DefId, I think most (if not all) other fields can be computed on demand, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably? What is the purpose of clean types anyway? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Types "cleaned up" for rustdoc use. :)

Copy link
Member Author

Choose a reason for hiding this comment

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

It just feels (from an outside perspective) that a lot of this can be replaced by DefId newtypes + getters 😅

Copy link
Member

Choose a reason for hiding this comment

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

unsafety or is_auto for example. :)

Well, can be done later on.

@GuillaumeGomez
Copy link
Member

Also: please add a test in src/test/rustdoc to ensure the attribute is generated in the HTML as expected.

@rust-log-analyzer

This comment has been minimized.

@fmease
Copy link
Member

fmease commented Jul 14, 2022

Slightly off-topic: For T-rustdoc reviewers and for future reference, this is how the equivalent feature in Haskell ({-# MINIMAL … #-}) looks like in the documentation generated by Haddock:

haddock_minimal

@WaffleLapkin WaffleLapkin force-pushed the rustdoc_implement_support_for_must_implement branch from df48600 to fd980c0 Compare July 17, 2022 16:58
@WaffleLapkin
Copy link
Member Author

Took me a while to figure out how to do rustdoc tests, but I added the test 😄

@rust-log-analyzer

This comment has been minimized.

if let Some(list) = must_implement_one_of_functions.as_deref() {
write!(
w,
"<div class=\"stab must_implement\">At least one of {} methods is required.</div>",
Copy link
Member

Choose a reason for hiding this comment

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

There can be one method right? If so, the s at the end of methods should be conditional.

Copy link
Member

Choose a reason for hiding this comment

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

Also, can you add backticks around each method name please? Makes it easier to read it in a console.

Copy link
Member Author

Choose a reason for hiding this comment

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

There can be one method right? If so, the s at the end of methods should be conditional.

No, there are always at least two methods.

Copy link
Member

Choose a reason for hiding this comment

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

Oh indeed. So my first comment can be ignored. Remains the second one. ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

Like that a81b4304e0d5668e74fd62443faf44da8a2083c8?

Copy link
Member

Choose a reason for hiding this comment

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

Yup!

@rust-log-analyzer

This comment has been minimized.

@@ -158,6 +158,7 @@ details.undocumented > summary::before {
.stab.empty-impl { background: #FFF5D6; border-color: #FFC600; }
.stab.unstable { background: #FFF5D6; border-color: #FFC600; }
.stab.deprecated { background: #ffc4c4; border-color: #db7b7b; }
.stab.must_implement { background: #F3DFFF; border-color: #b07bdb; }
Copy link
Member

Choose a reason for hiding this comment

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

You need to add this into ayu.css as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

It was already there though. Adding .stab.must_implement{} fixed the issue, seems like a bug in the checker...

Copy link
Member

Choose a reason for hiding this comment

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

No, the rule isn't the same so to speak. They needed to be all split (hence why it was unhappy). The joy of CSS. :)

@GuillaumeGomez
Copy link
Member

Looks all good to me. Please add the missing CSS rule in the ayu theme and it should be good to go!

@bors
Copy link
Contributor

bors commented Jul 22, 2022

☔ The latest upstream changes (presumably #99598) made this pull request unmergeable. Please resolve the merge conflicts.

@WaffleLapkin WaffleLapkin force-pushed the rustdoc_implement_support_for_must_implement branch from a81b430 to 7f1af42 Compare July 24, 2022 12:49
@rust-log-analyzer

This comment has been minimized.

@WaffleLapkin
Copy link
Member Author

Can someone explain why the tests fail/how to fix them? I don't really get gui tests 😅

@GuillaumeGomez
Copy link
Member

All the GUI tests are failing because there is a change in the body width. Basically, you broke the layout. 😆

@GuillaumeGomez
Copy link
Member

Thanks!

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jul 26, 2022

📌 Commit ed8c2c2 has been approved by GuillaumeGomez

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 Jul 26, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 26, 2022
…askrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#99235 (rustdoc: Add support for `#[rustc_must_implement_one_of]`)
 - rust-lang#99716 (remove useless mut from examples)
 - rust-lang#99724 (Fix some broken link fragments.)
 - rust-lang#99729 (Remove unused tuple fields)
 - rust-lang#99757 (Make `transmute_copy` docs read better)
 - rust-lang#99758 (remove useless `#[allow]` in a test)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 811b4b8 into rust-lang:master Jul 26, 2022
@rustbot rustbot added this to the 1.64.0 milestone Jul 26, 2022
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants