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(),
}
}
fn is_real(&mut self, file: &Self::SourceFile) -> bool {
file.is_real_file()
}
}
impl server::Span for Rustc<'_, '_> {

View File

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

View File

@ -623,36 +623,19 @@ impl SourceFile {
/// Gets the path to this source file.
///
/// ### 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.
///
/// [`is_real`]: Self::is_real
#[unstable(feature = "proc_macro_span", issue = "54725")]
pub fn path(&self) -> PathBuf {
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")]
impl fmt::Debug for SourceFile {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("SourceFile")
.field("path", &self.path())
.field("is_real", &self.is_real())
.finish()
f.debug_struct("SourceFile").field("path", &self.path()).finish()
}
}

View File

@ -10,21 +10,11 @@ pub fn reemit(input: TokenStream) -> TokenStream {
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]
pub fn assert_source_file(input: TokenStream) -> TokenStream {
for tk in input {
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()

View File

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