Skip to content

Commit 2c3a474

Browse files
committed
Replace proc_macro::SourceFile by Span::{file, local_file}.
1 parent 485eff7 commit 2c3a474

File tree

4 files changed

+21
-56
lines changed

4 files changed

+21
-56
lines changed

proc_macro/src/bridge/client.rs

-6
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,6 @@ impl Clone for TokenStream {
111111
}
112112
}
113113

114-
impl Clone for SourceFile {
115-
fn clone(&self) -> Self {
116-
self.clone()
117-
}
118-
}
119-
120114
impl Span {
121115
pub(crate) fn def_site() -> Span {
122116
Bridge::with(|bridge| bridge.globals.def_site)

proc_macro/src/bridge/mod.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,17 @@ macro_rules! with_api {
8181
$self: $S::TokenStream
8282
) -> Vec<TokenTree<$S::TokenStream, $S::Span, $S::Symbol>>;
8383
},
84-
SourceFile {
85-
fn drop($self: $S::SourceFile);
86-
fn clone($self: &$S::SourceFile) -> $S::SourceFile;
87-
fn eq($self: &$S::SourceFile, other: &$S::SourceFile) -> bool;
88-
fn path($self: &$S::SourceFile) -> String;
89-
},
9084
Span {
9185
fn debug($self: $S::Span) -> String;
92-
fn source_file($self: $S::Span) -> $S::SourceFile;
9386
fn parent($self: $S::Span) -> Option<$S::Span>;
9487
fn source($self: $S::Span) -> $S::Span;
9588
fn byte_range($self: $S::Span) -> Range<usize>;
9689
fn start($self: $S::Span) -> $S::Span;
9790
fn end($self: $S::Span) -> $S::Span;
9891
fn line($self: $S::Span) -> usize;
9992
fn column($self: $S::Span) -> usize;
93+
fn file($self: $S::Span) -> String;
94+
fn local_file($self: $S::Span) -> Option<String>;
10095
fn join($self: $S::Span, other: $S::Span) -> Option<$S::Span>;
10196
fn subspan($self: $S::Span, start: Bound<usize>, end: Bound<usize>) -> Option<$S::Span>;
10297
fn resolved_at($self: $S::Span, at: $S::Span) -> $S::Span;
@@ -119,7 +114,6 @@ macro_rules! with_api_handle_types {
119114
'owned:
120115
FreeFunctions,
121116
TokenStream,
122-
SourceFile,
123117

124118
'interned:
125119
Span,

proc_macro/src/bridge/server.rs

-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ with_api_handle_types!(define_server_handles);
8282
pub trait Types {
8383
type FreeFunctions: 'static;
8484
type TokenStream: 'static + Clone;
85-
type SourceFile: 'static + Clone;
8685
type Span: 'static + Copy + Eq + Hash;
8786
type Symbol: 'static;
8887
}

proc_macro/src/lib.rs

+19-41
Original file line numberDiff line numberDiff line change
@@ -491,12 +491,6 @@ impl Span {
491491
Span(bridge::client::Span::mixed_site())
492492
}
493493

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-
500494
/// The `Span` for the tokens in the previous macro expansion from which
501495
/// `self` was generated from, if any.
502496
#[unstable(feature = "proc_macro_span", issue = "54725")]
@@ -546,6 +540,25 @@ impl Span {
546540
self.0.column()
547541
}
548542

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+
549562
/// Creates a new span encompassing `self` and `other`.
550563
///
551564
/// Returns `None` if `self` and `other` are from different files.
@@ -614,41 +627,6 @@ impl fmt::Debug for Span {
614627
}
615628
}
616629

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-
652630
/// A single token or a delimited sequence of token trees (e.g., `[1, (), ..]`).
653631
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
654632
#[derive(Clone)]

0 commit comments

Comments
 (0)