Skip to content

Commit 0d0a470

Browse files
committed
Make signature of Path::strip_prefix un-bizarre
BREAKING CHANGE: This has the potential to cause regressions in type inference.
1 parent 27a046e commit 0d0a470

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/libstd/path.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,9 @@ pub const MAIN_SEPARATOR: char = ::sys::path::MAIN_SEP;
297297
// Iterate through `iter` while it matches `prefix`; return `None` if `prefix`
298298
// is not a prefix of `iter`, otherwise return `Some(iter_after_prefix)` giving
299299
// `iter` after having exhausted `prefix`.
300-
fn iter_after<A, I, J>(mut iter: I, mut prefix: J) -> Option<I>
301-
where I: Iterator<Item = A> + Clone,
302-
J: Iterator<Item = A>,
303-
A: PartialEq
300+
fn iter_after<'a, 'b, I, J>(mut iter: I, mut prefix: J) -> Option<I>
301+
where I: Iterator<Item = Component<'a>> + Clone,
302+
J: Iterator<Item = Component<'b>>,
304303
{
305304
loop {
306305
let mut iter_next = iter.clone();
@@ -1865,7 +1864,7 @@ impl Path {
18651864
/// # Examples
18661865
///
18671866
/// ```
1868-
/// use std::path::Path;
1867+
/// use std::path::{Path, PathBuf};
18691868
///
18701869
/// let path = Path::new("/test/haha/foo.txt");
18711870
///
@@ -1876,16 +1875,19 @@ impl Path {
18761875
/// assert_eq!(path.strip_prefix("/test/haha/foo.txt/"), Ok(Path::new("")));
18771876
/// assert_eq!(path.strip_prefix("test").is_ok(), false);
18781877
/// assert_eq!(path.strip_prefix("/haha").is_ok(), false);
1878+
///
1879+
/// let prefix = PathBuf::from("/test/");
1880+
/// assert_eq!(path.strip_prefix(prefix), Ok(Path::new("haha/foo.txt")));
18791881
/// ```
18801882
#[stable(since = "1.7.0", feature = "path_strip_prefix")]
1881-
pub fn strip_prefix<'a, P: ?Sized>(&'a self, base: &'a P)
1882-
-> Result<&'a Path, StripPrefixError>
1883+
pub fn strip_prefix<'a, P>(&'a self, base: P)
1884+
-> Result<&'a Path, StripPrefixError>
18831885
where P: AsRef<Path>
18841886
{
18851887
self._strip_prefix(base.as_ref())
18861888
}
18871889

1888-
fn _strip_prefix<'a>(&'a self, base: &'a Path)
1890+
fn _strip_prefix<'a>(&'a self, base: &Path)
18891891
-> Result<&'a Path, StripPrefixError> {
18901892
iter_after(self.components(), base.components())
18911893
.map(|c| c.as_path())

0 commit comments

Comments
 (0)