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

Documentation for std::path::PathBuf::pop is slightly wrong #58474

Closed
nathan opened this issue Feb 15, 2019 · 2 comments
Closed

Documentation for std::path::PathBuf::pop is slightly wrong #58474

nathan opened this issue Feb 15, 2019 · 2 comments
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools

Comments

@nathan
Copy link
Contributor

nathan commented Feb 15, 2019

The documentation for std::path::PathBuf::pop() says:

Returns false and does nothing if self.file_name is None. Otherwise, returns true.

However, self.file_name() is None when the path ends in ..—but pop() still does removes that component and returns true. The docs should probably be changed to reflect that pop() truncates and returns true unless self.parent() is None.

use std::path::PathBuf;

fn main() {
  let mut p = PathBuf::from("/foo/bar/..");
  println!("{:?} {:?}", p.display(), p.file_name());
  println!("{:?}", p.pop());
  println!("{:?} {:?}", p.display(), p.file_name());
  println!("{:?}", p.pop());
  println!("{:?} {:?}", p.display(), p.file_name());
  println!("{:?}", p.pop());
  println!("{:?} {:?}", p.display(), p.file_name());
  println!("{:?}", p.pop());
  println!("{:?} {:?}", p.display(), p.file_name());
}

(Playground)

Output:

"/foo/bar/.." None
true
"/foo/bar" Some("bar")
true
"/foo" Some("foo")
true
"/" None
false
"/" None
@csmoe csmoe added the A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools label Feb 15, 2019
@hellow554
Copy link
Contributor

hellow554 commented Feb 15, 2019

@nathan would you open a PR and edit the required paragraph? Seems to be an easy issue :)

https://github.com/rust-lang/rust/blob/master/src/libstd/path.rs#L1231-L1261

@nathan
Copy link
Contributor Author

nathan commented Feb 15, 2019

@hellow554 Sure thing! #58496

kennytm added a commit to kennytm/rust that referenced this issue Feb 16, 2019
…frewsxcv

Fix documentation for std::path::PathBuf::pop

Closes rust-lang#58474.
kennytm added a commit to kennytm/rust that referenced this issue Feb 17, 2019
…frewsxcv

Fix documentation for std::path::PathBuf::pop

Closes rust-lang#58474.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools
Projects
None yet
Development

No branches or pull requests

3 participants