Skip to content

Conversation

steveklabnik
Copy link
Contributor

Fixes #17554

@rust-highfive
Copy link
Contributor

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
Contributor 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
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