@@ -5,7 +5,7 @@ use std::ffi::OsString;
55use std:: fs:: File ;
66use std:: io;
77use std:: io:: { prelude:: * , Error , ErrorKind } ;
8- use std:: path:: { Component , Path , PathBuf } ;
8+ use std:: path:: { Path , PathBuf } ;
99use std:: sync:: Arc ;
1010
1111pub struct FileResolver {
@@ -138,7 +138,7 @@ impl FileResolver {
138138 if let ( Some ( mapping) , import_path) = import {
139139 if first_part == mapping {
140140 // match!
141- if let Ok ( full_path) = join_fold ( import_path, & relpath) . canonicalize ( ) {
141+ if let Ok ( full_path) = import_path. join ( & relpath) . canonicalize ( ) {
142142 self . load_file ( & full_path) ?;
143143 let base = full_path
144144 . parent ( )
@@ -165,7 +165,7 @@ impl FileResolver {
165165 {
166166 if self . import_paths . is_empty ( ) {
167167 // we have no import paths, resolve by what's in the cache
168- let full_path = join_fold ( base, & path) ;
168+ let full_path = base. join ( & path) ;
169169 let base = ( & full_path. parent ( ) )
170170 . expect ( "path should include filename" )
171171 . to_path_buf ( ) ;
@@ -178,9 +178,9 @@ impl FileResolver {
178178 }
179179
180180 if let ( None , import_path) = & self . import_paths [ * import_no] {
181- let import_path = join_fold ( import_path, base) ;
181+ let import_path = import_path. join ( base) ;
182182
183- if let Ok ( full_path) = join_fold ( & import_path, & path) . canonicalize ( ) {
183+ if let Ok ( full_path) = import_path. join ( & path) . canonicalize ( ) {
184184 self . load_file ( & full_path) ?;
185185 let base = full_path
186186 . parent ( )
@@ -218,7 +218,7 @@ impl FileResolver {
218218 let import_no = ( i + start_import_no) % self . import_paths . len ( ) ;
219219
220220 if let ( None , import_path) = & self . import_paths [ import_no] {
221- if let Ok ( full_path) = join_fold ( import_path, & path) . canonicalize ( ) {
221+ if let Ok ( full_path) = import_path. join ( & path) . canonicalize ( ) {
222222 let base = full_path
223223 . parent ( )
224224 . expect ( "path should include filename" )
@@ -275,98 +275,3 @@ impl FileResolver {
275275 ( full_line, begin_line, begin_column, size)
276276 }
277277}
278-
279- // see https://github.com/rust-lang/rust/pull/89270
280- fn join_fold ( left : & Path , right : & Path ) -> PathBuf {
281- let mut buf = Vec :: new ( ) ;
282- let mut has_prefix = false ;
283-
284- for c in left. components ( ) {
285- match c {
286- Component :: Prefix ( _) => {
287- has_prefix = true ;
288- buf. push ( c) ;
289- }
290- Component :: Normal ( _) | Component :: RootDir => {
291- buf. push ( c) ;
292- }
293- Component :: CurDir => ( ) ,
294- Component :: ParentDir => {
295- if let Some ( Component :: Normal ( _) ) = buf. last ( ) {
296- buf. pop ( ) ;
297- } else {
298- buf. push ( c) ;
299- }
300- }
301- }
302- }
303-
304- for c in right. components ( ) {
305- match c {
306- Component :: Prefix ( _) => {
307- buf = vec ! [ c] ;
308- has_prefix = true ;
309- }
310- Component :: RootDir => {
311- if has_prefix {
312- buf. push ( c) ;
313- } else {
314- buf = vec ! [ c] ;
315- }
316- }
317- Component :: CurDir => ( ) ,
318- Component :: ParentDir => match buf. last ( ) {
319- Some ( Component :: RootDir ) => ( ) ,
320- Some ( Component :: Prefix ( _) | Component :: ParentDir ) | None => buf. push ( c) ,
321- _ => {
322- let _ = buf. pop ( ) ;
323- }
324- } ,
325- Component :: Normal ( _) => {
326- buf. push ( c) ;
327- }
328- }
329- }
330-
331- buf. iter ( ) . collect ( )
332- }
333-
334- #[ test]
335- #[ cfg( not( windows) ) ]
336- fn test_join ( ) {
337- let x = join_fold ( & PathBuf :: from ( "/foo//" ) , & PathBuf :: from ( "bar" ) ) ;
338-
339- assert_eq ! ( x. to_string_lossy( ) , r"/foo/bar" ) ;
340-
341- let x = join_fold ( & PathBuf :: from ( "/foo//" ) , & PathBuf :: from ( "/../bar" ) ) ;
342-
343- assert_eq ! ( x. to_string_lossy( ) , r"/bar" ) ;
344- }
345-
346- #[ test]
347- #[ cfg( windows) ]
348- fn test_win_join ( ) {
349- let x = join_fold ( & PathBuf :: from ( "/foo//" ) , & PathBuf :: from ( "bar" ) ) ;
350-
351- assert_eq ! ( x. to_string_lossy( ) , r"\foo\bar" ) ;
352-
353- let x = join_fold ( & PathBuf :: from ( "/foo//" ) , & PathBuf :: from ( "/../bar" ) ) ;
354-
355- assert_eq ! ( x. to_string_lossy( ) , r"\bar" ) ;
356-
357- let x = join_fold ( & PathBuf :: from ( "C:/foo//" ) , & PathBuf :: from ( "bar" ) ) ;
358-
359- assert_eq ! ( x. to_string_lossy( ) , r"C:\foo\bar" ) ;
360-
361- let x = join_fold ( & PathBuf :: from ( "C:" ) , & PathBuf :: from ( "bar/../foo" ) ) ;
362-
363- assert_eq ! ( x. to_string_lossy( ) , r"C:foo" ) ;
364-
365- let x = join_fold ( & PathBuf :: from ( "C:" ) , & PathBuf :: from ( "/bar/../foo" ) ) ;
366-
367- assert_eq ! ( x. to_string_lossy( ) , r"C:\foo" ) ;
368-
369- let x = join_fold ( & PathBuf :: from ( "C:" ) , & PathBuf :: from ( "../foo" ) ) ;
370-
371- assert_eq ! ( x. to_string_lossy( ) , r"C:..\foo" ) ;
372- }
0 commit comments