diff --git a/src/libproc_macro/lib.rs b/src/libproc_macro/lib.rs index c88a245d3b37..f85235278f87 100644 --- a/src/libproc_macro/lib.rs +++ b/src/libproc_macro/lib.rs @@ -50,6 +50,7 @@ mod diagnostic; pub use diagnostic::{Diagnostic, Level}; use std::{ascii, fmt, iter}; +use std::path::PathBuf; use rustc_data_structures::sync::Lrc; use std::str::FromStr; @@ -421,8 +422,11 @@ impl SourceFile { /// /// [`is_real`]: #method.is_real #[unstable(feature = "proc_macro_span", issue = "38356")] - pub fn path(&self) -> &FileName { - &self.filemap.name + pub fn path(&self) -> PathBuf { + match self.filemap.name { + FileName::Real(ref path) => path.clone(), + _ => PathBuf::from(self.filemap.name.to_string()) + } } /// Returns `true` if this source file is a real source file, and not generated by an external @@ -436,18 +440,12 @@ impl SourceFile { } } -#[unstable(feature = "proc_macro_span", issue = "38356")] -impl AsRef for SourceFile { - fn as_ref(&self) -> &FileName { - self.path() - } -} #[unstable(feature = "proc_macro_span", issue = "38356")] impl fmt::Debug for SourceFile { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("SourceFile") - .field("path", self.path()) + .field("path", &self.path()) .field("is_real", &self.is_real()) .finish() } @@ -463,13 +461,6 @@ impl PartialEq for SourceFile { #[unstable(feature = "proc_macro_span", issue = "38356")] impl Eq for SourceFile {} -#[unstable(feature = "proc_macro_span", issue = "38356")] -impl PartialEq for SourceFile { - fn eq(&self, other: &FileName) -> bool { - self.as_ref() == other - } -} - /// A single token or a delimited sequence of token trees (e.g. `[1, (), ..]`). #[stable(feature = "proc_macro_lib2", since = "1.29.0")] #[derive(Clone)]