Skip to content
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

Wrong documentation for std::path::Path::file_name #34632

Closed
bennofs opened this issue Jul 3, 2016 · 1 comment
Closed

Wrong documentation for std::path::Path::file_name #34632

bennofs opened this issue Jul 3, 2016 · 1 comment

Comments

@bennofs
Copy link

bennofs commented Jul 3, 2016

The documentation states:

The final component of the path, if it is a normal file.
If the path terminates in ., .., or consists solely of a root of prefix, file_name will return None.

but:

fn do_file_name(x: &str) {
    println!("file_name({}) = {:?}", x, std::path::Path::new(x).file_name());
}

fn main() {
    use std::path::Path;
    do_file_name("/path/with/dot/.");
    do_file_name("/path/with/with/dot/slash/./");
    do_file_name("/path/with/dot/double/slash/.//");
    do_file_name("/path/with/double/dot/..");
    do_file_name("/path/with/nul/bytes/test\0invalid");
}

prints

file_name(/path/with/dot/.) = Some("dot")
file_name(/path/with/with/dot/slash/./) = Some("slash")
file_name(/path/with/dot/double/slash/.//) = Some("slash")
file_name(/path/with/double/dot/..) = None
file_name(/path/with/nul/bytes/testinvalid) = Some("test\u{0}invalid")

(Playground: https://play.rust-lang.org/?gist=2eddf89b4c80926240b9cbd4d6d40821&version=stable&backtrace=0)

I think the documentation for the "ends with ." case is wrong.

@sfackler sfackler added the A-docs label Jul 3, 2016
@GuillaumeGomez
Copy link
Member

The problem is still in nightly.

@bennofs: Want to fix it?

steveklabnik added a commit to steveklabnik/rust that referenced this issue Jul 5, 2016
…eveklabnik

Fix `std::path::Path::file_name()` doc

Fixes rust-lang#34632

r? @steveklabnik
Manishearth added a commit to Manishearth/rust that referenced this issue Jul 8, 2016
…eveklabnik

Fix `std::path::Path::file_name()` doc

Fixes rust-lang#34632

r? @steveklabnik
Manishearth added a commit to Manishearth/rust that referenced this issue Jul 8, 2016
…eveklabnik

Fix `std::path::Path::file_name()` doc

Fixes rust-lang#34632

r? @steveklabnik
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

No branches or pull requests

3 participants