@@ -5,7 +5,7 @@ use std::ffi::OsString;
5
5
use std:: fs:: File ;
6
6
use std:: io;
7
7
use std:: io:: { prelude:: * , Error , ErrorKind } ;
8
- use std:: path:: { Component , Path , PathBuf } ;
8
+ use std:: path:: { Path , PathBuf } ;
9
9
use std:: sync:: Arc ;
10
10
11
11
pub struct FileResolver {
@@ -138,7 +138,7 @@ impl FileResolver {
138
138
if let ( Some ( mapping) , import_path) = import {
139
139
if first_part == mapping {
140
140
// match!
141
- if let Ok ( full_path) = join_fold ( import_path, & relpath) . canonicalize ( ) {
141
+ if let Ok ( full_path) = import_path. join ( & relpath) . canonicalize ( ) {
142
142
self . load_file ( & full_path) ?;
143
143
let base = full_path
144
144
. parent ( )
@@ -165,7 +165,7 @@ impl FileResolver {
165
165
{
166
166
if self . import_paths . is_empty ( ) {
167
167
// 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) ;
169
169
let base = ( & full_path. parent ( ) )
170
170
. expect ( "path should include filename" )
171
171
. to_path_buf ( ) ;
@@ -178,9 +178,9 @@ impl FileResolver {
178
178
}
179
179
180
180
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) ;
182
182
183
- if let Ok ( full_path) = join_fold ( & import_path, & path) . canonicalize ( ) {
183
+ if let Ok ( full_path) = import_path. join ( & path) . canonicalize ( ) {
184
184
self . load_file ( & full_path) ?;
185
185
let base = full_path
186
186
. parent ( )
@@ -218,7 +218,7 @@ impl FileResolver {
218
218
let import_no = ( i + start_import_no) % self . import_paths . len ( ) ;
219
219
220
220
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 ( ) {
222
222
let base = full_path
223
223
. parent ( )
224
224
. expect ( "path should include filename" )
@@ -275,98 +275,3 @@ impl FileResolver {
275
275
( full_line, begin_line, begin_column, size)
276
276
}
277
277
}
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