Skip to content

Commit 4774e6e

Browse files
committed
Fix up feature gates
1 parent 5409a40 commit 4774e6e

File tree

11 files changed

+149
-139
lines changed

11 files changed

+149
-139
lines changed

crates/proc-macro-api/src/legacy_protocol/msg/flat.rs

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@
3434
//! as we don't have bincode in Cargo.toml yet, lets stick with serde_json for
3535
//! the time being.
3636
37+
#[cfg(feature = "sysroot-abi")]
38+
use proc_macro_srv::TokenStream;
39+
3740
use std::collections::VecDeque;
3841

3942
use intern::Symbol;
40-
use proc_macro_srv::TokenStream;
4143
use rustc_hash::FxHashMap;
4244
use serde_derive::{Deserialize, Serialize};
4345
use span::{EditionedFileId, ErasedFileAstId, Span, SpanAnchor, SyntaxContext, TextRange};
@@ -162,6 +164,39 @@ impl FlatTree {
162164
}
163165
}
164166

167+
pub fn to_subtree_resolved(
168+
self,
169+
version: u32,
170+
span_data_table: &SpanDataIndexMap,
171+
) -> tt::TopSubtree<Span> {
172+
Reader::<Span> {
173+
subtree: if version >= ENCODE_CLOSE_SPAN_VERSION {
174+
read_vec(self.subtree, SubtreeRepr::read_with_close_span)
175+
} else {
176+
read_vec(self.subtree, SubtreeRepr::read)
177+
},
178+
literal: if version >= EXTENDED_LEAF_DATA {
179+
read_vec(self.literal, LiteralRepr::read_with_kind)
180+
} else {
181+
read_vec(self.literal, LiteralRepr::read)
182+
},
183+
punct: read_vec(self.punct, PunctRepr::read),
184+
ident: if version >= EXTENDED_LEAF_DATA {
185+
read_vec(self.ident, IdentRepr::read_with_rawness)
186+
} else {
187+
read_vec(self.ident, IdentRepr::read)
188+
},
189+
token_tree: self.token_tree,
190+
text: self.text,
191+
span_data_table,
192+
version,
193+
}
194+
.read_subtree()
195+
}
196+
}
197+
198+
#[cfg(feature = "sysroot-abi")]
199+
impl FlatTree {
165200
pub fn from_tokenstream(
166201
tokenstream: proc_macro_srv::TokenStream<Span>,
167202
version: u32,
@@ -265,37 +300,6 @@ impl FlatTree {
265300
}
266301
}
267302

268-
pub fn to_subtree_resolved(
269-
self,
270-
version: u32,
271-
span_data_table: &SpanDataIndexMap,
272-
) -> tt::TopSubtree<Span> {
273-
Reader::<Span> {
274-
subtree: if version >= ENCODE_CLOSE_SPAN_VERSION {
275-
read_vec(self.subtree, SubtreeRepr::read_with_close_span)
276-
} else {
277-
read_vec(self.subtree, SubtreeRepr::read)
278-
},
279-
literal: if version >= EXTENDED_LEAF_DATA {
280-
read_vec(self.literal, LiteralRepr::read_with_kind)
281-
} else {
282-
read_vec(self.literal, LiteralRepr::read)
283-
},
284-
punct: read_vec(self.punct, PunctRepr::read),
285-
ident: if version >= EXTENDED_LEAF_DATA {
286-
read_vec(self.ident, IdentRepr::read_with_rawness)
287-
} else {
288-
read_vec(self.ident, IdentRepr::read)
289-
},
290-
token_tree: self.token_tree,
291-
text: self.text,
292-
span_data_table,
293-
version,
294-
}
295-
.read_subtree()
296-
}
297-
}
298-
impl FlatTree {
299303
pub fn to_tokenstream_unresolved<T: SpanTransformer<Table = ()>>(
300304
self,
301305
version: u32,
@@ -836,6 +840,7 @@ impl<T: SpanTransformer> Reader<'_, T> {
836840
}
837841
}
838842

843+
#[cfg(feature = "sysroot-abi")]
839844
impl<T: SpanTransformer> Reader<'_, T> {
840845
pub(crate) fn read_tokenstream(self) -> proc_macro_srv::TokenStream<T::Span> {
841846
let mut res: Vec<Option<proc_macro_srv::Group<T::Span>>> = vec![None; self.subtree.len()];

crates/proc-macro-srv-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ clap = {version = "4.5.42", default-features = false, features = ["std"]}
1818
postcard = { version = "1.1.3", optional = true }
1919

2020
[features]
21-
default = ["postcard", "sysroot-abi"]
21+
default = ["postcard"]
2222
sysroot-abi = ["proc-macro-srv/sysroot-abi", "proc-macro-api/sysroot-abi"]
2323
in-rust-tree = ["proc-macro-srv/in-rust-tree", "sysroot-abi"]
2424
postcard = ["dep:postcard"]

crates/proc-macro-srv-cli/build.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::{env, path::PathBuf, process::Command};
55
fn main() {
66
set_rerun();
77
set_commit_info();
8-
println!("cargo::rustc-check-cfg=cfg(rust_analyzer)");
98
}
109

1110
fn set_rerun() {

crates/proc-macro-srv-cli/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ extern crate rustc_driver as _;
99

1010
mod version;
1111

12-
#[cfg(any(feature = "sysroot-abi", rust_analyzer))]
12+
#[cfg(any(feature = "sysroot-abi"))]
1313
mod main_loop;
1414
use clap::{Command, ValueEnum};
15-
#[cfg(any(feature = "sysroot-abi", rust_analyzer))]
15+
#[cfg(any(feature = "sysroot-abi"))]
1616
use main_loop::run;
1717

1818
fn main() -> std::io::Result<()> {
@@ -77,7 +77,7 @@ impl ValueEnum for ProtocolFormat {
7777
}
7878
}
7979

80-
#[cfg(not(any(feature = "sysroot-abi", rust_analyzer)))]
80+
#[cfg(not(feature = "sysroot-abi"))]
8181
fn run(_: ProtocolFormat) -> std::io::Result<()> {
8282
Err(std::io::Error::new(
8383
std::io::ErrorKind::Unsupported,

crates/proc-macro-srv/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ expect-test.workspace = true
3636
proc-macro-test.path = "./proc-macro-test"
3737

3838
[features]
39-
default = ["sysroot-abi"]
39+
default = []
4040
sysroot-abi = []
4141
in-rust-tree = ["sysroot-abi"]
4242

crates/proc-macro-srv/build.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
use std::{env, process::Command};
55

66
fn main() {
7-
println!("cargo::rustc-check-cfg=cfg(rust_analyzer)");
8-
97
let rustc = env::var("RUSTC").expect("proc-macro-srv's build script expects RUSTC to be set");
108
#[allow(clippy::disallowed_methods)]
119
let output = Command::new(rustc).arg("--version").output().expect("rustc --version must run");

crates/proc-macro-srv/src/bridge.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! `proc_macro::bridge` newtypes.
2+
13
use proc_macro::bridge as pm_bridge;
24

35
pub use pm_bridge::{DelimSpan, Diagnostic, ExpnGlobals, LitKind};

crates/proc-macro-srv/src/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@
1010
//! * By **copying** the whole rustc `lib_proc_macro` code, we are able to build this with `stable`
1111
//! rustc rather than `unstable`. (Although in general ABI compatibility is still an issue)…
1212
13-
#![cfg(any(feature = "sysroot-abi", rust_analyzer))]
14-
#![cfg_attr(not(feature = "sysroot-abi"), allow(unused_crate_dependencies))]
13+
#![cfg(feature = "sysroot-abi")]
1514
#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
1615
#![feature(proc_macro_internals, proc_macro_diagnostic, proc_macro_span)]
17-
#![allow(unreachable_pub, internal_features, clippy::disallowed_types, clippy::print_stderr)]
16+
#![allow(
17+
unreachable_pub,
18+
internal_features,
19+
clippy::disallowed_types,
20+
clippy::print_stderr,
21+
unused_crate_dependencies
22+
)]
1823
#![deny(deprecated_safe, clippy::undocumented_unsafe_blocks)]
1924

2025
extern crate proc_macro;

0 commit comments

Comments
 (0)