@@ -64,6 +64,7 @@ mod diagnostic;
64
64
pub use diagnostic:: { Diagnostic , Level } ;
65
65
66
66
use std:: { ascii, fmt, iter} ;
67
+ use std:: path:: PathBuf ;
67
68
use rustc_data_structures:: sync:: Lrc ;
68
69
use std:: str:: FromStr ;
69
70
@@ -332,14 +333,17 @@ impl SourceFile {
332
333
/// the command line, the path as given may not actually be valid.
333
334
///
334
335
/// [`is_real`]: #method.is_real
335
- # [ unstable( feature = "proc_macro" , issue = "38356" ) ]
336
- pub fn path ( & self ) -> & FileName {
337
- & self . filemap . name
336
+ #[ unstable( feature = "proc_macro" , issue = "38356" ) ]
337
+ pub fn path ( & self ) -> PathBuf {
338
+ match self . filemap . name {
339
+ FileName :: Real ( ref path) => path. clone ( ) ,
340
+ _ => PathBuf :: from ( self . filemap . name . to_string ( ) )
341
+ }
338
342
}
339
343
340
344
/// Returns `true` if this source file is a real source file, and not generated by an external
341
345
/// macro's expansion.
342
- # [ unstable( feature = "proc_macro" , issue = "38356" ) ]
346
+ #[ unstable( feature = "proc_macro" , issue = "38356" ) ]
343
347
pub fn is_real ( & self ) -> bool {
344
348
// This is a hack until intercrate spans are implemented and we can have real source files
345
349
// for spans generated in external macros.
@@ -348,18 +352,12 @@ impl SourceFile {
348
352
}
349
353
}
350
354
351
- #[ unstable( feature = "proc_macro" , issue = "38356" ) ]
352
- impl AsRef < FileName > for SourceFile {
353
- fn as_ref ( & self ) -> & FileName {
354
- self . path ( )
355
- }
356
- }
357
355
358
356
#[ unstable( feature = "proc_macro" , issue = "38356" ) ]
359
357
impl fmt:: Debug for SourceFile {
360
358
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
361
359
f. debug_struct ( "SourceFile" )
362
- . field ( "path" , self . path ( ) )
360
+ . field ( "path" , & self . path ( ) )
363
361
. field ( "is_real" , & self . is_real ( ) )
364
362
. finish ( )
365
363
}
@@ -375,13 +373,6 @@ impl PartialEq for SourceFile {
375
373
#[ unstable( feature = "proc_macro" , issue = "38356" ) ]
376
374
impl Eq for SourceFile { }
377
375
378
- #[ unstable( feature = "proc_macro" , issue = "38356" ) ]
379
- impl PartialEq < FileName > for SourceFile {
380
- fn eq ( & self , other : & FileName ) -> bool {
381
- self . as_ref ( ) == other
382
- }
383
- }
384
-
385
376
/// A single token or a delimited sequence of token trees (e.g. `[1, (), ..]`).
386
377
#[ unstable( feature = "proc_macro" , issue = "38356" ) ]
387
378
#[ derive( Clone , Debug ) ]
0 commit comments