Skip to content

Commit 648a009

Browse files
authored
Merge pull request #18670 from Veykril/push-ylomnylswnxm
internal: Drop proc-macro server support for ~1.66.0 and older toolchains
2 parents 05f9d44 + 1ae8416 commit 648a009

File tree

2 files changed

+30
-48
lines changed

2 files changed

+30
-48
lines changed

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

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

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

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

147147
FlatTree {
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-
},
148+
subtree: write_vec(w.subtree, SubtreeRepr::write),
153149
literal: if version >= EXTENDED_LEAF_DATA {
154150
write_vec(w.literal, LiteralRepr::write_with_kind)
155151
} else {
@@ -183,11 +179,7 @@ impl FlatTree {
183179
w.write(subtree);
184180

185181
FlatTree {
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-
},
182+
subtree: write_vec(w.subtree, SubtreeRepr::write),
191183
literal: if version >= EXTENDED_LEAF_DATA {
192184
write_vec(w.literal, LiteralRepr::write_with_kind)
193185
} else {
@@ -210,11 +202,7 @@ impl FlatTree {
210202
span_data_table: &SpanDataIndexMap,
211203
) -> tt::Subtree<Span> {
212204
Reader {
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-
},
205+
subtree: read_vec(self.subtree, SubtreeRepr::read),
218206
literal: if version >= EXTENDED_LEAF_DATA {
219207
read_vec(self.literal, LiteralRepr::read_with_kind)
220208
} else {
@@ -236,11 +224,7 @@ impl FlatTree {
236224

237225
pub fn to_subtree_unresolved(self, version: u32) -> tt::Subtree<TokenId> {
238226
Reader {
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-
},
227+
subtree: read_vec(self.subtree, SubtreeRepr::read),
244228
literal: if version >= EXTENDED_LEAF_DATA {
245229
read_vec(self.literal, LiteralRepr::read_with_kind)
246230
} else {
@@ -273,26 +257,7 @@ fn write_vec<T, F: Fn(T) -> [u32; N], const N: usize>(xs: Vec<T>, f: F) -> Vec<u
273257
}
274258

275259
impl SubtreeRepr {
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] {
260+
fn write(self) -> [u32; 5] {
296261
let kind = match self.kind {
297262
tt::DelimiterKind::Invisible => 0,
298263
tt::DelimiterKind::Parenthesis => 1,
@@ -301,7 +266,7 @@ impl SubtreeRepr {
301266
};
302267
[self.open.0, self.close.0, kind, self.tt[0], self.tt[1]]
303268
}
304-
fn read_with_close_span([open, close, kind, lo, len]: [u32; 5]) -> SubtreeRepr {
269+
fn read([open, close, kind, lo, len]: [u32; 5]) -> SubtreeRepr {
305270
let kind = match kind {
306271
0 => tt::DelimiterKind::Invisible,
307272
1 => tt::DelimiterKind::Parenthesis,

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

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,25 @@ 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!( "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."
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."
6178
),
6279
)),
6380
Ok(v) => {
@@ -72,10 +89,10 @@ impl ProcMacroProcessSrv {
7289
tracing::info!("Proc-macro server span mode: {:?}", srv.mode);
7390
Ok(srv)
7491
}
75-
Err(e) => {
76-
tracing::info!(%e, "proc-macro version check failed, restarting and assuming version 0");
77-
create_srv(false)
78-
}
92+
Err(e) => Err(io::Error::new(
93+
io::ErrorKind::Other,
94+
format!("Failed to fetch proc-macro server version: {e}"),
95+
)),
7996
}
8097
}
8198

0 commit comments

Comments
 (0)