Skip to content
Merged
Changes from 1 commit
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
18 changes: 10 additions & 8 deletions src/libstd/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,9 @@ pub const MAIN_SEPARATOR: char = ::sys::path::MAIN_SEP;
// Iterate through `iter` while it matches `prefix`; return `None` if `prefix`
// is not a prefix of `iter`, otherwise return `Some(iter_after_prefix)` giving
// `iter` after having exhausted `prefix`.
fn iter_after<A, I, J>(mut iter: I, mut prefix: J) -> Option<I>
where I: Iterator<Item = A> + Clone,
J: Iterator<Item = A>,
A: PartialEq
fn iter_after<'a, 'b, I, J>(mut iter: I, mut prefix: J) -> Option<I>
where I: Iterator<Item = Component<'a>> + Clone,
J: Iterator<Item = Component<'b>>,
{
loop {
let mut iter_next = iter.clone();
Expand Down Expand Up @@ -1865,7 +1864,7 @@ impl Path {
/// # Examples
///
/// ```
/// use std::path::Path;
/// use std::path::{Path, PathBuf};
///
/// let path = Path::new("/test/haha/foo.txt");
///
Expand All @@ -1876,16 +1875,19 @@ impl Path {
/// assert_eq!(path.strip_prefix("/test/haha/foo.txt/"), Ok(Path::new("")));
/// assert_eq!(path.strip_prefix("test").is_ok(), false);
/// assert_eq!(path.strip_prefix("/haha").is_ok(), false);
///
/// let prefix = PathBuf::from("/test/");
/// assert_eq!(path.strip_prefix(prefix), Ok(Path::new("haha/foo.txt")));
/// ```
#[stable(since = "1.7.0", feature = "path_strip_prefix")]
pub fn strip_prefix<'a, P: ?Sized>(&'a self, base: &'a P)
-> Result<&'a Path, StripPrefixError>
pub fn strip_prefix<'a, P>(&'a self, base: P)
Copy link
Member

Choose a reason for hiding this comment

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

I believe the 'a lifetime can now be elided.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, thanks for catching this!

-> Result<&'a Path, StripPrefixError>
where P: AsRef<Path>
{
self._strip_prefix(base.as_ref())
}

fn _strip_prefix<'a>(&'a self, base: &'a Path)
fn _strip_prefix<'a>(&'a self, base: &Path)
Copy link
Member

Choose a reason for hiding this comment

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

Same here, I believe 'a can be elided.

-> Result<&'a Path, StripPrefixError> {
iter_after(self.components(), base.components())
.map(|c| c.as_path())
Expand Down