@@ -965,8 +965,10 @@ impl PathBuf {
965965 /// * if `path` has a prefix but no root, it replaces `self`.
966966 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
967967 pub fn push < P : AsRef < Path > > ( & mut self , path : P ) {
968- let path = path. as_ref ( ) ;
968+ self . _push ( path. as_ref ( ) )
969+ }
969970
971+ fn _push ( & mut self , path : & Path ) {
970972 // in general, a separator is needed if the rightmost byte is not a separator
971973 let mut need_sep = self . as_mut_vec ( ) . last ( ) . map ( |c| !is_sep_byte ( * c) ) . unwrap_or ( false ) ;
972974
@@ -1033,11 +1035,15 @@ impl PathBuf {
10331035 /// ```
10341036 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
10351037 pub fn set_file_name < S : AsRef < OsStr > > ( & mut self , file_name : S ) {
1038+ self . _set_file_name ( file_name. as_ref ( ) )
1039+ }
1040+
1041+ fn _set_file_name ( & mut self , file_name : & OsStr ) {
10361042 if self . file_name ( ) . is_some ( ) {
10371043 let popped = self . pop ( ) ;
10381044 debug_assert ! ( popped) ;
10391045 }
1040- self . push ( file_name. as_ref ( ) ) ;
1046+ self . push ( file_name) ;
10411047 }
10421048
10431049 /// Updates `self.extension()` to `extension`.
@@ -1048,14 +1054,17 @@ impl PathBuf {
10481054 /// is added; otherwise it is replaced.
10491055 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
10501056 pub fn set_extension < S : AsRef < OsStr > > ( & mut self , extension : S ) -> bool {
1057+ self . _set_extension ( extension. as_ref ( ) )
1058+ }
1059+
1060+ fn _set_extension ( & mut self , extension : & OsStr ) -> bool {
10511061 if self . file_name ( ) . is_none ( ) { return false ; }
10521062
10531063 let mut stem = match self . file_stem ( ) {
10541064 Some ( stem) => stem. to_os_string ( ) ,
10551065 None => OsString :: new ( ) ,
10561066 } ;
10571067
1058- let extension = extension. as_ref ( ) ;
10591068 if !os_str_as_u8_slice ( extension) . is_empty ( ) {
10601069 stem. push ( "." ) ;
10611070 stem. push ( extension) ;
@@ -1106,7 +1115,7 @@ impl<P: AsRef<Path>> iter::FromIterator<P> for PathBuf {
11061115impl < P : AsRef < Path > > iter:: Extend < P > for PathBuf {
11071116 fn extend < I : IntoIterator < Item = P > > ( & mut self , iter : I ) {
11081117 for p in iter {
1109- self . push ( p)
1118+ self . push ( p. as_ref ( ) )
11101119 }
11111120 }
11121121}
@@ -1452,7 +1461,11 @@ impl Path {
14521461 issue = "23284" ) ]
14531462 pub fn relative_from < ' a , P : ?Sized + AsRef < Path > > ( & ' a self , base : & ' a P ) -> Option < & Path >
14541463 {
1455- iter_after ( self . components ( ) , base. as_ref ( ) . components ( ) ) . map ( |c| c. as_path ( ) )
1464+ self . _relative_from ( base. as_ref ( ) )
1465+ }
1466+
1467+ fn _relative_from < ' a > ( & ' a self , base : & ' a Path ) -> Option < & ' a Path > {
1468+ iter_after ( self . components ( ) , base. components ( ) ) . map ( |c| c. as_path ( ) )
14561469 }
14571470
14581471 /// Determines whether `base` is a prefix of `self`.
@@ -1472,7 +1485,11 @@ impl Path {
14721485 /// ```
14731486 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
14741487 pub fn starts_with < P : AsRef < Path > > ( & self , base : P ) -> bool {
1475- iter_after ( self . components ( ) , base. as_ref ( ) . components ( ) ) . is_some ( )
1488+ self . _starts_with ( base. as_ref ( ) )
1489+ }
1490+
1491+ fn _starts_with ( & self , base : & Path ) -> bool {
1492+ iter_after ( self . components ( ) , base. components ( ) ) . is_some ( )
14761493 }
14771494
14781495 /// Determines whether `child` is a suffix of `self`.
@@ -1490,7 +1507,11 @@ impl Path {
14901507 /// ```
14911508 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
14921509 pub fn ends_with < P : AsRef < Path > > ( & self , child : P ) -> bool {
1493- iter_after ( self . components ( ) . rev ( ) , child. as_ref ( ) . components ( ) . rev ( ) ) . is_some ( )
1510+ self . _ends_with ( child. as_ref ( ) )
1511+ }
1512+
1513+ fn _ends_with ( & self , child : & Path ) -> bool {
1514+ iter_after ( self . components ( ) . rev ( ) , child. components ( ) . rev ( ) ) . is_some ( )
14941515 }
14951516
14961517 /// Extracts the stem (non-extension) portion of `self.file_name()`.
@@ -1552,6 +1573,10 @@ impl Path {
15521573 /// ```
15531574 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
15541575 pub fn join < P : AsRef < Path > > ( & self , path : P ) -> PathBuf {
1576+ self . _join ( path. as_ref ( ) )
1577+ }
1578+
1579+ fn _join ( & self , path : & Path ) -> PathBuf {
15551580 let mut buf = self . to_path_buf ( ) ;
15561581 buf. push ( path) ;
15571582 buf
@@ -1571,6 +1596,10 @@ impl Path {
15711596 /// ```
15721597 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
15731598 pub fn with_file_name < S : AsRef < OsStr > > ( & self , file_name : S ) -> PathBuf {
1599+ self . _with_file_name ( file_name. as_ref ( ) )
1600+ }
1601+
1602+ fn _with_file_name ( & self , file_name : & OsStr ) -> PathBuf {
15741603 let mut buf = self . to_path_buf ( ) ;
15751604 buf. set_file_name ( file_name) ;
15761605 buf
@@ -1590,6 +1619,10 @@ impl Path {
15901619 /// ```
15911620 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
15921621 pub fn with_extension < S : AsRef < OsStr > > ( & self , extension : S ) -> PathBuf {
1622+ self . _with_extension ( extension. as_ref ( ) )
1623+ }
1624+
1625+ fn _with_extension ( & self , extension : & OsStr ) -> PathBuf {
15931626 let mut buf = self . to_path_buf ( ) ;
15941627 buf. set_extension ( extension) ;
15951628 buf
0 commit comments