Skip to content

rustdoc: Document how and when rustdoc wraps a code block in a main function. #17554

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

Closed
DanielKeep opened this issue Sep 26, 2014 · 0 comments · Fixed by #21041
Closed

rustdoc: Document how and when rustdoc wraps a code block in a main function. #17554

DanielKeep opened this issue Sep 26, 2014 · 0 comments · Fixed by #21041
Labels
T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@DanielKeep
Copy link
Contributor

Currently, there is no indication in the documentation for rustdoc that it wraps code blocks in fn main() { ... }, nor how to stop it from doing so.

To give an example of how this can be very confusing, if you try to test the following code block, you get an error stating "unresolved import f1. There is no f1 in ???" which is (seemingly) not true.

pub fn f1() {}

mod a {
    use f1;
    fn f2() { f1() }
}

Preferably, the docs should note that, by default, all code blocks are wrapped in a main function, that this can be avoided by ensuring the string "fn main" appears (or whatever the actual test is; I think it just looks for a string in the input), and that # can be used to hide this from the rendered output (which is already in the docs in a different context).

@huonw huonw added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-docs labels Sep 26, 2014
steveklabnik added a commit to steveklabnik/rust that referenced this issue Jan 13, 2015
steveklabnik added a commit to steveklabnik/rust that referenced this issue Jan 15, 2015
alexcrichton added a commit to alexcrichton/rust that referenced this issue Jan 15, 2015
lnicola pushed a commit to lnicola/rust that referenced this issue Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants