Skip to content

Commit

Permalink
proc_macro: don't expose compiler-internal FileName in public API.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Jul 19, 2018
1 parent 56aaa53 commit e5e29d1
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions src/libproc_macro/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -436,18 +440,12 @@ impl SourceFile {
}
}

#[unstable(feature = "proc_macro_span", issue = "38356")]
impl AsRef<FileName> 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()
}
Expand All @@ -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<FileName> 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)]
Expand Down

0 comments on commit e5e29d1

Please sign in to comment.