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

Document the doc attribute #43792

Merged
merged 5 commits into from Aug 12, 2017
Merged

Conversation

steveklabnik
Copy link
Member

cc #42322

@rust-highfive
Copy link
Collaborator

r? @frewsxcv

(rust_highfive has picked a reviewer for you, use r? to override)

@steveklabnik
Copy link
Member Author

I'm missing doc(inline) because I am actually not sure what it does yet!

/cc @rust-lang/docs

Copy link
Contributor

@chordowl chordowl left a comment

Choose a reason for hiding this comment

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

Just a nits, I like it!

its job.

The most basic job of `#[doc]` is to be the way that the text of the documentation
is handled. That is, `///` is syntax sugar for `#[doc]`. This means that these two
Copy link
Contributor

Choose a reason for hiding this comment

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

I find this phrasing (and the repetition of "job") really awkward... how about "The most basic function of #[doc] is to handle the actual documentation text."?

Copy link
Member Author

Choose a reason for hiding this comment

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

sounds good to me!


```rust,ignore
/// This is a doc comment.
#[doc = "This is a doc comment."]
Copy link
Member

Choose a reason for hiding this comment

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

Note that these are not actually the same! The former has a leading space, but the latter does not. This is why the unindent-comments pass exists, and also is the reason #42760 exists.

Copy link
Member Author

Choose a reason for hiding this comment

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

adding in a note

```rust,ignore
#[doc = "This is"]
#[doc = " a "]
#[doc = "doc comment"]
Copy link
Member

Choose a reason for hiding this comment

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

Except collapse-docs will put these all on multiple lines. It's not necessarily the same as ///This is a doc comment, all on one line.

Copy link
Member Author

Choose a reason for hiding this comment

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

right, and then it's markdown that makes them all in one line in the final output. whew.

Copy link
Member

Choose a reason for hiding this comment

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

oh right, markdown joins those lines up anyway >_>;;

Copy link
Member Author

Choose a reason for hiding this comment

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

this should be resolved now

#![doc(html_playground_url = "https://playground.foo.com/")]
```

Now, when you press "run", the button will make a request to this domain.
Copy link
Member

Choose a reason for hiding this comment

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

note that for html_favicon_url, html_logo_url, and html_playground_url, their corresponding items will be missing entirely if they're not given. (i.e. no favicon/no corner logo/no run buttons)

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed


Since primitive types are defined in the compiler, there's no place to attach documentation
attributes. This attribute is used by the standard library to provide a way to generate
documentation for primitive types.
Copy link
Member

Choose a reason for hiding this comment

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

When i was adding the new primitive pages, i wondered whether it would be useful for certain extension crates to include their own primitive pages, in case they implement their traits on the primitives. num comes to mind. Would we want to promote this at all? From what i saw of the code, rustdoc doesn't discriminate based on whether the crate is libstd or not, it just looks for them in the root of the crate and generates the page based on what's there.

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 would be useful for certain extension crates to include their own primitive pages,

Hm, I think I'd want to see how this works before advocating for people to use it. Wouldn't this overwrite the usual primitive page?

Copy link
Member

Choose a reason for hiding this comment

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

What usual primitive page? Some random crate isn't going to include the libstd primitive docs anywhere. I can try this out with num to see how it goes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Consider https://docs.rs/mysql/12.0.2/mysql/struct.Row.html#method.len

the return type is usize, it links to usize's primitive page.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, the links! Yeah, that would totally overwrite those links.

...in fact, it would probably also overwrite those links in any dependent crates, too. I think the thing that populates those links searches from the top down, which means that any overridden links would definitely appear before libstd. Possibly worth investigating, and maybe worth changing, but it's probably not something to encourage in that case. >_>

@steveklabnik
Copy link
Member Author

Updated with the inline and no_inline stuff.

This form of the `doc` attribute lets you control the favicon of your docs.

```rust,ignore
#![doc(html_favicon_url = "https://foo.com/favicon.ico")]
Copy link
Member

Choose a reason for hiding this comment

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

For example URLs in docs you really should use example.com or one of the domains reserved for this: https://en.wikipedia.org/wiki/Example.com.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

the tracking issue.

```rust,ignore
#![doc(issue_tracker_base_url = "https://github.com/foo/foo/issues/")]
Copy link
Member

Choose a reason for hiding this comment

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

Again this should be replaced with https://github.com/rust-lang/rust/issues/ as github.com/foo is a real github account and this attribute is only for std anyway,

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

## `#[doc(hidden)]`

Any item annotated with `#[doc(hidden)]` will not appear in the documentation, unless
the `strip-hidden` pass is removed.
Copy link
Member

Choose a reason for hiding this comment

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

Ideally, this would link to the section in your other PR, but it depends which PR gets shipped first

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, I think we should worry about intra-linking after all the chapters land

@shepmaster shepmaster added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 11, 2017
@frewsxcv
Copy link
Member

looks good to me, great addition to the rustdoc book! 🎉

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Aug 11, 2017

📌 Commit 1e4aaea has been approved by frewsxcv

bors added a commit that referenced this pull request Aug 12, 2017
@bors
Copy link
Contributor

bors commented Aug 12, 2017

⌛ Testing commit 1e4aaea with merge 2fa5340...

@bors
Copy link
Contributor

bors commented Aug 12, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: frewsxcv
Pushing 2fa5340 to master...

@bors bors merged commit 1e4aaea into rust-lang:master Aug 12, 2017
@steveklabnik steveklabnik deleted the rustdoc-directives branch October 25, 2017 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants