-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 missing code examples #45361
Add missing code examples #45361
Conversation
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 |
Oh! You're trying to use the |
Ah maybe. |
Let's see with this cfg. :) |
o_O Why not just add |
It's working fine in a code of mine so I don't think this is the issue. |
38263d6
to
a0614a3
Compare
My fix worked! |
You just |
This should work, you could adapt it to the examples... use std::fs;
use std::os::linux::fs::MetadataExt; // <--------------- use this -------------
use std::io;
fn f() -> io::Result<()> {
let meta = fs::metadata("/dev/null")?;
println!("{}", meta.st_dev());
Ok(())
}
fn main() {
println!("{:?}", f());
} |
a0614a3
to
dfcffbf
Compare
Updated and working. |
src/libstd/os/linux/fs.rs
Outdated
/// # Examples | ||
/// | ||
/// ``` | ||
/// # #[cfg(target_os = "linux")] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
/// | ||
/// # Examples | ||
/// | ||
/// ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no_run
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
dfcffbf
to
e42da90
Compare
/// # 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth adding an example to this method, since it's deprecated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's always worth it. As long as it's there, it has to be documented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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 |
📌 Commit e42da90 has been approved by |
…reavus Add missing code examples r? @rust-lang/docs
r? @rust-lang/docs