@@ -491,12 +491,6 @@ impl Span {
491
491
Span ( bridge:: client:: Span :: mixed_site ( ) )
492
492
}
493
493
494
- /// The original source file into which this span points.
495
- #[ unstable( feature = "proc_macro_span" , issue = "54725" ) ]
496
- pub fn source_file ( & self ) -> SourceFile {
497
- SourceFile ( self . 0 . source_file ( ) )
498
- }
499
-
500
494
/// The `Span` for the tokens in the previous macro expansion from which
501
495
/// `self` was generated from, if any.
502
496
#[ unstable( feature = "proc_macro_span" , issue = "54725" ) ]
@@ -546,6 +540,25 @@ impl Span {
546
540
self . 0 . column ( )
547
541
}
548
542
543
+ /// The path to the source file in which this span occurs, for display purposes.
544
+ ///
545
+ /// This might not correspond to a valid file system path.
546
+ /// It might be remapped, or might be an artificial path such as `"<macro expansion>"`.
547
+ #[ unstable( feature = "proc_macro_span" , issue = "54725" ) ]
548
+ pub fn file ( & self ) -> String {
549
+ self . 0 . file ( )
550
+ }
551
+
552
+ /// The path to the source file in which this span occurs on disk.
553
+ ///
554
+ /// This is the actual path on disk. It is unaffected by path remapping.
555
+ ///
556
+ /// This path should not be embedded in the output of the macro; prefer `file()` instead.
557
+ #[ unstable( feature = "proc_macro_span" , issue = "54725" ) ]
558
+ pub fn local_file ( & self ) -> Option < PathBuf > {
559
+ self . 0 . local_file ( ) . map ( |s| PathBuf :: from ( s) )
560
+ }
561
+
549
562
/// Creates a new span encompassing `self` and `other`.
550
563
///
551
564
/// Returns `None` if `self` and `other` are from different files.
@@ -614,41 +627,6 @@ impl fmt::Debug for Span {
614
627
}
615
628
}
616
629
617
- /// The source file of a given `Span`.
618
- #[ unstable( feature = "proc_macro_span" , issue = "54725" ) ]
619
- #[ derive( Clone ) ]
620
- pub struct SourceFile ( bridge:: client:: SourceFile ) ;
621
-
622
- impl SourceFile {
623
- /// Gets the path to this source file.
624
- ///
625
- /// ### Note
626
- ///
627
- /// If `--remap-path-prefix` was passed on
628
- /// the command line, the path as given might not actually be valid.
629
- #[ unstable( feature = "proc_macro_span" , issue = "54725" ) ]
630
- pub fn path ( & self ) -> PathBuf {
631
- PathBuf :: from ( self . 0 . path ( ) )
632
- }
633
- }
634
-
635
- #[ unstable( feature = "proc_macro_span" , issue = "54725" ) ]
636
- impl fmt:: Debug for SourceFile {
637
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
638
- f. debug_struct ( "SourceFile" ) . field ( "path" , & self . path ( ) ) . finish ( )
639
- }
640
- }
641
-
642
- #[ unstable( feature = "proc_macro_span" , issue = "54725" ) ]
643
- impl PartialEq for SourceFile {
644
- fn eq ( & self , other : & Self ) -> bool {
645
- self . 0 . eq ( & other. 0 )
646
- }
647
- }
648
-
649
- #[ unstable( feature = "proc_macro_span" , issue = "54725" ) ]
650
- impl Eq for SourceFile { }
651
-
652
630
/// A single token or a delimited sequence of token trees (e.g., `[1, (), ..]`).
653
631
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
654
632
#[ derive( Clone ) ]
0 commit comments