Skip to content

Commit 2d895a7

Browse files
authored
Merge pull request rust-lang#18731 from rust-lang/revert-18670-push-ylomnylswnxm
Revert "internal: Drop proc-macro server support for ~1.66.0 and older toolchains"
2 parents b694ff3 + b7bde82 commit 2d895a7

File tree

2 files changed

+48
-30
lines changed

2 files changed

+48
-30
lines changed

src/tools/rust-analyzer/crates/proc-macro-api/src/msg/flat.rs

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use rustc_hash::FxHashMap;
4242
use serde_derive::{Deserialize, Serialize};
4343
use span::{EditionedFileId, ErasedFileAstId, Span, SpanAnchor, SyntaxContextId, TextRange};
4444

45-
use crate::msg::EXTENDED_LEAF_DATA;
45+
use crate::msg::{ENCODE_CLOSE_SPAN_VERSION, EXTENDED_LEAF_DATA};
4646

4747
pub type SpanDataIndexMap =
4848
indexmap::IndexSet<Span, std::hash::BuildHasherDefault<rustc_hash::FxHasher>>;
@@ -145,7 +145,11 @@ impl FlatTree {
145145
w.write(subtree);
146146

147147
FlatTree {
148-
subtree: write_vec(w.subtree, SubtreeRepr::write),
148+
subtree: if version >= ENCODE_CLOSE_SPAN_VERSION {
149+
write_vec(w.subtree, SubtreeRepr::write_with_close_span)
150+
} else {
151+
write_vec(w.subtree, SubtreeRepr::write)
152+
},
149153
literal: if version >= EXTENDED_LEAF_DATA {
150154
write_vec(w.literal, LiteralRepr::write_with_kind)
151155
} else {
@@ -179,7 +183,11 @@ impl FlatTree {
179183
w.write(subtree);
180184

181185
FlatTree {
182-
subtree: write_vec(w.subtree, SubtreeRepr::write),
186+
subtree: if version >= ENCODE_CLOSE_SPAN_VERSION {
187+
write_vec(w.subtree, SubtreeRepr::write_with_close_span)
188+
} else {
189+
write_vec(w.subtree, SubtreeRepr::write)
190+
},
183191
literal: if version >= EXTENDED_LEAF_DATA {
184192
write_vec(w.literal, LiteralRepr::write_with_kind)
185193
} else {
@@ -202,7 +210,11 @@ impl FlatTree {
202210
span_data_table: &SpanDataIndexMap,
203211
) -> tt::Subtree<Span> {
204212
Reader {
205-
subtree: read_vec(self.subtree, SubtreeRepr::read),
213+
subtree: if version >= ENCODE_CLOSE_SPAN_VERSION {
214+
read_vec(self.subtree, SubtreeRepr::read_with_close_span)
215+
} else {
216+
read_vec(self.subtree, SubtreeRepr::read)
217+
},
206218
literal: if version >= EXTENDED_LEAF_DATA {
207219
read_vec(self.literal, LiteralRepr::read_with_kind)
208220
} else {
@@ -224,7 +236,11 @@ impl FlatTree {
224236

225237
pub fn to_subtree_unresolved(self, version: u32) -> tt::Subtree<TokenId> {
226238
Reader {
227-
subtree: read_vec(self.subtree, SubtreeRepr::read),
239+
subtree: if version >= ENCODE_CLOSE_SPAN_VERSION {
240+
read_vec(self.subtree, SubtreeRepr::read_with_close_span)
241+
} else {
242+
read_vec(self.subtree, SubtreeRepr::read)
243+
},
228244
literal: if version >= EXTENDED_LEAF_DATA {
229245
read_vec(self.literal, LiteralRepr::read_with_kind)
230246
} else {
@@ -257,7 +273,26 @@ fn write_vec<T, F: Fn(T) -> [u32; N], const N: usize>(xs: Vec<T>, f: F) -> Vec<u
257273
}
258274

259275
impl SubtreeRepr {
260-
fn write(self) -> [u32; 5] {
276+
fn write(self) -> [u32; 4] {
277+
let kind = match self.kind {
278+
tt::DelimiterKind::Invisible => 0,
279+
tt::DelimiterKind::Parenthesis => 1,
280+
tt::DelimiterKind::Brace => 2,
281+
tt::DelimiterKind::Bracket => 3,
282+
};
283+
[self.open.0, kind, self.tt[0], self.tt[1]]
284+
}
285+
fn read([open, kind, lo, len]: [u32; 4]) -> SubtreeRepr {
286+
let kind = match kind {
287+
0 => tt::DelimiterKind::Invisible,
288+
1 => tt::DelimiterKind::Parenthesis,
289+
2 => tt::DelimiterKind::Brace,
290+
3 => tt::DelimiterKind::Bracket,
291+
other => panic!("bad kind {other}"),
292+
};
293+
SubtreeRepr { open: TokenId(open), close: TokenId(!0), kind, tt: [lo, len] }
294+
}
295+
fn write_with_close_span(self) -> [u32; 5] {
261296
let kind = match self.kind {
262297
tt::DelimiterKind::Invisible => 0,
263298
tt::DelimiterKind::Parenthesis => 1,
@@ -266,7 +301,7 @@ impl SubtreeRepr {
266301
};
267302
[self.open.0, self.close.0, kind, self.tt[0], self.tt[1]]
268303
}
269-
fn read([open, close, kind, lo, len]: [u32; 5]) -> SubtreeRepr {
304+
fn read_with_close_span([open, close, kind, lo, len]: [u32; 5]) -> SubtreeRepr {
270305
let kind = match kind {
271306
0 => tt::DelimiterKind::Invisible,
272307
1 => tt::DelimiterKind::Parenthesis,

src/tools/rust-analyzer/crates/proc-macro-api/src/process.rs

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,8 @@ impl ProcMacroProcessSrv {
5656
match srv.version_check() {
5757
Ok(v) if v > CURRENT_API_VERSION => Err(io::Error::new(
5858
io::ErrorKind::Other,
59-
format!(
60-
"The version of the proc-macro server ({v}) in your Rust toolchain \
61-
is newer than the version supported by your rust-analyzer ({CURRENT_API_VERSION}).
62-
\
63-
This will prevent proc-macro expansion from working. \
64-
Please consider updating your rust-analyzer to ensure compatibility with your \
65-
current toolchain."
66-
),
67-
)),
68-
Ok(v) if v < RUST_ANALYZER_SPAN_SUPPORT => Err(io::Error::new(
69-
io::ErrorKind::Other,
70-
format!(
71-
"The version of the proc-macro server ({v}) in your Rust toolchain \
72-
is too old and no longer supported by your rust-analyzer which requires\
73-
version {RUST_ANALYZER_SPAN_SUPPORT} or higher.
74-
\
75-
This will prevent proc-macro expansion from working. \
76-
Please consider updating your toolchain or downgrading your rust-analyzer \
77-
to ensure compatibility with your current toolchain."
59+
format!( "The version of the proc-macro server ({v}) in your Rust toolchain is newer than the version supported by your rust-analyzer ({CURRENT_API_VERSION}).
60+
This will prevent proc-macro expansion from working. Please consider updating your rust-analyzer to ensure compatibility with your current toolchain."
7861
),
7962
)),
8063
Ok(v) => {
@@ -89,10 +72,10 @@ impl ProcMacroProcessSrv {
8972
tracing::info!("Proc-macro server span mode: {:?}", srv.mode);
9073
Ok(srv)
9174
}
92-
Err(e) => Err(io::Error::new(
93-
io::ErrorKind::Other,
94-
format!("Failed to fetch proc-macro server version: {e}"),
95-
)),
75+
Err(e) => {
76+
tracing::info!(%e, "proc-macro version check failed, restarting and assuming version 0");
77+
create_srv(false)
78+
}
9679
}
9780
}
9881

0 commit comments

Comments
 (0)