1
Fork 0

Remove proc_macro::SourceFile::is_real().

This commit is contained in:
Mara Bos 2025-04-11 13:47:52 +02:00
parent 81d8c747fb
commit 6788ce76c9
5 changed files with 3 additions and 37 deletions

View file

@ -689,10 +689,6 @@ impl server::SourceFile for Rustc<'_, '_> {
_ => file.name.prefer_local().to_string(), _ => file.name.prefer_local().to_string(),
} }
} }
fn is_real(&mut self, file: &Self::SourceFile) -> bool {
file.is_real_file()
}
} }
impl server::Span for Rustc<'_, '_> { impl server::Span for Rustc<'_, '_> {

View file

@ -86,7 +86,6 @@ macro_rules! with_api {
fn clone($self: &$S::SourceFile) -> $S::SourceFile; fn clone($self: &$S::SourceFile) -> $S::SourceFile;
fn eq($self: &$S::SourceFile, other: &$S::SourceFile) -> bool; fn eq($self: &$S::SourceFile, other: &$S::SourceFile) -> bool;
fn path($self: &$S::SourceFile) -> String; fn path($self: &$S::SourceFile) -> String;
fn is_real($self: &$S::SourceFile) -> bool;
}, },
Span { Span {
fn debug($self: $S::Span) -> String; fn debug($self: $S::Span) -> String;

View file

@ -623,36 +623,19 @@ impl SourceFile {
/// Gets the path to this source file. /// Gets the path to this source file.
/// ///
/// ### Note /// ### Note
/// If the code span associated with this `SourceFile` was generated by an external macro, this
/// macro, this might not be an actual path on the filesystem. Use [`is_real`] to check.
/// ///
/// Also note that even if `is_real` returns `true`, if `--remap-path-prefix` was passed on /// If `--remap-path-prefix` was passed on
/// the command line, the path as given might not actually be valid. /// the command line, the path as given might not actually be valid.
///
/// [`is_real`]: Self::is_real
#[unstable(feature = "proc_macro_span", issue = "54725")] #[unstable(feature = "proc_macro_span", issue = "54725")]
pub fn path(&self) -> PathBuf { pub fn path(&self) -> PathBuf {
PathBuf::from(self.0.path()) PathBuf::from(self.0.path())
} }
/// Returns `true` if this source file is a real source file, and not generated by an external
/// macro's expansion.
#[unstable(feature = "proc_macro_span", issue = "54725")]
pub fn is_real(&self) -> bool {
// This is a hack until intercrate spans are implemented and we can have real source files
// for spans generated in external macros.
// https://github.com/rust-lang/rust/pull/43604#issuecomment-333334368
self.0.is_real()
}
} }
#[unstable(feature = "proc_macro_span", issue = "54725")] #[unstable(feature = "proc_macro_span", issue = "54725")]
impl fmt::Debug for SourceFile { impl fmt::Debug for SourceFile {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("SourceFile") f.debug_struct("SourceFile").field("path", &self.path()).finish()
.field("path", &self.path())
.field("is_real", &self.is_real())
.finish()
} }
} }

View file

@ -10,21 +10,11 @@ pub fn reemit(input: TokenStream) -> TokenStream {
input.to_string().parse().unwrap() input.to_string().parse().unwrap()
} }
#[proc_macro]
pub fn assert_fake_source_file(input: TokenStream) -> TokenStream {
for tk in input {
let source_file = tk.span().source_file();
assert!(!source_file.is_real(), "Source file is real: {:?}", source_file);
}
"".parse().unwrap()
}
#[proc_macro] #[proc_macro]
pub fn assert_source_file(input: TokenStream) -> TokenStream { pub fn assert_source_file(input: TokenStream) -> TokenStream {
for tk in input { for tk in input {
let source_file = tk.span().source_file(); let source_file = tk.span().source_file();
assert!(source_file.is_real(), "Source file is not real: {:?}", source_file); assert!(!source_file.as_os_str().is_empty(), "No source file for span: {:?}", tk.span());
} }
"".parse().unwrap() "".parse().unwrap()

View file

@ -8,8 +8,6 @@ extern crate span_test_macros;
extern crate span_api_tests; extern crate span_api_tests;
// FIXME(69775): Investigate `assert_fake_source_file`.
use span_api_tests::{reemit, assert_source_file, macro_stringify}; use span_api_tests::{reemit, assert_source_file, macro_stringify};
macro_rules! say_hello { macro_rules! say_hello {