-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Closed
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and tools
Description
The documentation for std::path::PathBuf::pop() says:
Returns
falseand does nothing ifself.file_nameisNone. Otherwise, returnstrue.
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());
}Output:
"/foo/bar/.." None
true
"/foo/bar" Some("bar")
true
"/foo" Some("foo")
true
"/" None
false
"/" None
Metadata
Metadata
Assignees
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and tools