Uh oh!
There was an error while loading. Please reload this page.
Add missing code examples - #45361
Conversation
QuietMisdreavus
commented
Oct 18, 2017
Every doctest failed with something like this: From the Cargo invocation that's printed at the end, it looks like it's properly running under the |
QuietMisdreavus
commented
Oct 18, 2017
Oh! You're trying to use the |
GuillaumeGomez
commented
Oct 18, 2017
Ah maybe. |
GuillaumeGomez
commented
Oct 18, 2017
Let's see with this cfg. :) |
kennytm
commented
Oct 18, 2017
o_O Why not just add |
GuillaumeGomez
commented
Oct 19, 2017
It's working fine in a code of mine so I don't think this is the issue. |
GuillaumeGomez
commented
Oct 19, 2017
My fix worked! |
QuietMisdreavus
commented
Oct 19, 2017
You just |
kennytm
commented
Oct 19, 2017
This should work, you could adapt it to the examples... use std::fs;use std::os::linux::fs::MetadataExt;// <--------------- use this -------------use std::io;fnf() -> io::Result<()>{let meta = fs::metadata("/dev/null")?;println!("{}", meta.st_dev());Ok(())}fnmain(){println!("{:?}", f());} |
GuillaumeGomez
commented
Oct 22, 2017
Updated and working. |
There was a problem hiding this comment.
This #[cfg(target_os = "linux")] block could be removed, #[doc(cfg)] should not run the doc tests outside of Linux.
There was a problem hiding this comment.
The point is that, if users want to take a look at the full code (by clicking on "run"), they'll see this conditional compilation.
There was a problem hiding this comment.
How many people click on "Run" though? I'm thinking of how many people copy out the examples in File and run into "? in main" errors.
There was a problem hiding this comment.
I guess since all of the examples are secretly function definitions that are never called, it's no difference whether or not no_run is actually there.
| /// # use std::io; | ||
| /// # fn f() -> io::Result<()> { | ||
| /// let meta = fs::metadata("some_file")?; | ||
| /// let stat = meta.as_raw_stat(); |
There was a problem hiding this comment.
Is it worth adding an example to this method, since it's deprecated?
There was a problem hiding this comment.
It's always worth it. As long as it's there, it has to be documented.
There was a problem hiding this comment.
Fair point. I was thinking in terms of "we're suggesting people use other methods, so why do we provide incentive to look at this one?"
Also now that i'm thinking about it, i'm concerned that this may not actually pass tests, since every doctest in std has deny(warnings) applied to it. If this passes travis, i'll let it slide, but that's at least my reasoning.
QuietMisdreavus
commented
Oct 24, 2017
Welp, travis passed and i have no idea how. If it's a problem then homu will find it; if it's not a problem then i'll stop worrying about it. @bors r+ rollup |
bors
commented
Oct 24, 2017
📌 Commit e42da90 has been approved by |
…reavus Add missing code examples r? @rust-lang/docs
r? @rust-lang/docs