From 4a996c2c7c22a8c77e90a55b4a8c89f27c7b6c9d Mon Sep 17 00:00:00 2001 From: Arthur Beck Date: Mon, 16 Dec 2024 17:34:15 -0600 Subject: [PATCH 1/3] Begun reorganization of proc_macro crate --- .../src/{bridge => backend}/arena.rs | 0 .../src/{ => backend}/bridge/buffer.rs | 0 .../src/{ => backend}/bridge/client.rs | 0 .../src/{ => backend}/bridge/closure.rs | 0 .../src/{ => backend}/bridge/handle.rs | 2 +- .../src/{ => backend}/bridge/mod.rs | 4 - .../src/{ => backend}/bridge/rpc.rs | 0 .../{ => backend}/bridge/selfless_reify.rs | 0 .../src/{ => backend}/bridge/server.rs | 0 .../src/{ => backend}/bridge/symbol.rs | 10 +- .../src/{bridge => backend}/fxhash.rs | 0 library/proc_macro/src/backend/mod.rs | 7 + library/proc_macro/src/diagnostic.rs | 8 +- library/proc_macro/src/lib.rs | 166 ++++++++++-------- 14 files changed, 110 insertions(+), 87 deletions(-) rename library/proc_macro/src/{bridge => backend}/arena.rs (100%) rename library/proc_macro/src/{ => backend}/bridge/buffer.rs (100%) rename library/proc_macro/src/{ => backend}/bridge/client.rs (100%) rename library/proc_macro/src/{ => backend}/bridge/closure.rs (100%) rename library/proc_macro/src/{ => backend}/bridge/handle.rs (98%) rename library/proc_macro/src/{ => backend}/bridge/mod.rs (99%) rename library/proc_macro/src/{ => backend}/bridge/rpc.rs (100%) rename library/proc_macro/src/{ => backend}/bridge/selfless_reify.rs (100%) rename library/proc_macro/src/{ => backend}/bridge/server.rs (100%) rename library/proc_macro/src/{ => backend}/bridge/symbol.rs (96%) rename library/proc_macro/src/{bridge => backend}/fxhash.rs (100%) create mode 100644 library/proc_macro/src/backend/mod.rs diff --git a/library/proc_macro/src/bridge/arena.rs b/library/proc_macro/src/backend/arena.rs similarity index 100% rename from library/proc_macro/src/bridge/arena.rs rename to library/proc_macro/src/backend/arena.rs diff --git a/library/proc_macro/src/bridge/buffer.rs b/library/proc_macro/src/backend/bridge/buffer.rs similarity index 100% rename from library/proc_macro/src/bridge/buffer.rs rename to library/proc_macro/src/backend/bridge/buffer.rs diff --git a/library/proc_macro/src/bridge/client.rs b/library/proc_macro/src/backend/bridge/client.rs similarity index 100% rename from library/proc_macro/src/bridge/client.rs rename to library/proc_macro/src/backend/bridge/client.rs diff --git a/library/proc_macro/src/bridge/closure.rs b/library/proc_macro/src/backend/bridge/closure.rs similarity index 100% rename from library/proc_macro/src/bridge/closure.rs rename to library/proc_macro/src/backend/bridge/closure.rs diff --git a/library/proc_macro/src/bridge/handle.rs b/library/proc_macro/src/backend/bridge/handle.rs similarity index 98% rename from library/proc_macro/src/bridge/handle.rs rename to library/proc_macro/src/backend/bridge/handle.rs index 8c53bb609f60c..2f5e086f7d5f3 100644 --- a/library/proc_macro/src/bridge/handle.rs +++ b/library/proc_macro/src/backend/bridge/handle.rs @@ -6,7 +6,7 @@ use std::num::NonZero; use std::ops::{Index, IndexMut}; use std::sync::atomic::{AtomicU32, Ordering}; -use super::fxhash::FxHashMap; +use crate::backend::fxhash::FxHashMap; pub(super) type Handle = NonZero; diff --git a/library/proc_macro/src/bridge/mod.rs b/library/proc_macro/src/backend/bridge/mod.rs similarity index 99% rename from library/proc_macro/src/bridge/mod.rs rename to library/proc_macro/src/backend/bridge/mod.rs index 03c3e697cfe2b..e24851ea91954 100644 --- a/library/proc_macro/src/bridge/mod.rs +++ b/library/proc_macro/src/backend/bridge/mod.rs @@ -146,8 +146,6 @@ macro_rules! reverse_decode { } } -#[allow(unsafe_code)] -mod arena; #[allow(unsafe_code)] mod buffer; #[deny(unsafe_code)] @@ -155,8 +153,6 @@ pub mod client; #[allow(unsafe_code)] mod closure; #[forbid(unsafe_code)] -mod fxhash; -#[forbid(unsafe_code)] mod handle; #[macro_use] #[forbid(unsafe_code)] diff --git a/library/proc_macro/src/bridge/rpc.rs b/library/proc_macro/src/backend/bridge/rpc.rs similarity index 100% rename from library/proc_macro/src/bridge/rpc.rs rename to library/proc_macro/src/backend/bridge/rpc.rs diff --git a/library/proc_macro/src/bridge/selfless_reify.rs b/library/proc_macro/src/backend/bridge/selfless_reify.rs similarity index 100% rename from library/proc_macro/src/bridge/selfless_reify.rs rename to library/proc_macro/src/backend/bridge/selfless_reify.rs diff --git a/library/proc_macro/src/bridge/server.rs b/library/proc_macro/src/backend/bridge/server.rs similarity index 100% rename from library/proc_macro/src/bridge/server.rs rename to library/proc_macro/src/backend/bridge/server.rs diff --git a/library/proc_macro/src/bridge/symbol.rs b/library/proc_macro/src/backend/bridge/symbol.rs similarity index 96% rename from library/proc_macro/src/bridge/symbol.rs rename to library/proc_macro/src/backend/bridge/symbol.rs index 6a1cecd69fb5f..55dd6a840146f 100644 --- a/library/proc_macro/src/bridge/symbol.rs +++ b/library/proc_macro/src/backend/bridge/symbol.rs @@ -127,8 +127,8 @@ impl DecodeMut<'_, '_, S> for Symbol { thread_local! { static INTERNER: RefCell = RefCell::new(Interner { - arena: arena::Arena::new(), - names: fxhash::FxHashMap::default(), + arena: crate::backend::arena::Arena::new(), + names: crate::backend::fxhash::FxHashMap::default(), strings: Vec::new(), // Start with a base of 1 to make sure that `NonZero` works. sym_base: NonZero::new(1).unwrap(), @@ -137,11 +137,11 @@ thread_local! { /// Basic interner for a `Symbol`, inspired by the one in `rustc_span`. struct Interner { - arena: arena::Arena, + arena: crate::backend::arena::Arena, // SAFETY: These `'static` lifetimes are actually references to data owned // by the Arena. This is safe, as we never return them as static references // from `Interner`. - names: fxhash::FxHashMap<&'static str, Symbol>, + names: crate::backend::fxhash::FxHashMap<&'static str, Symbol>, strings: Vec<&'static str>, // The offset to apply to symbol names stored in the interner. This is used // to ensure that symbol names are not re-used after the interner is @@ -194,6 +194,6 @@ impl Interner { // SAFETY: This is cleared after the names and strings tables are // cleared out, so no references into the arena should remain. - self.arena = arena::Arena::new(); + self.arena = crate::backend::arena::Arena::new(); } } diff --git a/library/proc_macro/src/bridge/fxhash.rs b/library/proc_macro/src/backend/fxhash.rs similarity index 100% rename from library/proc_macro/src/bridge/fxhash.rs rename to library/proc_macro/src/backend/fxhash.rs diff --git a/library/proc_macro/src/backend/mod.rs b/library/proc_macro/src/backend/mod.rs new file mode 100644 index 0000000000000..730e9953de44d --- /dev/null +++ b/library/proc_macro/src/backend/mod.rs @@ -0,0 +1,7 @@ +pub mod bridge; + +#[allow(unsafe_code)] +pub(self) mod arena; + +#[forbid(unsafe_code)] +pub(self) mod fxhash; diff --git a/library/proc_macro/src/diagnostic.rs b/library/proc_macro/src/diagnostic.rs index 5a209f7c7aa18..30d806338fe73 100644 --- a/library/proc_macro/src/diagnostic.rs +++ b/library/proc_macro/src/diagnostic.rs @@ -161,8 +161,10 @@ impl Diagnostic { /// Emit the diagnostic. #[unstable(feature = "proc_macro_diagnostic", issue = "54140")] pub fn emit(self) { - fn to_internal(diag: Diagnostic) -> crate::bridge::Diagnostic { - crate::bridge::Diagnostic { + fn to_internal( + diag: Diagnostic, + ) -> crate::backend::bridge::Diagnostic { + crate::backend::bridge::Diagnostic { level: diag.level, message: diag.message, spans: diag.spans.into_iter().map(|s| s.0).collect(), @@ -170,6 +172,6 @@ impl Diagnostic { } } - crate::bridge::client::FreeFunctions::emit_diagnostic(to_internal(self)); + crate::backend::bridge::client::FreeFunctions::emit_diagnostic(to_internal(self)); } } diff --git a/library/proc_macro/src/lib.rs b/library/proc_macro/src/lib.rs index 26a09f0daca02..6dc06e52e137e 100644 --- a/library/proc_macro/src/lib.rs +++ b/library/proc_macro/src/lib.rs @@ -35,7 +35,7 @@ #[unstable(feature = "proc_macro_internals", issue = "27812")] #[doc(hidden)] -pub mod bridge; +pub mod backend; mod diagnostic; mod escape; @@ -69,7 +69,7 @@ use crate::escape::{EscapeOptions, escape_bytes}; /// inside of a procedural macro, false if invoked from any other binary. #[stable(feature = "proc_macro_is_available", since = "1.57.0")] pub fn is_available() -> bool { - bridge::client::is_available() + backend::bridge::client::is_available() } /// The main type provided by this crate, representing an abstract stream of @@ -82,7 +82,7 @@ pub fn is_available() -> bool { #[rustc_diagnostic_item = "TokenStream"] #[stable(feature = "proc_macro_lib", since = "1.15.0")] #[derive(Clone)] -pub struct TokenStream(Option); +pub struct TokenStream(Option); #[stable(feature = "proc_macro_lib", since = "1.15.0")] impl !Send for TokenStream {} @@ -158,7 +158,7 @@ impl TokenStream { #[unstable(feature = "proc_macro_expand", issue = "90765")] pub fn expand_expr(&self) -> Result { let stream = self.0.as_ref().ok_or(ExpandError)?; - match bridge::client::TokenStream::expand_expr(stream) { + match backend::bridge::client::TokenStream::expand_expr(stream) { Ok(stream) => Ok(TokenStream(Some(stream))), Err(_) => Err(ExpandError), } @@ -177,7 +177,7 @@ impl FromStr for TokenStream { type Err = LexError; fn from_str(src: &str) -> Result { - Ok(TokenStream(Some(bridge::client::TokenStream::from_str(src)))) + Ok(TokenStream(Some(backend::bridge::client::TokenStream::from_str(src)))) } } @@ -224,12 +224,16 @@ pub use quote::{quote, quote_span}; fn tree_to_bridge_tree( tree: TokenTree, -) -> bridge::TokenTree { +) -> backend::bridge::TokenTree< + backend::bridge::client::TokenStream, + backend::bridge::client::Span, + backend::bridge::client::Symbol, +> { match tree { - TokenTree::Group(tt) => bridge::TokenTree::Group(tt.0), - TokenTree::Punct(tt) => bridge::TokenTree::Punct(tt.0), - TokenTree::Ident(tt) => bridge::TokenTree::Ident(tt.0), - TokenTree::Literal(tt) => bridge::TokenTree::Literal(tt.0), + TokenTree::Group(tt) => backend::bridge::TokenTree::Group(tt.0), + TokenTree::Punct(tt) => backend::bridge::TokenTree::Punct(tt.0), + TokenTree::Ident(tt) => backend::bridge::TokenTree::Ident(tt.0), + TokenTree::Literal(tt) => backend::bridge::TokenTree::Literal(tt.0), } } @@ -237,7 +241,9 @@ fn tree_to_bridge_tree( #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl From for TokenStream { fn from(tree: TokenTree) -> TokenStream { - TokenStream(Some(bridge::client::TokenStream::from_token_tree(tree_to_bridge_tree(tree)))) + TokenStream(Some(backend::bridge::client::TokenStream::from_token_tree( + tree_to_bridge_tree(tree), + ))) } } @@ -245,10 +251,10 @@ impl From for TokenStream { /// `Extend` with less monomorphization in calling crates. struct ConcatTreesHelper { trees: Vec< - bridge::TokenTree< - bridge::client::TokenStream, - bridge::client::Span, - bridge::client::Symbol, + backend::bridge::TokenTree< + backend::bridge::client::TokenStream, + backend::bridge::client::Span, + backend::bridge::client::Symbol, >, >, } @@ -266,7 +272,7 @@ impl ConcatTreesHelper { if self.trees.is_empty() { TokenStream(None) } else { - TokenStream(Some(bridge::client::TokenStream::concat_trees(None, self.trees))) + TokenStream(Some(backend::bridge::client::TokenStream::concat_trees(None, self.trees))) } } @@ -274,14 +280,15 @@ impl ConcatTreesHelper { if self.trees.is_empty() { return; } - stream.0 = Some(bridge::client::TokenStream::concat_trees(stream.0.take(), self.trees)) + stream.0 = + Some(backend::bridge::client::TokenStream::concat_trees(stream.0.take(), self.trees)) } } /// Non-generic helper for implementing `FromIterator` and /// `Extend` with less monomorphization in calling crates. struct ConcatStreamsHelper { - streams: Vec, + streams: Vec, } impl ConcatStreamsHelper { @@ -299,7 +306,10 @@ impl ConcatStreamsHelper { if self.streams.len() <= 1 { TokenStream(self.streams.pop()) } else { - TokenStream(Some(bridge::client::TokenStream::concat_streams(None, self.streams))) + TokenStream(Some(backend::bridge::client::TokenStream::concat_streams( + None, + self.streams, + ))) } } @@ -311,7 +321,8 @@ impl ConcatStreamsHelper { if base.is_none() && self.streams.len() == 1 { stream.0 = self.streams.pop(); } else { - stream.0 = Some(bridge::client::TokenStream::concat_streams(base, self.streams)); + stream.0 = + Some(backend::bridge::client::TokenStream::concat_streams(base, self.streams)); } } } @@ -362,7 +373,8 @@ impl Extend for TokenStream { /// Public implementation details for the `TokenStream` type, such as iterators. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] pub mod token_stream { - use crate::{Group, Ident, Literal, Punct, TokenStream, TokenTree, bridge}; + use crate::backend::bridge; + use crate::{Group, Ident, Literal, Punct, TokenStream, TokenTree}; /// An iterator over `TokenStream`'s `TokenTree`s. /// The iteration is "shallow", e.g., the iterator doesn't recurse into delimited groups, @@ -432,7 +444,7 @@ mod quote; /// A region of source code, along with macro expansion information. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] #[derive(Copy, Clone)] -pub struct Span(bridge::client::Span); +pub struct Span(backend::bridge::client::Span); #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl !Send for Span {} @@ -454,7 +466,7 @@ impl Span { /// A span that resolves at the macro definition site. #[unstable(feature = "proc_macro_def_site", issue = "54724")] pub fn def_site() -> Span { - Span(bridge::client::Span::def_site()) + Span(backend::bridge::client::Span::def_site()) } /// The span of the invocation of the current procedural macro. @@ -463,7 +475,7 @@ impl Span { /// at the macro call site will be able to refer to them as well. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] pub fn call_site() -> Span { - Span(bridge::client::Span::call_site()) + Span(backend::bridge::client::Span::call_site()) } /// A span that represents `macro_rules` hygiene, and sometimes resolves at the macro @@ -472,7 +484,7 @@ impl Span { /// The span location is taken from the call-site. #[stable(feature = "proc_macro_mixed_site", since = "1.45.0")] pub fn mixed_site() -> Span { - Span(bridge::client::Span::mixed_site()) + Span(backend::bridge::client::Span::mixed_site()) } /// The original source file into which this span points. @@ -581,7 +593,7 @@ impl Span { #[doc(hidden)] #[unstable(feature = "proc_macro_internals", issue = "27812")] pub fn recover_proc_macro_span(id: usize) -> Span { - Span(bridge::client::Span::recover_proc_macro_span(id)) + Span(backend::bridge::client::Span::recover_proc_macro_span(id)) } diagnostic_method!(error, Level::Error); @@ -601,7 +613,7 @@ impl fmt::Debug for Span { /// The source file of a given `Span`. #[unstable(feature = "proc_macro_span", issue = "54725")] #[derive(Clone)] -pub struct SourceFile(bridge::client::SourceFile); +pub struct SourceFile(backend::bridge::client::SourceFile); impl SourceFile { /// Gets the path to this source file. @@ -774,7 +786,9 @@ impl fmt::Display for TokenTree { /// A `Group` internally contains a `TokenStream` which is surrounded by `Delimiter`s. #[derive(Clone)] #[stable(feature = "proc_macro_lib2", since = "1.29.0")] -pub struct Group(bridge::Group); +pub struct Group( + backend::bridge::Group, +); #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl !Send for Group {} @@ -823,10 +837,10 @@ impl Group { /// method below. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] pub fn new(delimiter: Delimiter, stream: TokenStream) -> Group { - Group(bridge::Group { + Group(backend::bridge::Group { delimiter, stream: stream.0, - span: bridge::DelimSpan::from_single(Span::call_site().0), + span: backend::bridge::DelimSpan::from_single(Span::call_site().0), }) } @@ -887,7 +901,7 @@ impl Group { /// tokens at the level of the `Group`. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] pub fn set_span(&mut self, span: Span) { - self.0.span = bridge::DelimSpan::from_single(span.0); + self.0.span = backend::bridge::DelimSpan::from_single(span.0); } } @@ -919,7 +933,7 @@ impl fmt::Debug for Group { /// forms of `Spacing` returned. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] #[derive(Clone)] -pub struct Punct(bridge::Punct); +pub struct Punct(backend::bridge::Punct); #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl !Send for Punct {} @@ -970,7 +984,7 @@ impl Punct { if !LEGAL_CHARS.contains(&ch) { panic!("unsupported character `{:?}`", ch); } - Punct(bridge::Punct { + Punct(backend::bridge::Punct { ch: ch as u8, joint: spacing == Spacing::Joint, span: Span::call_site().0, @@ -1041,7 +1055,9 @@ impl PartialEq for char { /// An identifier (`ident`). #[derive(Clone)] #[stable(feature = "proc_macro_lib2", since = "1.29.0")] -pub struct Ident(bridge::Ident); +pub struct Ident( + backend::bridge::Ident, +); impl Ident { /// Creates a new `Ident` with the given `string` as well as the specified @@ -1065,8 +1081,8 @@ impl Ident { /// tokens, requires a `Span` to be specified at construction. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] pub fn new(string: &str, span: Span) -> Ident { - Ident(bridge::Ident { - sym: bridge::client::Symbol::new_ident(string, false), + Ident(backend::bridge::Ident { + sym: backend::bridge::client::Symbol::new_ident(string, false), is_raw: false, span: span.0, }) @@ -1078,8 +1094,8 @@ impl Ident { /// (e.g. `self`, `super`) are not supported, and will cause a panic. #[stable(feature = "proc_macro_raw_ident", since = "1.47.0")] pub fn new_raw(string: &str, span: Span) -> Ident { - Ident(bridge::Ident { - sym: bridge::client::Symbol::new_ident(string, true), + Ident(backend::bridge::Ident { + sym: backend::bridge::client::Symbol::new_ident(string, true), is_raw: true, span: span.0, }) @@ -1127,7 +1143,9 @@ impl fmt::Debug for Ident { /// Boolean literals like `true` and `false` do not belong here, they are `Ident`s. #[derive(Clone)] #[stable(feature = "proc_macro_lib2", since = "1.29.0")] -pub struct Literal(bridge::Literal); +pub struct Literal( + backend::bridge::Literal, +); macro_rules! suffixed_int_literals { ($($name:ident => $kind:ident,)*) => ($( @@ -1144,10 +1162,10 @@ macro_rules! suffixed_int_literals { /// below. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] pub fn $name(n: $kind) -> Literal { - Literal(bridge::Literal { - kind: bridge::LitKind::Integer, - symbol: bridge::client::Symbol::new(&n.to_string()), - suffix: Some(bridge::client::Symbol::new(stringify!($kind))), + Literal(backend::bridge::Literal { + kind: backend::bridge::LitKind::Integer, + symbol: backend::bridge::client::Symbol::new(&n.to_string()), + suffix: Some(backend::bridge::client::Symbol::new(stringify!($kind))), span: Span::call_site().0, }) } @@ -1171,9 +1189,9 @@ macro_rules! unsuffixed_int_literals { /// below. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] pub fn $name(n: $kind) -> Literal { - Literal(bridge::Literal { - kind: bridge::LitKind::Integer, - symbol: bridge::client::Symbol::new(&n.to_string()), + Literal(backend::bridge::Literal { + kind: backend::bridge::LitKind::Integer, + symbol: backend::bridge::client::Symbol::new(&n.to_string()), suffix: None, span: Span::call_site().0, }) @@ -1182,11 +1200,11 @@ macro_rules! unsuffixed_int_literals { } impl Literal { - fn new(kind: bridge::LitKind, value: &str, suffix: Option<&str>) -> Self { - Literal(bridge::Literal { + fn new(kind: backend::bridge::LitKind, value: &str, suffix: Option<&str>) -> Self { + Literal(backend::bridge::Literal { kind, - symbol: bridge::client::Symbol::new(value), - suffix: suffix.map(bridge::client::Symbol::new), + symbol: backend::bridge::client::Symbol::new(value), + suffix: suffix.map(backend::bridge::client::Symbol::new), span: Span::call_site().0, }) } @@ -1242,7 +1260,7 @@ impl Literal { if !repr.contains('.') { repr.push_str(".0"); } - Literal::new(bridge::LitKind::Float, &repr, None) + Literal::new(backend::bridge::LitKind::Float, &repr, None) } /// Creates a new suffixed floating-point literal. @@ -1263,7 +1281,7 @@ impl Literal { if !n.is_finite() { panic!("Invalid float literal {n}"); } - Literal::new(bridge::LitKind::Float, &n.to_string(), Some("f32")) + Literal::new(backend::bridge::LitKind::Float, &n.to_string(), Some("f32")) } /// Creates a new unsuffixed floating-point literal. @@ -1287,7 +1305,7 @@ impl Literal { if !repr.contains('.') { repr.push_str(".0"); } - Literal::new(bridge::LitKind::Float, &repr, None) + Literal::new(backend::bridge::LitKind::Float, &repr, None) } /// Creates a new suffixed floating-point literal. @@ -1308,7 +1326,7 @@ impl Literal { if !n.is_finite() { panic!("Invalid float literal {n}"); } - Literal::new(bridge::LitKind::Float, &n.to_string(), Some("f64")) + Literal::new(backend::bridge::LitKind::Float, &n.to_string(), Some("f64")) } /// String literal. @@ -1320,7 +1338,7 @@ impl Literal { escape_nonascii: false, }; let repr = escape_bytes(string.as_bytes(), escape); - Literal::new(bridge::LitKind::Str, &repr, None) + Literal::new(backend::bridge::LitKind::Str, &repr, None) } /// Character literal. @@ -1332,7 +1350,7 @@ impl Literal { escape_nonascii: false, }; let repr = escape_bytes(ch.encode_utf8(&mut [0u8; 4]).as_bytes(), escape); - Literal::new(bridge::LitKind::Char, &repr, None) + Literal::new(backend::bridge::LitKind::Char, &repr, None) } /// Byte character literal. @@ -1344,7 +1362,7 @@ impl Literal { escape_nonascii: true, }; let repr = escape_bytes(&[byte], escape); - Literal::new(bridge::LitKind::Byte, &repr, None) + Literal::new(backend::bridge::LitKind::Byte, &repr, None) } /// Byte string literal. @@ -1356,7 +1374,7 @@ impl Literal { escape_nonascii: true, }; let repr = escape_bytes(bytes, escape); - Literal::new(bridge::LitKind::ByteStr, &repr, None) + Literal::new(backend::bridge::LitKind::ByteStr, &repr, None) } /// C string literal. @@ -1368,7 +1386,7 @@ impl Literal { escape_nonascii: false, }; let repr = escape_bytes(string.to_bytes(), escape); - Literal::new(bridge::LitKind::CStr, &repr, None) + Literal::new(backend::bridge::LitKind::CStr, &repr, None) } /// Returns the span encompassing this literal. @@ -1426,27 +1444,27 @@ impl Literal { } self.with_symbol_and_suffix(|symbol, suffix| match self.0.kind { - bridge::LitKind::Byte => f(&["b'", symbol, "'", suffix]), - bridge::LitKind::Char => f(&["'", symbol, "'", suffix]), - bridge::LitKind::Str => f(&["\"", symbol, "\"", suffix]), - bridge::LitKind::StrRaw(n) => { + backend::bridge::LitKind::Byte => f(&["b'", symbol, "'", suffix]), + backend::bridge::LitKind::Char => f(&["'", symbol, "'", suffix]), + backend::bridge::LitKind::Str => f(&["\"", symbol, "\"", suffix]), + backend::bridge::LitKind::StrRaw(n) => { let hashes = get_hashes_str(n); f(&["r", hashes, "\"", symbol, "\"", hashes, suffix]) } - bridge::LitKind::ByteStr => f(&["b\"", symbol, "\"", suffix]), - bridge::LitKind::ByteStrRaw(n) => { + backend::bridge::LitKind::ByteStr => f(&["b\"", symbol, "\"", suffix]), + backend::bridge::LitKind::ByteStrRaw(n) => { let hashes = get_hashes_str(n); f(&["br", hashes, "\"", symbol, "\"", hashes, suffix]) } - bridge::LitKind::CStr => f(&["c\"", symbol, "\"", suffix]), - bridge::LitKind::CStrRaw(n) => { + backend::bridge::LitKind::CStr => f(&["c\"", symbol, "\"", suffix]), + backend::bridge::LitKind::CStrRaw(n) => { let hashes = get_hashes_str(n); f(&["cr", hashes, "\"", symbol, "\"", hashes, suffix]) } - bridge::LitKind::Integer | bridge::LitKind::Float | bridge::LitKind::ErrWithGuar => { - f(&[symbol, suffix]) - } + backend::bridge::LitKind::Integer + | backend::bridge::LitKind::Float + | backend::bridge::LitKind::ErrWithGuar => f(&[symbol, suffix]), }) } } @@ -1466,7 +1484,7 @@ impl FromStr for Literal { type Err = LexError; fn from_str(src: &str) -> Result { - match bridge::client::FreeFunctions::literal_from_str(src) { + match backend::bridge::client::FreeFunctions::literal_from_str(src) { Ok(literal) => Ok(Literal(literal)), Err(()) => Err(LexError), } @@ -1515,9 +1533,9 @@ pub mod tracked_env { #[unstable(feature = "proc_macro_tracked_env", issue = "99515")] pub fn var + AsRef>(key: K) -> Result { let key: &str = key.as_ref(); - let value = crate::bridge::client::FreeFunctions::injected_env_var(key) + let value = crate::backend::bridge::client::FreeFunctions::injected_env_var(key) .map_or_else(|| env::var(key), Ok); - crate::bridge::client::FreeFunctions::track_env_var(key, value.as_deref().ok()); + crate::backend::bridge::client::FreeFunctions::track_env_var(key, value.as_deref().ok()); value } } @@ -1532,6 +1550,6 @@ pub mod tracked_path { #[unstable(feature = "track_path", issue = "99515")] pub fn path>(path: P) { let path: &str = path.as_ref(); - crate::bridge::client::FreeFunctions::track_path(path); + crate::backend::bridge::client::FreeFunctions::track_path(path); } } From 17db22091c4ab66e6249b5a969149933294016d1 Mon Sep 17 00:00:00 2001 From: Arthur Beck Date: Mon, 16 Dec 2024 20:00:31 -0600 Subject: [PATCH 2/3] Attempted fix for regression caused by previous commit --- library/proc_macro/src/backend/mod.rs | 7 +- library/proc_macro/src/diagnostic.rs | 6 +- library/proc_macro/src/lib.rs | 188 ++++++++++++-------------- 3 files changed, 94 insertions(+), 107 deletions(-) diff --git a/library/proc_macro/src/backend/mod.rs b/library/proc_macro/src/backend/mod.rs index 730e9953de44d..6c5ad0cf90c88 100644 --- a/library/proc_macro/src/backend/mod.rs +++ b/library/proc_macro/src/backend/mod.rs @@ -1,7 +1,6 @@ +pub(crate) mod arena; pub mod bridge; +pub(crate) mod fxhash; #[allow(unsafe_code)] -pub(self) mod arena; - -#[forbid(unsafe_code)] -pub(self) mod fxhash; +pub use bridge::*; diff --git a/library/proc_macro/src/diagnostic.rs b/library/proc_macro/src/diagnostic.rs index 30d806338fe73..3ae58d08019a8 100644 --- a/library/proc_macro/src/diagnostic.rs +++ b/library/proc_macro/src/diagnostic.rs @@ -163,8 +163,8 @@ impl Diagnostic { pub fn emit(self) { fn to_internal( diag: Diagnostic, - ) -> crate::backend::bridge::Diagnostic { - crate::backend::bridge::Diagnostic { + ) -> crate::backend::Diagnostic { + crate::backend::Diagnostic { level: diag.level, message: diag.message, spans: diag.spans.into_iter().map(|s| s.0).collect(), @@ -172,6 +172,6 @@ impl Diagnostic { } } - crate::backend::bridge::client::FreeFunctions::emit_diagnostic(to_internal(self)); + crate::backend::client::FreeFunctions::emit_diagnostic(to_internal(self)); } } diff --git a/library/proc_macro/src/lib.rs b/library/proc_macro/src/lib.rs index 6dc06e52e137e..bf6e00ab44b91 100644 --- a/library/proc_macro/src/lib.rs +++ b/library/proc_macro/src/lib.rs @@ -35,7 +35,12 @@ #[unstable(feature = "proc_macro_internals", issue = "27812")] #[doc(hidden)] -pub mod backend; +pub mod bridge { + pub use super::backend::bridge::*; +} +#[unstable(feature = "proc_macro_internals", issue = "27812")] +#[doc(hidden)] +mod backend; mod diagnostic; mod escape; @@ -69,7 +74,7 @@ use crate::escape::{EscapeOptions, escape_bytes}; /// inside of a procedural macro, false if invoked from any other binary. #[stable(feature = "proc_macro_is_available", since = "1.57.0")] pub fn is_available() -> bool { - backend::bridge::client::is_available() + backend::client::is_available() } /// The main type provided by this crate, representing an abstract stream of @@ -82,7 +87,7 @@ pub fn is_available() -> bool { #[rustc_diagnostic_item = "TokenStream"] #[stable(feature = "proc_macro_lib", since = "1.15.0")] #[derive(Clone)] -pub struct TokenStream(Option); +pub struct TokenStream(Option); #[stable(feature = "proc_macro_lib", since = "1.15.0")] impl !Send for TokenStream {} @@ -158,7 +163,7 @@ impl TokenStream { #[unstable(feature = "proc_macro_expand", issue = "90765")] pub fn expand_expr(&self) -> Result { let stream = self.0.as_ref().ok_or(ExpandError)?; - match backend::bridge::client::TokenStream::expand_expr(stream) { + match backend::client::TokenStream::expand_expr(stream) { Ok(stream) => Ok(TokenStream(Some(stream))), Err(_) => Err(ExpandError), } @@ -177,7 +182,7 @@ impl FromStr for TokenStream { type Err = LexError; fn from_str(src: &str) -> Result { - Ok(TokenStream(Some(backend::bridge::client::TokenStream::from_str(src)))) + Ok(TokenStream(Some(backend::client::TokenStream::from_str(src)))) } } @@ -224,16 +229,13 @@ pub use quote::{quote, quote_span}; fn tree_to_bridge_tree( tree: TokenTree, -) -> backend::bridge::TokenTree< - backend::bridge::client::TokenStream, - backend::bridge::client::Span, - backend::bridge::client::Symbol, -> { +) -> backend::TokenTree +{ match tree { - TokenTree::Group(tt) => backend::bridge::TokenTree::Group(tt.0), - TokenTree::Punct(tt) => backend::bridge::TokenTree::Punct(tt.0), - TokenTree::Ident(tt) => backend::bridge::TokenTree::Ident(tt.0), - TokenTree::Literal(tt) => backend::bridge::TokenTree::Literal(tt.0), + TokenTree::Group(tt) => backend::TokenTree::Group(tt.0), + TokenTree::Punct(tt) => backend::TokenTree::Punct(tt.0), + TokenTree::Ident(tt) => backend::TokenTree::Ident(tt.0), + TokenTree::Literal(tt) => backend::TokenTree::Literal(tt.0), } } @@ -241,9 +243,7 @@ fn tree_to_bridge_tree( #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl From for TokenStream { fn from(tree: TokenTree) -> TokenStream { - TokenStream(Some(backend::bridge::client::TokenStream::from_token_tree( - tree_to_bridge_tree(tree), - ))) + TokenStream(Some(backend::client::TokenStream::from_token_tree(tree_to_bridge_tree(tree)))) } } @@ -251,10 +251,10 @@ impl From for TokenStream { /// `Extend` with less monomorphization in calling crates. struct ConcatTreesHelper { trees: Vec< - backend::bridge::TokenTree< - backend::bridge::client::TokenStream, - backend::bridge::client::Span, - backend::bridge::client::Symbol, + backend::TokenTree< + backend::client::TokenStream, + backend::client::Span, + backend::client::Symbol, >, >, } @@ -272,7 +272,7 @@ impl ConcatTreesHelper { if self.trees.is_empty() { TokenStream(None) } else { - TokenStream(Some(backend::bridge::client::TokenStream::concat_trees(None, self.trees))) + TokenStream(Some(backend::client::TokenStream::concat_trees(None, self.trees))) } } @@ -280,15 +280,14 @@ impl ConcatTreesHelper { if self.trees.is_empty() { return; } - stream.0 = - Some(backend::bridge::client::TokenStream::concat_trees(stream.0.take(), self.trees)) + stream.0 = Some(backend::client::TokenStream::concat_trees(stream.0.take(), self.trees)) } } /// Non-generic helper for implementing `FromIterator` and /// `Extend` with less monomorphization in calling crates. struct ConcatStreamsHelper { - streams: Vec, + streams: Vec, } impl ConcatStreamsHelper { @@ -306,10 +305,7 @@ impl ConcatStreamsHelper { if self.streams.len() <= 1 { TokenStream(self.streams.pop()) } else { - TokenStream(Some(backend::bridge::client::TokenStream::concat_streams( - None, - self.streams, - ))) + TokenStream(Some(backend::client::TokenStream::concat_streams(None, self.streams))) } } @@ -321,8 +317,7 @@ impl ConcatStreamsHelper { if base.is_none() && self.streams.len() == 1 { stream.0 = self.streams.pop(); } else { - stream.0 = - Some(backend::bridge::client::TokenStream::concat_streams(base, self.streams)); + stream.0 = Some(backend::client::TokenStream::concat_streams(base, self.streams)); } } } @@ -373,8 +368,7 @@ impl Extend for TokenStream { /// Public implementation details for the `TokenStream` type, such as iterators. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] pub mod token_stream { - use crate::backend::bridge; - use crate::{Group, Ident, Literal, Punct, TokenStream, TokenTree}; + use crate::{Group, Ident, Literal, Punct, TokenStream, TokenTree, backend}; /// An iterator over `TokenStream`'s `TokenTree`s. /// The iteration is "shallow", e.g., the iterator doesn't recurse into delimited groups, @@ -383,10 +377,10 @@ pub mod token_stream { #[stable(feature = "proc_macro_lib2", since = "1.29.0")] pub struct IntoIter( std::vec::IntoIter< - bridge::TokenTree< - bridge::client::TokenStream, - bridge::client::Span, - bridge::client::Symbol, + backend::TokenTree< + backend::client::TokenStream, + backend::client::Span, + backend::client::Symbol, >, >, ); @@ -397,10 +391,10 @@ pub mod token_stream { fn next(&mut self) -> Option { self.0.next().map(|tree| match tree { - bridge::TokenTree::Group(tt) => TokenTree::Group(Group(tt)), - bridge::TokenTree::Punct(tt) => TokenTree::Punct(Punct(tt)), - bridge::TokenTree::Ident(tt) => TokenTree::Ident(Ident(tt)), - bridge::TokenTree::Literal(tt) => TokenTree::Literal(Literal(tt)), + backend::TokenTree::Group(tt) => TokenTree::Group(Group(tt)), + backend::TokenTree::Punct(tt) => TokenTree::Punct(Punct(tt)), + backend::TokenTree::Ident(tt) => TokenTree::Ident(Ident(tt)), + backend::TokenTree::Literal(tt) => TokenTree::Literal(Literal(tt)), }) } @@ -444,7 +438,7 @@ mod quote; /// A region of source code, along with macro expansion information. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] #[derive(Copy, Clone)] -pub struct Span(backend::bridge::client::Span); +pub struct Span(backend::client::Span); #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl !Send for Span {} @@ -466,7 +460,7 @@ impl Span { /// A span that resolves at the macro definition site. #[unstable(feature = "proc_macro_def_site", issue = "54724")] pub fn def_site() -> Span { - Span(backend::bridge::client::Span::def_site()) + Span(backend::client::Span::def_site()) } /// The span of the invocation of the current procedural macro. @@ -475,7 +469,7 @@ impl Span { /// at the macro call site will be able to refer to them as well. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] pub fn call_site() -> Span { - Span(backend::bridge::client::Span::call_site()) + Span(backend::client::Span::call_site()) } /// A span that represents `macro_rules` hygiene, and sometimes resolves at the macro @@ -484,7 +478,7 @@ impl Span { /// The span location is taken from the call-site. #[stable(feature = "proc_macro_mixed_site", since = "1.45.0")] pub fn mixed_site() -> Span { - Span(backend::bridge::client::Span::mixed_site()) + Span(backend::client::Span::mixed_site()) } /// The original source file into which this span points. @@ -593,7 +587,7 @@ impl Span { #[doc(hidden)] #[unstable(feature = "proc_macro_internals", issue = "27812")] pub fn recover_proc_macro_span(id: usize) -> Span { - Span(backend::bridge::client::Span::recover_proc_macro_span(id)) + Span(backend::client::Span::recover_proc_macro_span(id)) } diagnostic_method!(error, Level::Error); @@ -613,7 +607,7 @@ impl fmt::Debug for Span { /// The source file of a given `Span`. #[unstable(feature = "proc_macro_span", issue = "54725")] #[derive(Clone)] -pub struct SourceFile(backend::bridge::client::SourceFile); +pub struct SourceFile(backend::client::SourceFile); impl SourceFile { /// Gets the path to this source file. @@ -786,9 +780,7 @@ impl fmt::Display for TokenTree { /// A `Group` internally contains a `TokenStream` which is surrounded by `Delimiter`s. #[derive(Clone)] #[stable(feature = "proc_macro_lib2", since = "1.29.0")] -pub struct Group( - backend::bridge::Group, -); +pub struct Group(backend::Group); #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl !Send for Group {} @@ -837,10 +829,10 @@ impl Group { /// method below. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] pub fn new(delimiter: Delimiter, stream: TokenStream) -> Group { - Group(backend::bridge::Group { + Group(backend::Group { delimiter, stream: stream.0, - span: backend::bridge::DelimSpan::from_single(Span::call_site().0), + span: backend::DelimSpan::from_single(Span::call_site().0), }) } @@ -901,7 +893,7 @@ impl Group { /// tokens at the level of the `Group`. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] pub fn set_span(&mut self, span: Span) { - self.0.span = backend::bridge::DelimSpan::from_single(span.0); + self.0.span = backend::DelimSpan::from_single(span.0); } } @@ -933,7 +925,7 @@ impl fmt::Debug for Group { /// forms of `Spacing` returned. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] #[derive(Clone)] -pub struct Punct(backend::bridge::Punct); +pub struct Punct(backend::Punct); #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl !Send for Punct {} @@ -984,7 +976,7 @@ impl Punct { if !LEGAL_CHARS.contains(&ch) { panic!("unsupported character `{:?}`", ch); } - Punct(backend::bridge::Punct { + Punct(backend::Punct { ch: ch as u8, joint: spacing == Spacing::Joint, span: Span::call_site().0, @@ -1055,9 +1047,7 @@ impl PartialEq for char { /// An identifier (`ident`). #[derive(Clone)] #[stable(feature = "proc_macro_lib2", since = "1.29.0")] -pub struct Ident( - backend::bridge::Ident, -); +pub struct Ident(backend::Ident); impl Ident { /// Creates a new `Ident` with the given `string` as well as the specified @@ -1081,8 +1071,8 @@ impl Ident { /// tokens, requires a `Span` to be specified at construction. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] pub fn new(string: &str, span: Span) -> Ident { - Ident(backend::bridge::Ident { - sym: backend::bridge::client::Symbol::new_ident(string, false), + Ident(backend::Ident { + sym: backend::client::Symbol::new_ident(string, false), is_raw: false, span: span.0, }) @@ -1094,8 +1084,8 @@ impl Ident { /// (e.g. `self`, `super`) are not supported, and will cause a panic. #[stable(feature = "proc_macro_raw_ident", since = "1.47.0")] pub fn new_raw(string: &str, span: Span) -> Ident { - Ident(backend::bridge::Ident { - sym: backend::bridge::client::Symbol::new_ident(string, true), + Ident(backend::Ident { + sym: backend::client::Symbol::new_ident(string, true), is_raw: true, span: span.0, }) @@ -1143,9 +1133,7 @@ impl fmt::Debug for Ident { /// Boolean literals like `true` and `false` do not belong here, they are `Ident`s. #[derive(Clone)] #[stable(feature = "proc_macro_lib2", since = "1.29.0")] -pub struct Literal( - backend::bridge::Literal, -); +pub struct Literal(backend::Literal); macro_rules! suffixed_int_literals { ($($name:ident => $kind:ident,)*) => ($( @@ -1162,10 +1150,10 @@ macro_rules! suffixed_int_literals { /// below. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] pub fn $name(n: $kind) -> Literal { - Literal(backend::bridge::Literal { - kind: backend::bridge::LitKind::Integer, - symbol: backend::bridge::client::Symbol::new(&n.to_string()), - suffix: Some(backend::bridge::client::Symbol::new(stringify!($kind))), + Literal(backend::Literal { + kind: backend::LitKind::Integer, + symbol: backend::client::Symbol::new(&n.to_string()), + suffix: Some(backend::client::Symbol::new(stringify!($kind))), span: Span::call_site().0, }) } @@ -1189,9 +1177,9 @@ macro_rules! unsuffixed_int_literals { /// below. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] pub fn $name(n: $kind) -> Literal { - Literal(backend::bridge::Literal { - kind: backend::bridge::LitKind::Integer, - symbol: backend::bridge::client::Symbol::new(&n.to_string()), + Literal(backend::Literal { + kind: backend::LitKind::Integer, + symbol: backend::client::Symbol::new(&n.to_string()), suffix: None, span: Span::call_site().0, }) @@ -1200,11 +1188,11 @@ macro_rules! unsuffixed_int_literals { } impl Literal { - fn new(kind: backend::bridge::LitKind, value: &str, suffix: Option<&str>) -> Self { - Literal(backend::bridge::Literal { + fn new(kind: backend::LitKind, value: &str, suffix: Option<&str>) -> Self { + Literal(backend::Literal { kind, - symbol: backend::bridge::client::Symbol::new(value), - suffix: suffix.map(backend::bridge::client::Symbol::new), + symbol: backend::client::Symbol::new(value), + suffix: suffix.map(backend::client::Symbol::new), span: Span::call_site().0, }) } @@ -1260,7 +1248,7 @@ impl Literal { if !repr.contains('.') { repr.push_str(".0"); } - Literal::new(backend::bridge::LitKind::Float, &repr, None) + Literal::new(backend::LitKind::Float, &repr, None) } /// Creates a new suffixed floating-point literal. @@ -1281,7 +1269,7 @@ impl Literal { if !n.is_finite() { panic!("Invalid float literal {n}"); } - Literal::new(backend::bridge::LitKind::Float, &n.to_string(), Some("f32")) + Literal::new(backend::LitKind::Float, &n.to_string(), Some("f32")) } /// Creates a new unsuffixed floating-point literal. @@ -1305,7 +1293,7 @@ impl Literal { if !repr.contains('.') { repr.push_str(".0"); } - Literal::new(backend::bridge::LitKind::Float, &repr, None) + Literal::new(backend::LitKind::Float, &repr, None) } /// Creates a new suffixed floating-point literal. @@ -1326,7 +1314,7 @@ impl Literal { if !n.is_finite() { panic!("Invalid float literal {n}"); } - Literal::new(backend::bridge::LitKind::Float, &n.to_string(), Some("f64")) + Literal::new(backend::LitKind::Float, &n.to_string(), Some("f64")) } /// String literal. @@ -1338,7 +1326,7 @@ impl Literal { escape_nonascii: false, }; let repr = escape_bytes(string.as_bytes(), escape); - Literal::new(backend::bridge::LitKind::Str, &repr, None) + Literal::new(backend::LitKind::Str, &repr, None) } /// Character literal. @@ -1350,7 +1338,7 @@ impl Literal { escape_nonascii: false, }; let repr = escape_bytes(ch.encode_utf8(&mut [0u8; 4]).as_bytes(), escape); - Literal::new(backend::bridge::LitKind::Char, &repr, None) + Literal::new(backend::LitKind::Char, &repr, None) } /// Byte character literal. @@ -1362,7 +1350,7 @@ impl Literal { escape_nonascii: true, }; let repr = escape_bytes(&[byte], escape); - Literal::new(backend::bridge::LitKind::Byte, &repr, None) + Literal::new(backend::LitKind::Byte, &repr, None) } /// Byte string literal. @@ -1374,7 +1362,7 @@ impl Literal { escape_nonascii: true, }; let repr = escape_bytes(bytes, escape); - Literal::new(backend::bridge::LitKind::ByteStr, &repr, None) + Literal::new(backend::LitKind::ByteStr, &repr, None) } /// C string literal. @@ -1386,7 +1374,7 @@ impl Literal { escape_nonascii: false, }; let repr = escape_bytes(string.to_bytes(), escape); - Literal::new(backend::bridge::LitKind::CStr, &repr, None) + Literal::new(backend::LitKind::CStr, &repr, None) } /// Returns the span encompassing this literal. @@ -1444,27 +1432,27 @@ impl Literal { } self.with_symbol_and_suffix(|symbol, suffix| match self.0.kind { - backend::bridge::LitKind::Byte => f(&["b'", symbol, "'", suffix]), - backend::bridge::LitKind::Char => f(&["'", symbol, "'", suffix]), - backend::bridge::LitKind::Str => f(&["\"", symbol, "\"", suffix]), - backend::bridge::LitKind::StrRaw(n) => { + backend::LitKind::Byte => f(&["b'", symbol, "'", suffix]), + backend::LitKind::Char => f(&["'", symbol, "'", suffix]), + backend::LitKind::Str => f(&["\"", symbol, "\"", suffix]), + backend::LitKind::StrRaw(n) => { let hashes = get_hashes_str(n); f(&["r", hashes, "\"", symbol, "\"", hashes, suffix]) } - backend::bridge::LitKind::ByteStr => f(&["b\"", symbol, "\"", suffix]), - backend::bridge::LitKind::ByteStrRaw(n) => { + backend::LitKind::ByteStr => f(&["b\"", symbol, "\"", suffix]), + backend::LitKind::ByteStrRaw(n) => { let hashes = get_hashes_str(n); f(&["br", hashes, "\"", symbol, "\"", hashes, suffix]) } - backend::bridge::LitKind::CStr => f(&["c\"", symbol, "\"", suffix]), - backend::bridge::LitKind::CStrRaw(n) => { + backend::LitKind::CStr => f(&["c\"", symbol, "\"", suffix]), + backend::LitKind::CStrRaw(n) => { let hashes = get_hashes_str(n); f(&["cr", hashes, "\"", symbol, "\"", hashes, suffix]) } - backend::bridge::LitKind::Integer - | backend::bridge::LitKind::Float - | backend::bridge::LitKind::ErrWithGuar => f(&[symbol, suffix]), + backend::LitKind::Integer | backend::LitKind::Float | backend::LitKind::ErrWithGuar => { + f(&[symbol, suffix]) + } }) } } @@ -1484,7 +1472,7 @@ impl FromStr for Literal { type Err = LexError; fn from_str(src: &str) -> Result { - match backend::bridge::client::FreeFunctions::literal_from_str(src) { + match backend::client::FreeFunctions::literal_from_str(src) { Ok(literal) => Ok(Literal(literal)), Err(()) => Err(LexError), } @@ -1533,9 +1521,9 @@ pub mod tracked_env { #[unstable(feature = "proc_macro_tracked_env", issue = "99515")] pub fn var + AsRef>(key: K) -> Result { let key: &str = key.as_ref(); - let value = crate::backend::bridge::client::FreeFunctions::injected_env_var(key) + let value = crate::backend::client::FreeFunctions::injected_env_var(key) .map_or_else(|| env::var(key), Ok); - crate::backend::bridge::client::FreeFunctions::track_env_var(key, value.as_deref().ok()); + crate::backend::client::FreeFunctions::track_env_var(key, value.as_deref().ok()); value } } @@ -1550,6 +1538,6 @@ pub mod tracked_path { #[unstable(feature = "track_path", issue = "99515")] pub fn path>(path: P) { let path: &str = path.as_ref(); - crate::backend::bridge::client::FreeFunctions::track_path(path); + crate::backend::client::FreeFunctions::track_path(path); } } From ddbe035a665e22a0a900afc5eace16913212d8b8 Mon Sep 17 00:00:00 2001 From: Arthur Beck Date: Mon, 16 Dec 2024 20:24:05 -0600 Subject: [PATCH 3/3] Removed problematic line --- library/proc_macro/src/backend/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/library/proc_macro/src/backend/mod.rs b/library/proc_macro/src/backend/mod.rs index 6c5ad0cf90c88..ea9f3477b9b56 100644 --- a/library/proc_macro/src/backend/mod.rs +++ b/library/proc_macro/src/backend/mod.rs @@ -2,5 +2,4 @@ pub(crate) mod arena; pub mod bridge; pub(crate) mod fxhash; -#[allow(unsafe_code)] pub use bridge::*;