Skip to content

Commit e5e29d1

Browse files
committed
proc_macro: don't expose compiler-internal FileName in public API.
1 parent 56aaa53 commit e5e29d1

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

src/libproc_macro/lib.rs

+7-16
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ mod diagnostic;
5050
pub use diagnostic::{Diagnostic, Level};
5151

5252
use std::{ascii, fmt, iter};
53+
use std::path::PathBuf;
5354
use rustc_data_structures::sync::Lrc;
5455
use std::str::FromStr;
5556

@@ -421,8 +422,11 @@ impl SourceFile {
421422
///
422423
/// [`is_real`]: #method.is_real
423424
#[unstable(feature = "proc_macro_span", issue = "38356")]
424-
pub fn path(&self) -> &FileName {
425-
&self.filemap.name
425+
pub fn path(&self) -> PathBuf {
426+
match self.filemap.name {
427+
FileName::Real(ref path) => path.clone(),
428+
_ => PathBuf::from(self.filemap.name.to_string())
429+
}
426430
}
427431

428432
/// Returns `true` if this source file is a real source file, and not generated by an external
@@ -436,18 +440,12 @@ impl SourceFile {
436440
}
437441
}
438442

439-
#[unstable(feature = "proc_macro_span", issue = "38356")]
440-
impl AsRef<FileName> for SourceFile {
441-
fn as_ref(&self) -> &FileName {
442-
self.path()
443-
}
444-
}
445443

446444
#[unstable(feature = "proc_macro_span", issue = "38356")]
447445
impl fmt::Debug for SourceFile {
448446
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
449447
f.debug_struct("SourceFile")
450-
.field("path", self.path())
448+
.field("path", &self.path())
451449
.field("is_real", &self.is_real())
452450
.finish()
453451
}
@@ -463,13 +461,6 @@ impl PartialEq for SourceFile {
463461
#[unstable(feature = "proc_macro_span", issue = "38356")]
464462
impl Eq for SourceFile {}
465463

466-
#[unstable(feature = "proc_macro_span", issue = "38356")]
467-
impl PartialEq<FileName> for SourceFile {
468-
fn eq(&self, other: &FileName) -> bool {
469-
self.as_ref() == other
470-
}
471-
}
472-
473464
/// A single token or a delimited sequence of token trees (e.g. `[1, (), ..]`).
474465
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
475466
#[derive(Clone)]

0 commit comments

Comments
 (0)