@@ -4,6 +4,8 @@ use crate::fallback::{self, FromStr2 as _};
44use crate :: location:: LineColumn ;
55#[ cfg( proc_macro_span) ]
66use crate :: probe:: proc_macro_span;
7+ #[ cfg( all( span_locations, proc_macro_span_file) ) ]
8+ use crate :: probe:: proc_macro_span_file;
79#[ cfg( all( span_locations, proc_macro_span_location) ) ]
810use crate :: probe:: proc_macro_span_location;
911use crate :: { Delimiter , Punct , Spacing , TokenTree } ;
@@ -12,7 +14,7 @@ use core::fmt::{self, Debug, Display};
1214use core:: ops:: Range ;
1315use core:: ops:: RangeBounds ;
1416use std:: ffi:: CStr ;
15- #[ cfg( super_unstable ) ]
17+ #[ cfg( span_locations ) ]
1618use std:: path:: PathBuf ;
1719
1820#[ derive( Clone ) ]
@@ -463,18 +465,24 @@ impl Span {
463465 }
464466 }
465467
466- #[ cfg( super_unstable ) ]
468+ #[ cfg( span_locations ) ]
467469 pub ( crate ) fn file ( & self ) -> String {
468470 match self {
469- Span :: Compiler ( s) => s. file ( ) ,
471+ #[ cfg( proc_macro_span_file) ]
472+ Span :: Compiler ( s) => proc_macro_span_file:: file ( s) ,
473+ #[ cfg( not( proc_macro_span_file) ) ]
474+ Span :: Compiler ( _) => "<token stream>" . to_owned ( ) ,
470475 Span :: Fallback ( s) => s. file ( ) ,
471476 }
472477 }
473478
474- #[ cfg( super_unstable ) ]
479+ #[ cfg( span_locations ) ]
475480 pub ( crate ) fn local_file ( & self ) -> Option < PathBuf > {
476481 match self {
477- Span :: Compiler ( s) => s. local_file ( ) ,
482+ #[ cfg( proc_macro_span_file) ]
483+ Span :: Compiler ( s) => proc_macro_span_file:: local_file ( s) ,
484+ #[ cfg( not( proc_macro_span_file) ) ]
485+ Span :: Compiler ( _) => None ,
478486 Span :: Fallback ( s) => s. local_file ( ) ,
479487 }
480488 }
0 commit comments