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

Add explanation of main to rustdoc docs #21041

Merged
merged 1 commit into from
Jan 16, 2015
Merged

Conversation

steveklabnik
Copy link
Member

Fixes #17554

@rust-highfive
Copy link
Collaborator

r? @huonw

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

@alexcrichton
Copy link
Member

The full logic is actually a bit more complicated than this, but I'm not sure how much in detail it should be spelled out. Specifically, the steps taken are:

  1. Given a code block, if it does not contain fn main, it is wrapped in fn main() { <codeblock> }
  2. Given that result, if it contains no extern crate directives but it also contains the name of the crate being tested, then extern crate <name> is injected at the top.
  3. Some common allow attributes are added for doc examples at the top.

This result is then tested.

Specifically, the example here isn't quite right, as what's actually tested look more like:

fn main() {
    use std::rc:Rc;
    let five = Rc::new(5);
}

@steveklabnik
Copy link
Member Author

@alexcrichton I added the full thing, with some copyedit and formatting changes. I'm fine with just repeating it verbatim, I don't think this is incredibly likely to change.

bors added a commit that referenced this pull request Jan 14, 2015
Add explanation of main to rustdoc docs

Reviewed-by: alexcrichton
bors added a commit that referenced this pull request Jan 14, 2015
Add explanation of main to rustdoc docs

Reviewed-by: alexcrichton
bors added a commit that referenced this pull request Jan 15, 2015
Add explanation of main to rustdoc docs

Reviewed-by: alexcrichton
```

fn main() {
use std::rc:Rc;
Copy link
Member

Choose a reason for hiding this comment

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

rc:Rc should be rc::Rc.

bors added a commit that referenced this pull request Jan 15, 2015
Add explanation of main to rustdoc docs

Reviewed-by: steveklabnik
alexcrichton added a commit to alexcrichton/rust that referenced this pull request Jan 15, 2015
@bors bors merged commit 462dd64 into rust-lang:master Jan 16, 2015
@steveklabnik steveklabnik deleted the gh17554 branch October 25, 2017 18:28
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.

rustdoc: Document how and when rustdoc wraps a code block in a main function.
6 participants