Skip to content

Commit 9118645

Browse files
authored
Rollup merge of #139671 - m-ou-se:proc-macro-span, r=dtolnay
Proc macro span API redesign: Replace proc_macro::SourceFile by Span::{file, local_file} Simplification/redesign of the unstable proc macro span API, tracked in rust-lang/rust#54725: Before: ```rust impl Span { pub fn line(&self) -> usize; pub fn column(&self) -> usize; pub fn source_file(&self) -> SourceFile; } #[derive(Clone, Debug, PartialEq, Eq)] pub struct SourceFile { .. } impl !Send for SourceFile {} impl !Sync for SourceFile {} impl SourceFile { pub fn path(&self) -> PathBuf; pub fn is_real(&self) -> bool; } ``` After: ```rust impl Span { pub fn line(&self) -> usize; pub fn column(&self) -> usize; pub fn file(&self) -> String; // Mapped file name, for display purposes. pub fn local_file(&self) -> Option<PathBuf>; // Real file name as it exists on disk. } ``` This resolves the last blocker for stabilizing these methods. (Stabilizing will be a separate PR with FCP.)
2 parents 8166849 + 963d076 commit 9118645

File tree

3 files changed

+15
-38
lines changed

3 files changed

+15
-38
lines changed

crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::{
1111

1212
use intern::Symbol;
1313
use proc_macro::bridge::{self, server};
14-
use span::{FileId, Span, FIXUP_ERASED_FILE_AST_ID_MARKER};
14+
use span::{Span, FIXUP_ERASED_FILE_AST_ID_MARKER};
1515
use tt::{TextRange, TextSize};
1616

1717
use crate::server_impl::{literal_kind_to_internal, token_stream::TokenStreamBuilder, TopSubtree};
@@ -27,10 +27,6 @@ mod tt {
2727

2828
type TokenStream = crate::server_impl::TokenStream<Span>;
2929

30-
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
31-
pub struct SourceFile {
32-
file_id: FileId,
33-
}
3430
pub struct FreeFunctions;
3531

3632
pub struct RaSpanServer {
@@ -46,7 +42,6 @@ pub struct RaSpanServer {
4642
impl server::Types for RaSpanServer {
4743
type FreeFunctions = FreeFunctions;
4844
type TokenStream = TokenStream;
49-
type SourceFile = SourceFile;
5045
type Span = Span;
5146
type Symbol = Symbol;
5247
}
@@ -245,25 +240,17 @@ impl server::TokenStream for RaSpanServer {
245240
}
246241
}
247242

248-
impl server::SourceFile for RaSpanServer {
249-
fn eq(&mut self, file1: &Self::SourceFile, file2: &Self::SourceFile) -> bool {
250-
file1 == file2
251-
}
252-
fn path(&mut self, _file: &Self::SourceFile) -> String {
253-
// FIXME
254-
String::new()
255-
}
256-
fn is_real(&mut self, _file: &Self::SourceFile) -> bool {
257-
true
258-
}
259-
}
260-
261243
impl server::Span for RaSpanServer {
262244
fn debug(&mut self, span: Self::Span) -> String {
263245
format!("{:?}", span)
264246
}
265-
fn source_file(&mut self, span: Self::Span) -> Self::SourceFile {
266-
SourceFile { file_id: span.anchor.file_id.file_id() }
247+
fn file(&mut self, _: Self::Span) -> String {
248+
// FIXME
249+
String::new()
250+
}
251+
fn local_file(&mut self, _: Self::Span) -> Option<String> {
252+
// FIXME
253+
None
267254
}
268255
fn save_span(&mut self, _span: Self::Span) -> usize {
269256
// FIXME, quote is incompatible with third-party tools

crates/proc-macro-srv/src/server_impl/token_id.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ type Literal = tt::Literal;
2424
type Span = tt::TokenId;
2525
type TokenStream = crate::server_impl::TokenStream<Span>;
2626

27-
#[derive(Clone)]
28-
pub struct SourceFile;
2927
pub struct FreeFunctions;
3028

3129
pub struct TokenIdServer {
@@ -37,7 +35,6 @@ pub struct TokenIdServer {
3735
impl server::Types for TokenIdServer {
3836
type FreeFunctions = FreeFunctions;
3937
type TokenStream = TokenStream;
40-
type SourceFile = SourceFile;
4138
type Span = Span;
4239
type Symbol = Symbol;
4340
}
@@ -223,24 +220,15 @@ impl server::TokenStream for TokenIdServer {
223220
}
224221
}
225222

226-
impl server::SourceFile for TokenIdServer {
227-
fn eq(&mut self, _file1: &Self::SourceFile, _file2: &Self::SourceFile) -> bool {
228-
true
229-
}
230-
fn path(&mut self, _file: &Self::SourceFile) -> String {
231-
String::new()
232-
}
233-
fn is_real(&mut self, _file: &Self::SourceFile) -> bool {
234-
true
235-
}
236-
}
237-
238223
impl server::Span for TokenIdServer {
239224
fn debug(&mut self, span: Self::Span) -> String {
240225
format!("{:?}", span.0)
241226
}
242-
fn source_file(&mut self, _span: Self::Span) -> Self::SourceFile {
243-
SourceFile {}
227+
fn file(&mut self, _span: Self::Span) -> String {
228+
String::new()
229+
}
230+
fn local_file(&mut self, _span: Self::Span) -> Option<String> {
231+
None
244232
}
245233
fn save_span(&mut self, _span: Self::Span) -> usize {
246234
0

crates/proc-macro-srv/src/tests/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ fn test_fn_like_macro_clone_raw_ident() {
9797
}
9898

9999
#[test]
100+
#[cfg(not(bootstrap))]
100101
fn test_fn_like_fn_like_span_join() {
101102
assert_expand(
102103
"fn_like_span_join",
@@ -111,6 +112,7 @@ fn test_fn_like_fn_like_span_join() {
111112
}
112113

113114
#[test]
115+
#[cfg(not(bootstrap))]
114116
fn test_fn_like_fn_like_span_ops() {
115117
assert_expand(
116118
"fn_like_span_ops",

0 commit comments

Comments
 (0)