Skip to content

Commit 56668e6

Browse files
committed
proc_macro: don't expose compiler-internal FileName in public API.
1 parent d708d02 commit 56668e6

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

src/libproc_macro/lib.rs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ mod diagnostic;
6464
pub use diagnostic::{Diagnostic, Level};
6565

6666
use std::{ascii, fmt, iter};
67+
use std::path::PathBuf;
6768
use rustc_data_structures::sync::Lrc;
6869
use std::str::FromStr;
6970

@@ -332,14 +333,17 @@ impl SourceFile {
332333
/// the command line, the path as given may not actually be valid.
333334
///
334335
/// [`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+
}
338342
}
339343

340344
/// Returns `true` if this source file is a real source file, and not generated by an external
341345
/// macro's expansion.
342-
# [unstable(feature = "proc_macro", issue = "38356")]
346+
#[unstable(feature = "proc_macro", issue = "38356")]
343347
pub fn is_real(&self) -> bool {
344348
// This is a hack until intercrate spans are implemented and we can have real source files
345349
// for spans generated in external macros.
@@ -348,18 +352,12 @@ impl SourceFile {
348352
}
349353
}
350354

351-
#[unstable(feature = "proc_macro", issue = "38356")]
352-
impl AsRef<FileName> for SourceFile {
353-
fn as_ref(&self) -> &FileName {
354-
self.path()
355-
}
356-
}
357355

358356
#[unstable(feature = "proc_macro", issue = "38356")]
359357
impl fmt::Debug for SourceFile {
360358
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
361359
f.debug_struct("SourceFile")
362-
.field("path", self.path())
360+
.field("path", &self.path())
363361
.field("is_real", &self.is_real())
364362
.finish()
365363
}
@@ -375,13 +373,6 @@ impl PartialEq for SourceFile {
375373
#[unstable(feature = "proc_macro", issue = "38356")]
376374
impl Eq for SourceFile {}
377375

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-
385376
/// A single token or a delimited sequence of token trees (e.g. `[1, (), ..]`).
386377
#[unstable(feature = "proc_macro", issue = "38356")]
387378
#[derive(Clone, Debug)]

0 commit comments

Comments
 (0)