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 doc snippets for trait impls, with a read more link #33679

Merged
merged 4 commits into from
May 21, 2016

Conversation

Manishearth
Copy link
Member

The read more link only appears if the documentation is more than one line long.

screenshot from 2016-05-17 06 54 14

It currently does not appear on non-defaulted methods, since you can document them directly. I could make it so that default documentation gets forwarded if regular docs don't exist.

Fixes #33672

r? @alexcrichton

cc @steveklabnik

@Manishearth
Copy link
Member Author

Added support for a fallback to short docs

The following code produces the pictured docs:

pub struct Foo<'a>(&'a str);

impl<'a> Iterator for Foo<'a> {
  type Item = &'a str;
  fn next(&mut self) -> Option<&'a str> {
    Some(self.0)
  }

  /// All your docs are
  ///
  /// belong to us
  fn size_hint(&self) -> (usize, Option<usize>) {
   (1,None)
  }
}

screenshot from 2016-05-17 07 30 52

Note that the show more link isn't shown on Item, since it has only one line of docs. size_hint has an overridden impl so its docs are shown in full. Everything else defaults to the regular Iterator docs.

@Manishearth
Copy link
Member Author

The formatting for "read more" could probably be improved, suggestions?

@nrc
Copy link
Member

nrc commented May 17, 2016

Why have the +/- expand box and "read more"? Why not show all the description, but have it hidden by default?

@Manishearth
Copy link
Member Author

That's another option, I guess. Is there anything else we collapse by default?

@pcwalton
Copy link
Contributor

pcwalton commented May 17, 2016

@Manishearth How about putting "Read more" on the same line to save space?

"Consumes the iterator, returning the last element. More..."

@Manishearth
Copy link
Member Author

That can work. I didn't do it because it requires some markdown splicing, but that's no big deal

@Manishearth
Copy link
Member Author

I don't have a preference of any one of the suggestions -- @alexcrichton, do you? Both are easy to implement.

@GuillaumeGomez
Copy link
Member

Why have the +/- expand box and "read more"? Why not show all the description, but have it hidden by default?

I like it.

@Manishearth: How do you know it's only one line?

@Manishearth
Copy link
Member Author

@Manishearth: How do you know it's only one line?

That's how the snippet function works

@GuillaumeGomez
Copy link
Member

That's how the snippet function works

I guess it's based on the characters' number. I don't really like this if this is really the case.

@Manishearth
Copy link
Member Author

I don't know what you mean? I think it just extracts the first line, in a markdown-aware way. It's already used for documenting modules and in search results

@GuillaumeGomez
Copy link
Member

I thought you said that if the description was only one short line, no need to hide it. And I was wondering how you decided if it was short.

@Manishearth
Copy link
Member Author

I don't decide if it's short. The heuristic is if it's a single line, I don't show a "Read more" link - See https://github.com/rust-lang/rust/pull/33679/files#diff-05c3c8b7c08a25764218b8c18d8204b7R1672

@alexcrichton
Copy link
Member

@Manishearth yeah I like @pcwalton's suggestion of placing the link on the same line to cut down on space (that's why these links were omitted in the first place). Also, could you build libstd docs and provide a link so we can browse around as well? It'd probably help to see what this look like in practice as well.

Nice idea though!

@mitaa
Copy link
Contributor

mitaa commented May 18, 2016

Perhaps the "read more" could be expanded in-place instead of linking to another page?

@Manishearth
Copy link
Member Author

@Manishearth Manishearth force-pushed the rustdoc-readmore-impls branch from b78025f to 74633b0 Compare May 18, 2016 18:31
@GuillaumeGomez
Copy link
Member

@Manishearth: Like this it's just great! Thanks a lot for this!

@alexcrichton
Copy link
Member

Looks good to me! Can you also add a test to ensure that the longer form docs are omitted? That is, if there's multiple lines, none but the first show up in the output

@Manishearth
Copy link
Member Author

Done

@Manishearth Manishearth force-pushed the rustdoc-readmore-impls branch 2 times, most recently from 24502d3 to da15112 Compare May 19, 2016 08:08
@alexcrichton
Copy link
Member

@bors: r+ da15112c825beb8792ab9a26c8d033c1d7bbc0d3

@bors
Copy link
Contributor

bors commented May 19, 2016

⌛ Testing commit da15112 with merge 7c4159c...

@bors
Copy link
Contributor

bors commented May 19, 2016

💔 Test failed - auto-linux-64-opt-rustbuild

@Manishearth
Copy link
Member Author

Ah, that was a legit error, I wasn't ignoring static methods for Deref.

There are a bunch of failures for internals docs though (haven't investigated yet, it could just be this bug)

rustc_typeck/check/regionck/struct.Rcx.html:94: broken link fragment  `#method.visit_ident` pointing to `rustc_typeck/hir/intravisit/trait.Visitor.html`
rustc_typeck/check/regionck/struct.Rcx.html:114: broken link fragment  `#method.visit_explicit_self` pointing to `rustc_typeck/hir/intravisit/trait.Visitor.html`
std/ffi/struct.CString.html:181: broken link fragment  `#method.from_ptr` pointing to `std/ffi/struct.CString.html`
std/ffi/struct.CString.html:182: broken link fragment  `#method.from_bytes_with_nul` pointing to `std/ffi/struct.CString.html`
std/ffi/struct.CString.html:183: broken link fragment  `#method.from_bytes_with_nul_unchecked` pointing to `std/ffi/struct.CString.html`
rustc/ty/index.html:55: broken link - rustc/ty/sty/BuiltinBound/index.html
rustc/ty/index.html:57: broken link - rustc/ty/sty/BuiltinBound/index.html
rustc/ty/index.html:59: broken link - rustc/ty/sty/BuiltinBound/index.html
rustc/ty/index.html:61: broken link - rustc/ty/sty/BuiltinBound/index.html
syntax/parse/token/struct.InternedString.html:68: broken link - syntax/parse/token/primitive.char.html
syntax/parse/token/struct.InternedString.html:128: broken link - syntax/parse/token/primitive.u8.html
syntax/parse/token/struct.InternedString.html:402: broken link - syntax/parse/token/primitive.char.html
syntax/parse/token/struct.InternedString.html:404: broken link - syntax/parse/token/primitive.char.html
syntax/parse/token/struct.InternedString.html:429: broken link - syntax/parse/token/primitive.char.html
syntax/parse/token/struct.InternedString.html:441: broken link - syntax/parse/token/primitive.char.html
syntax/parse/token/struct.InternedString.html:445: broken link - syntax/parse/token/primitive.char.html
syntax/parse/token/struct.InternedString.html:446: broken link - syntax/parse/token/primitive.char.html
syntax/parse/token/struct.InternedString.html:448: broken link - syntax/parse/token/primitive.char.html
syntax/parse/token/struct.InternedString.html:472: broken link - syntax/parse/token/primitive.char.html
syntax/parse/token/struct.InternedString.html:622: broken link - syntax/parse/token/option/enum.Option.html
syntax/parse/token/struct.InternedString.html:624: broken link - syntax/parse/token/primitive.char.html
syntax/parse/token/struct.InternedString.html:656: broken link - syntax/parse/token/option/enum.Option.html
syntax/parse/token/struct.InternedString.html:658: broken link - syntax/parse/token/primitive.char.html
syntax/parse/token/struct.InternedString.html:689: broken link - syntax/parse/token/primitive.char.html
syntax/parse/token/struct.InternedString.html:693: broken link - syntax/parse/token/iter/trait.DoubleEndedIterator.html
syntax/parse/token/struct.InternedString.html:695: broken link - syntax/parse/token/primitive.char.html
syntax/parse/token/struct.InternedString.html:756: broken link - syntax/parse/token/primitive.char.html
syntax/parse/token/struct.InternedString.html:761: broken link - syntax/parse/token/iter/trait.DoubleEndedIterator.html
syntax/parse/token/struct.InternedString.html:791: broken link - syntax/parse/token/primitive.char.html
syntax/parse/token/struct.InternedString.html:801: broken link - syntax/parse/token/iter/trait.DoubleEndedIterator.html
syntax/parse/token/struct.InternedString.html:803: broken link - syntax/parse/token/primitive.char.html
syntax/parse/token/struct.InternedString.html:821: broken link - syntax/parse/token/primitive.char.html
syntax/parse/token/struct.InternedString.html:854: broken link - syntax/parse/token/primitive.char.html
syntax/parse/token/struct.InternedString.html:893: broken link - syntax/parse/token/primitive.char.html
syntax/parse/token/struct.InternedString.html:924: broken link - syntax/parse/token/primitive.char.html
syntax/parse/token/struct.InternedString.html:928: broken link - syntax/parse/token/iter/trait.DoubleEndedIterator.html
syntax/parse/token/struct.InternedString.html:930: broken link - syntax/parse/token/primitive.char.html
syntax/parse/token/struct.InternedString.html:948: broken link - syntax/parse/token/primitive.char.html
syntax/parse/token/struct.InternedString.html:953: broken link - syntax/parse/token/iter/trait.DoubleEndedIterator.html
syntax/parse/token/struct.InternedString.html:974: broken link - syntax/parse/token/primitive.char.html
syntax/parse/token/struct.InternedString.html:978: broken link - syntax/parse/token/iter/trait.DoubleEndedIterator.html
syntax/parse/token/struct.InternedString.html:980: broken link - syntax/parse/token/primitive.char.html
syntax/parse/token/struct.InternedString.html:1004: broken link - syntax/parse/token/primitive.char.html
syntax/parse/token/struct.InternedString.html:1009: broken link - syntax/parse/token/iter/trait.DoubleEndedIterator.html
syntax/parse/token/struct.InternedString.html:1099: broken link - syntax/parse/token/primitive.char.html
syntax/parse/token/struct.InternedString.html:1120: broken link - syntax/parse/token/primitive.char.html
syntax/parse/token/struct.InternedString.html:1142: broken link - syntax/parse/token/primitive.char.html
syntax/parse/token/struct.InternedString.html:1174: broken link - syntax/parse/token/str/trait.FromStr.html
syntax/parse/token/struct.InternedString.html:1177: broken link - syntax/parse/token/str/trait.FromStr.html
syntax/parse/token/struct.InternedString.html:1204: broken link - syntax/parse/token/string/struct.String.html
syntax/parse/token/struct.InternedString.html:1222: broken link - syntax/parse/token/string/struct.String.html
syntax/parse/token/struct.InternedString.html:1254: broken link - syntax/parse/token/string/struct.String.html
syntax/parse/token/struct.InternedString.html:1280: broken link - syntax/parse/token/string/struct.String.html
syntax/util/interner/struct.RcStr.html:58: broken link - syntax/util/interner/primitive.char.html
syntax/util/interner/struct.RcStr.html:118: broken link - syntax/util/interner/primitive.u8.html
syntax/util/interner/struct.RcStr.html:392: broken link - syntax/util/interner/primitive.char.html
syntax/util/interner/struct.RcStr.html:394: broken link - syntax/util/interner/primitive.char.html
syntax/util/interner/struct.RcStr.html:419: broken link - syntax/util/interner/primitive.char.html
syntax/util/interner/struct.RcStr.html:431: broken link - syntax/util/interner/primitive.char.html
syntax/util/interner/struct.RcStr.html:435: broken link - syntax/util/interner/primitive.char.html
syntax/util/interner/struct.RcStr.html:436: broken link - syntax/util/interner/primitive.char.html
syntax/util/interner/struct.RcStr.html:438: broken link - syntax/util/interner/primitive.char.html
syntax/util/interner/struct.RcStr.html:462: broken link - syntax/util/interner/primitive.char.html
syntax/util/interner/struct.RcStr.html:612: broken link - syntax/util/interner/option/enum.Option.html
syntax/util/interner/struct.RcStr.html:614: broken link - syntax/util/interner/primitive.char.html
syntax/util/interner/struct.RcStr.html:646: broken link - syntax/util/interner/option/enum.Option.html
syntax/util/interner/struct.RcStr.html:648: broken link - syntax/util/interner/primitive.char.html
syntax/util/interner/struct.RcStr.html:679: broken link - syntax/util/interner/primitive.char.html
syntax/util/interner/struct.RcStr.html:683: broken link - syntax/util/interner/iter/trait.DoubleEndedIterator.html
syntax/util/interner/struct.RcStr.html:685: broken link - syntax/util/interner/primitive.char.html
syntax/util/interner/struct.RcStr.html:746: broken link - syntax/util/interner/primitive.char.html
syntax/util/interner/struct.RcStr.html:751: broken link - syntax/util/interner/iter/trait.DoubleEndedIterator.html
syntax/util/interner/struct.RcStr.html:781: broken link - syntax/util/interner/primitive.char.html
syntax/util/interner/struct.RcStr.html:791: broken link - syntax/util/interner/iter/trait.DoubleEndedIterator.html
syntax/util/interner/struct.RcStr.html:793: broken link - syntax/util/interner/primitive.char.html
syntax/util/interner/struct.RcStr.html:811: broken link - syntax/util/interner/primitive.char.html
syntax/util/interner/struct.RcStr.html:844: broken link - syntax/util/interner/primitive.char.html
syntax/util/interner/struct.RcStr.html:883: broken link - syntax/util/interner/primitive.char.html
syntax/util/interner/struct.RcStr.html:914: broken link - syntax/util/interner/primitive.char.html
syntax/util/interner/struct.RcStr.html:918: broken link - syntax/util/interner/iter/trait.DoubleEndedIterator.html
syntax/util/interner/struct.RcStr.html:920: broken link - syntax/util/interner/primitive.char.html
syntax/util/interner/struct.RcStr.html:938: broken link - syntax/util/interner/primitive.char.html
syntax/util/interner/struct.RcStr.html:943: broken link - syntax/util/interner/iter/trait.DoubleEndedIterator.html
syntax/util/interner/struct.RcStr.html:964: broken link - syntax/util/interner/primitive.char.html
syntax/util/interner/struct.RcStr.html:968: broken link - syntax/util/interner/iter/trait.DoubleEndedIterator.html
syntax/util/interner/struct.RcStr.html:970: broken link - syntax/util/interner/primitive.char.html
syntax/util/interner/struct.RcStr.html:994: broken link - syntax/util/interner/primitive.char.html
syntax/util/interner/struct.RcStr.html:999: broken link - syntax/util/interner/iter/trait.DoubleEndedIterator.html
syntax/util/interner/struct.RcStr.html:1089: broken link - syntax/util/interner/primitive.char.html
syntax/util/interner/struct.RcStr.html:1110: broken link - syntax/util/interner/primitive.char.html
syntax/util/interner/struct.RcStr.html:1132: broken link - syntax/util/interner/primitive.char.html
syntax/util/interner/struct.RcStr.html:1164: broken link - syntax/util/interner/str/trait.FromStr.html
syntax/util/interner/struct.RcStr.html:1167: broken link - syntax/util/interner/str/trait.FromStr.html
syntax/util/interner/struct.RcStr.html:1194: broken link - syntax/util/interner/string/struct.String.html
syntax/util/interner/struct.RcStr.html:1212: broken link - syntax/util/interner/string/struct.String.html
syntax/util/interner/struct.RcStr.html:1244: broken link - syntax/util/interner/string/struct.String.html
syntax/util/interner/struct.RcStr.html:1270: broken link - syntax/util/interner/string/struct.String.html
rustc_plugin/index.html:88: broken link - /home/manishearth/Mozilla/rust/book/compiler-plugins.html
rustc_trans/middle/const_val/enum.ConstVal.html:53: broken link - rustc_const_math/int/ConstInt/index.html
thread '<main>' panicked at 'found some broken links', main.rs:54
note: Run with `RUST_BACKTRACE=1` for a backtrace.

@Manishearth Manishearth force-pushed the rustdoc-readmore-impls branch from da15112 to 9ce018b Compare May 20, 2016 12:16
@Manishearth
Copy link
Member Author

Fixed.

the internals errors listed above still exist

@alexcrichton
Copy link
Member

@bors: r+ 9ce018b

Manishearth added a commit to Manishearth/rust that referenced this pull request May 21, 2016
… r=alexcrichton

rustdoc: Add doc snippets for trait impls, with a read more link

The read more link only appears if the documentation is more than one line long.

![screenshot from 2016-05-17 06 54 14](https://cloud.githubusercontent.com/assets/1617736/15308544/4c2ba0ce-1bfc-11e6-9add-29de8dc7ac6e.png)

It currently does not appear on non-defaulted methods, since you can document them directly. I could make it so that default documentation gets forwarded if regular docs don't exist.

Fixes rust-lang#33672

r? @alexcrichton

cc @steveklabnik
bors added a commit that referenced this pull request May 21, 2016
Rollup of 7 pull requests

- Successful merges: #33578, #33679, #33743, #33746, #33747, #33750, #33757
- Failed merges:
@bors bors merged commit 9ce018b into rust-lang:master May 21, 2016
@solson
Copy link
Member

solson commented May 24, 2016

Would it be possible to override this with impl-specific documentation for methods? (Is there already an issue for that?)

EDIT: Aha. I was only looking at stable, where this wasn't yet the case.

@Manishearth
Copy link
Member Author

This already happens

@Manishearth Manishearth deleted the rustdoc-readmore-impls branch December 2, 2016 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants