@@ -50,6 +50,7 @@ mod diagnostic;
50
50
pub use diagnostic:: { Diagnostic , Level } ;
51
51
52
52
use std:: { ascii, fmt, iter} ;
53
+ use std:: path:: PathBuf ;
53
54
use rustc_data_structures:: sync:: Lrc ;
54
55
use std:: str:: FromStr ;
55
56
@@ -421,8 +422,11 @@ impl SourceFile {
421
422
///
422
423
/// [`is_real`]: #method.is_real
423
424
#[ unstable( feature = "proc_macro_span" , issue = "38356" ) ]
424
- pub fn path ( & self ) -> & FileName {
425
- & self . filemap . name
425
+ pub fn path ( & self ) -> PathBuf {
426
+ match self . filemap . name {
427
+ FileName :: Real ( ref path) => path. clone ( ) ,
428
+ _ => PathBuf :: from ( self . filemap . name . to_string ( ) )
429
+ }
426
430
}
427
431
428
432
/// Returns `true` if this source file is a real source file, and not generated by an external
@@ -436,18 +440,12 @@ impl SourceFile {
436
440
}
437
441
}
438
442
439
- #[ unstable( feature = "proc_macro_span" , issue = "38356" ) ]
440
- impl AsRef < FileName > for SourceFile {
441
- fn as_ref ( & self ) -> & FileName {
442
- self . path ( )
443
- }
444
- }
445
443
446
444
#[ unstable( feature = "proc_macro_span" , issue = "38356" ) ]
447
445
impl fmt:: Debug for SourceFile {
448
446
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
449
447
f. debug_struct ( "SourceFile" )
450
- . field ( "path" , self . path ( ) )
448
+ . field ( "path" , & self . path ( ) )
451
449
. field ( "is_real" , & self . is_real ( ) )
452
450
. finish ( )
453
451
}
@@ -463,13 +461,6 @@ impl PartialEq for SourceFile {
463
461
#[ unstable( feature = "proc_macro_span" , issue = "38356" ) ]
464
462
impl Eq for SourceFile { }
465
463
466
- #[ unstable( feature = "proc_macro_span" , issue = "38356" ) ]
467
- impl PartialEq < FileName > for SourceFile {
468
- fn eq ( & self , other : & FileName ) -> bool {
469
- self . as_ref ( ) == other
470
- }
471
- }
472
-
473
464
/// A single token or a delimited sequence of token trees (e.g. `[1, (), ..]`).
474
465
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
475
466
#[ derive( Clone ) ]
0 commit comments