mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-30 10:45:18 +00:00
proc_macro: don't expose compiler-internal FileName in public API.
This commit is contained in:
parent
56aaa53278
commit
e5e29d1a19
@ -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<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()
|
||||
}
|
||||
@ -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)]
|
||||
|
Loading…
Reference in New Issue
Block a user