-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Document usage of extern crate
declaration in doctests
#30137
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
Comments
This seems like a bug somewhere in rustc/cargo, rather than a problem with the docs, because ///```
///extern crate mylib;
///mylib::foo('bar');
///```
works fine, but (as was mentioned here) ///```
///extern crate mylib;
///use mylib::foo;
///foo('bar');
///```
does not. This seems like wrong behaviour. Also, the suggested ///```
///extern crate mylib;
///use self::mylib::foo;
///foo('bar');
///```
does not work either, I don't know if there is an RFC or issue open about attempting to resolve the names suggested under EDIT: as mentioned below, this is not a bug with rustc or cargo, it's just that there is no way to refer to the current function scope in a use statement if you import a crate into it. |
@jFransham it's not wrong but it is very misleading. The key is that if |
Right, it's the 'entire' part that's confusing. I myself find it to be so and I wrote the sentence! |
It would be nice if rustdoc used similar heuristics to playbot, where stuff like extern crates and crate attributes get hoisted out of the generated main function. |
Why is extern crate even allowed inside of functions? That seems like a horrible misfeature. |
It's similar to anything else that brings a name into scope, you can do it in whatever scope you'd like. |
I guess the "real" problem is that |
I think this fixes rust-lang#30137. I basically just repeated some details that were scattered around other places in this document, and emphasized that you probably don't want an `extern crate` or `mod` statement to end up inside a function.
I think this fixes rust-lang#30137. I basically just repeated some details that were scattered around other places in this document, and emphasized that you probably don't want an `extern crate` or `mod` statement to end up inside a function.
When a doctest like this is written:
running the tests will produce an error like:
since the test code is wrapped inside a
fn main()
for execution.This is imho not clear in this algorithm description https://doc.rust-lang.org/stable/book/documentation.html
The text was updated successfully, but these errors were encountered: