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

Fix error message for WindowsPath::new #16443

Merged
merged 1 commit into from
Aug 21, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/libstd/path/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,18 +628,36 @@ impl GenericPath for Path {
}

impl Path {
/// Returns a new Path from a byte vector or string
/// Returns a new `Path` from a `BytesContainer`.
///
/// # Failure
///
/// Fails the task if the vector contains a NUL.
/// Fails if invalid UTF-8.
/// Fails if the vector contains a `NUL`, or if it contains invalid UTF-8.
///
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to check to make sure this is true, it looks like this is actually true or perhaps there is a bug:

use std::path::WindowsPath;             

fn main() { WindowsPath::new(b"\xff"); }
task '<main>' failed at 'called `Option::unwrap()` on a `None` value', /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/libcore/option.rs:262

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrm.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WindowsPath::new() requires UTF-8. PosixPath::new() only requires no NUL bytes. Path::new() may fail in either scenario depending on current platform.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did the example in the reddit thread not fail, then?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What @huonw's example? That used Path::new(). Change it to WindowsPath::new() and fix the bytestring to actually use the correct \xFF escape (the backslash was lost) and it fails.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Cool. I will change this PR to just update the style of these docs then.

/// # Example
///
/// ```
/// println!("{}", Path::new(r"C:\some\path").display());
/// ```
#[inline]
pub fn new<T: BytesContainer>(path: T) -> Path {
GenericPath::new(path)
}

/// Returns a new Path from a byte vector or string, if possible
/// Returns a new `Some(Path)` from a `BytesContainer`.
///
/// Returns `None` if the vector contains a `NUL`, or if it contains invalid UTF-8.
///
/// # Example
///
/// ```
/// let path = Path::new_opt(r"C:\some\path");
///
/// match path {
/// Some(path) => println!("{}", path.display()),
/// None => println!("There was a problem with your path."),
/// }
/// ```
#[inline]
pub fn new_opt<T: BytesContainer>(path: T) -> Option<Path> {
GenericPath::new_opt(path)
Expand Down