diff --git a/library/proc_macro/src/bridge/client.rs b/library/proc_macro/src/backend/client.rs similarity index 96% rename from library/proc_macro/src/bridge/client.rs rename to library/proc_macro/src/backend/client.rs index 92558f2b7d9cc..981343f730906 100644 --- a/library/proc_macro/src/bridge/client.rs +++ b/library/proc_macro/src/backend/client.rs @@ -25,7 +25,7 @@ macro_rules! define_client_handles { $( pub(crate) struct $oty { - handle: handle::Handle, + handle: Handle, } impl !Send for $oty {} @@ -61,7 +61,7 @@ macro_rules! define_client_handles { impl DecodeMut<'_, '_, S> for $oty { fn decode(r: &mut Reader<'_>, s: &mut S) -> Self { $oty { - handle: handle::Handle::decode(r, s), + handle: Handle::decode(r, s), } } } @@ -70,7 +70,7 @@ macro_rules! define_client_handles { $( #[derive(Copy, Clone, PartialEq, Eq, Hash)] pub(crate) struct $ity { - handle: handle::Handle, + handle: Handle, } impl !Send for $ity {} @@ -85,7 +85,7 @@ macro_rules! define_client_handles { impl DecodeMut<'_, '_, S> for $ity { fn decode(r: &mut Reader<'_>, s: &mut S) -> Self { $ity { - handle: handle::Handle::decode(r, s), + handle: Handle::decode(r, s), } } } @@ -161,7 +161,7 @@ struct Bridge<'a> { cached_buffer: Buffer, /// Server-side function that the client uses to make requests. - dispatch: closure::Closure<'a, Buffer, Buffer>, + dispatch: Closure<'a, Buffer, Buffer>, /// Provided globals for this macro expansion. globals: ExpnGlobals, @@ -327,7 +327,7 @@ impl Client { pub const fn expand1(f: impl Fn(crate::TokenStream) -> crate::TokenStream + Copy) -> Self { Client { handle_counters: &COUNTERS, - run: super::selfless_reify::reify_to_extern_c_fn_hrt_bridge(move |bridge| { + run: reify_to_extern_c_fn_hrt_bridge(move |bridge| { run_client(bridge, |input| f(crate::TokenStream(Some(input))).0) }), _marker: PhantomData, @@ -341,7 +341,7 @@ impl Client<(crate::TokenStream, crate::TokenStream), crate::TokenStream> { ) -> Self { Client { handle_counters: &COUNTERS, - run: super::selfless_reify::reify_to_extern_c_fn_hrt_bridge(move |bridge| { + run: reify_to_extern_c_fn_hrt_bridge(move |bridge| { run_client(bridge, |(input, input2)| { f(crate::TokenStream(Some(input)), crate::TokenStream(Some(input2))).0 }) diff --git a/library/proc_macro/src/bridge/mod.rs b/library/proc_macro/src/backend/mod.rs similarity index 97% rename from library/proc_macro/src/bridge/mod.rs rename to library/proc_macro/src/backend/mod.rs index 1b09deb6bfe60..b043775631d30 100644 --- a/library/proc_macro/src/bridge/mod.rs +++ b/library/proc_macro/src/backend/mod.rs @@ -119,31 +119,24 @@ macro_rules! with_api_handle_types { }; } -#[allow(unsafe_code)] -mod arena; -#[allow(unsafe_code)] -mod buffer; #[deny(unsafe_code)] pub mod client; -#[allow(unsafe_code)] -mod closure; -#[forbid(unsafe_code)] -mod fxhash; -#[forbid(unsafe_code)] -mod handle; #[macro_use] #[forbid(unsafe_code)] mod rpc; -#[allow(unsafe_code)] -mod selfless_reify; #[forbid(unsafe_code)] pub mod server; +mod support; #[allow(unsafe_code)] mod symbol; - -use buffer::Buffer; pub use rpc::PanicMessage; use rpc::{Decode, DecodeMut, Encode, Reader, Writer}; +pub(crate) use support::arena::Arena; +pub(crate) use support::buffer::Buffer; +pub(crate) use support::closure::Closure; +pub(crate) use support::fxhash::FxHashMap; +pub(crate) use support::handle::{Handle, InternedStore, OwnedStore}; +pub(crate) use support::selfless_reify::reify_to_extern_c_fn_hrt_bridge; /// Configuration for establishing an active connection between a server and a /// client. The server creates the bridge config (`run_server` in `server.rs`), @@ -156,7 +149,7 @@ pub struct BridgeConfig<'a> { input: Buffer, /// Server-side function that the client uses to make requests. - dispatch: closure::Closure<'a, Buffer, Buffer>, + dispatch: Closure<'a, Buffer, Buffer>, /// If 'true', always invoke the default panic hook force_show_panics: bool, diff --git a/library/proc_macro/src/bridge/rpc.rs b/library/proc_macro/src/backend/rpc.rs similarity index 99% rename from library/proc_macro/src/bridge/rpc.rs rename to library/proc_macro/src/backend/rpc.rs index 85fd7d138585c..ed8e69b0d60b8 100644 --- a/library/proc_macro/src/bridge/rpc.rs +++ b/library/proc_macro/src/backend/rpc.rs @@ -5,7 +5,7 @@ use std::io::Write; use std::num::NonZero; use std::str; -pub(super) type Writer = super::buffer::Buffer; +pub(super) type Writer = super::Buffer; pub(super) trait Encode: Sized { fn encode(self, w: &mut Writer, s: &mut S); diff --git a/library/proc_macro/src/bridge/server.rs b/library/proc_macro/src/backend/server.rs similarity index 96% rename from library/proc_macro/src/bridge/server.rs rename to library/proc_macro/src/backend/server.rs index 0bb30698aa1d7..fbdfb41c22e29 100644 --- a/library/proc_macro/src/bridge/server.rs +++ b/library/proc_macro/src/backend/server.rs @@ -12,15 +12,15 @@ macro_rules! define_server_handles { ) => { #[allow(non_snake_case)] pub(super) struct HandleStore { - $($oty: handle::OwnedStore,)* - $($ity: handle::InternedStore,)* + $($oty: OwnedStore,)* + $($ity: InternedStore,)* } impl HandleStore { fn new(handle_counters: &'static client::HandleCounters) -> Self { HandleStore { - $($oty: handle::OwnedStore::new(&handle_counters.$oty),)* - $($ity: handle::InternedStore::new(&handle_counters.$ity),)* + $($oty: OwnedStore::new(&handle_counters.$oty),)* + $($ity: InternedStore::new(&handle_counters.$ity),)* } } } @@ -36,7 +36,7 @@ macro_rules! define_server_handles { for Marked { fn decode(r: &mut Reader<'_>, s: &mut HandleStore>) -> Self { - s.$oty.take(handle::Handle::decode(r, &mut ())) + s.$oty.take(Handle::decode(r, &mut ())) } } @@ -44,7 +44,7 @@ macro_rules! define_server_handles { for &'s Marked { fn decode(r: &mut Reader<'_>, s: &'s HandleStore>) -> Self { - &s.$oty[handle::Handle::decode(r, &mut ())] + &s.$oty[Handle::decode(r, &mut ())] } } @@ -55,7 +55,7 @@ macro_rules! define_server_handles { r: &mut Reader<'_>, s: &'s mut HandleStore> ) -> Self { - &mut s.$oty[handle::Handle::decode(r, &mut ())] + &mut s.$oty[Handle::decode(r, &mut ())] } } )* @@ -71,7 +71,7 @@ macro_rules! define_server_handles { for Marked { fn decode(r: &mut Reader<'_>, s: &mut HandleStore>) -> Self { - s.$ity.copy(handle::Handle::decode(r, &mut ())) + s.$ity.copy(Handle::decode(r, &mut ())) } } )* diff --git a/library/proc_macro/src/bridge/arena.rs b/library/proc_macro/src/backend/support/arena.rs similarity index 100% rename from library/proc_macro/src/bridge/arena.rs rename to library/proc_macro/src/backend/support/arena.rs diff --git a/library/proc_macro/src/bridge/buffer.rs b/library/proc_macro/src/backend/support/buffer.rs similarity index 92% rename from library/proc_macro/src/bridge/buffer.rs rename to library/proc_macro/src/backend/support/buffer.rs index 3760749d83a54..fab97640c6dd9 100644 --- a/library/proc_macro/src/bridge/buffer.rs +++ b/library/proc_macro/src/backend/support/buffer.rs @@ -41,17 +41,17 @@ impl DerefMut for Buffer { impl Buffer { #[inline] - pub(super) fn new() -> Self { + pub(crate) fn new() -> Self { Self::default() } #[inline] - pub(super) fn clear(&mut self) { + pub(crate) fn clear(&mut self) { self.len = 0; } #[inline] - pub(super) fn take(&mut self) -> Self { + pub(crate) fn take(&mut self) -> Self { mem::take(self) } @@ -60,7 +60,7 @@ impl Buffer { // (avoiding a memmove call). With extend_from_slice, LLVM at least // currently is not able to make that optimization. #[inline] - pub(super) fn extend_from_array(&mut self, xs: &[u8; N]) { + pub(crate) fn extend_from_array(&mut self, xs: &[u8; N]) { if xs.len() > (self.capacity - self.len) { let b = self.take(); *self = (b.reserve)(b, xs.len()); @@ -72,7 +72,7 @@ impl Buffer { } #[inline] - pub(super) fn extend_from_slice(&mut self, xs: &[u8]) { + pub(crate) fn extend_from_slice(&mut self, xs: &[u8]) { if xs.len() > (self.capacity - self.len) { let b = self.take(); *self = (b.reserve)(b, xs.len()); @@ -84,7 +84,7 @@ impl Buffer { } #[inline] - pub(super) fn push(&mut self, v: u8) { + pub(crate) fn push(&mut self, v: u8) { // The code here is taken from Vec::push, and we know that reserve() // will panic if we're exceeding isize::MAX bytes and so there's no need // to check for overflow. diff --git a/library/proc_macro/src/bridge/closure.rs b/library/proc_macro/src/backend/support/closure.rs similarity index 90% rename from library/proc_macro/src/bridge/closure.rs rename to library/proc_macro/src/backend/support/closure.rs index e5133907854b2..e7b624f16a8ae 100644 --- a/library/proc_macro/src/bridge/closure.rs +++ b/library/proc_macro/src/backend/support/closure.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; #[repr(C)] -pub(super) struct Closure<'a, A, R> { +pub(crate) struct Closure<'a, A, R> { call: unsafe extern "C" fn(*mut Env, A) -> R, env: *mut Env, // Prevent Send and Sync impls. @@ -24,7 +24,7 @@ impl<'a, A, R, F: FnMut(A) -> R> From<&'a mut F> for Closure<'a, A, R> { } impl<'a, A, R> Closure<'a, A, R> { - pub(super) fn call(&mut self, arg: A) -> R { + pub(crate) fn call(&mut self, arg: A) -> R { unsafe { (self.call)(self.env, arg) } } } diff --git a/library/proc_macro/src/bridge/fxhash.rs b/library/proc_macro/src/backend/support/fxhash.rs similarity index 97% rename from library/proc_macro/src/bridge/fxhash.rs rename to library/proc_macro/src/backend/support/fxhash.rs index 5f6b3d1b929e4..4e5e36ff34df3 100644 --- a/library/proc_macro/src/bridge/fxhash.rs +++ b/library/proc_macro/src/backend/support/fxhash.rs @@ -9,7 +9,7 @@ use std::hash::{BuildHasherDefault, Hasher}; use std::ops::BitXor; /// Type alias for a hashmap using the `fx` hash algorithm. -pub(super) type FxHashMap = HashMap>; +pub(crate) type FxHashMap = HashMap>; /// A speedy hash algorithm for use within rustc. The hashmap in alloc by /// default uses SipHash which isn't quite as speedy as we want. In the compiler @@ -23,7 +23,7 @@ pub(super) type FxHashMap = HashMap>; /// similar or slightly worse than FNV, but the speed of the hash function /// itself is much higher because it works on up to 8 bytes at a time. #[derive(Default)] -pub(super) struct FxHasher { +pub(crate) struct FxHasher { hash: usize, } diff --git a/library/proc_macro/src/bridge/handle.rs b/library/proc_macro/src/backend/support/handle.rs similarity index 80% rename from library/proc_macro/src/bridge/handle.rs rename to library/proc_macro/src/backend/support/handle.rs index 8c53bb609f60c..b0392eb293b06 100644 --- a/library/proc_macro/src/bridge/handle.rs +++ b/library/proc_macro/src/backend/support/handle.rs @@ -8,17 +8,17 @@ use std::sync::atomic::{AtomicU32, Ordering}; use super::fxhash::FxHashMap; -pub(super) type Handle = NonZero; +pub(crate) type Handle = NonZero; /// A store that associates values of type `T` with numeric handles. A value can /// be looked up using its handle. -pub(super) struct OwnedStore { +pub(crate) struct OwnedStore { counter: &'static AtomicU32, data: BTreeMap, } impl OwnedStore { - pub(super) fn new(counter: &'static AtomicU32) -> Self { + pub(crate) fn new(counter: &'static AtomicU32) -> Self { // Ensure the handle counter isn't 0, which would panic later, // when `NonZero::new` (aka `Handle::new`) is called in `alloc`. assert_ne!(counter.load(Ordering::Relaxed), 0); @@ -28,14 +28,14 @@ impl OwnedStore { } impl OwnedStore { - pub(super) fn alloc(&mut self, x: T) -> Handle { + pub(crate) fn alloc(&mut self, x: T) -> Handle { let counter = self.counter.fetch_add(1, Ordering::Relaxed); let handle = Handle::new(counter).expect("`proc_macro` handle counter overflowed"); assert!(self.data.insert(handle, x).is_none()); handle } - pub(super) fn take(&mut self, h: Handle) -> T { + pub(crate) fn take(&mut self, h: Handle) -> T { self.data.remove(&h).expect("use-after-free in `proc_macro` handle") } } @@ -54,22 +54,22 @@ impl IndexMut for OwnedStore { } /// Like `OwnedStore`, but avoids storing any value more than once. -pub(super) struct InternedStore { +pub(crate) struct InternedStore { owned: OwnedStore, interner: FxHashMap, } impl InternedStore { - pub(super) fn new(counter: &'static AtomicU32) -> Self { + pub(crate) fn new(counter: &'static AtomicU32) -> Self { InternedStore { owned: OwnedStore::new(counter), interner: FxHashMap::default() } } - pub(super) fn alloc(&mut self, x: T) -> Handle { + pub(crate) fn alloc(&mut self, x: T) -> Handle { let owned = &mut self.owned; *self.interner.entry(x).or_insert_with(|| owned.alloc(x)) } - pub(super) fn copy(&mut self, h: Handle) -> T { + pub(crate) fn copy(&mut self, h: Handle) -> T { self.owned[h] } } diff --git a/library/proc_macro/src/backend/support/mod.rs b/library/proc_macro/src/backend/support/mod.rs new file mode 100644 index 0000000000000..aea0c42abfac9 --- /dev/null +++ b/library/proc_macro/src/backend/support/mod.rs @@ -0,0 +1,12 @@ +#[allow(unsafe_code)] +pub(crate) mod arena; +#[allow(unsafe_code)] +pub(crate) mod buffer; +#[allow(unsafe_code)] +pub(crate) mod closure; +#[forbid(unsafe_code)] +pub(crate) mod fxhash; +#[forbid(unsafe_code)] +pub(crate) mod handle; +#[allow(unsafe_code)] +pub(crate) mod selfless_reify; diff --git a/library/proc_macro/src/bridge/selfless_reify.rs b/library/proc_macro/src/backend/support/selfless_reify.rs similarity index 97% rename from library/proc_macro/src/bridge/selfless_reify.rs rename to library/proc_macro/src/backend/support/selfless_reify.rs index b06434a5ffee2..ace07bf16aabc 100644 --- a/library/proc_macro/src/bridge/selfless_reify.rs +++ b/library/proc_macro/src/backend/support/selfless_reify.rs @@ -44,7 +44,7 @@ macro_rules! define_reify_functions { fn $name:ident $(<$($param:ident),*>)? for $(extern $abi:tt)? fn($($arg:ident: $arg_ty:ty),*) -> $ret_ty:ty; )+) => { - $(pub(super) const fn $name< + $(pub(crate) const fn $name< $($($param,)*)? F: Fn($($arg_ty),*) -> $ret_ty + Copy >(f: F) -> $(extern $abi)? fn($($arg_ty),*) -> $ret_ty { @@ -80,5 +80,5 @@ define_reify_functions! { // because of the `fn` pointer type being "higher-ranked" (i.e. the // `for<'a>` binder). // FIXME(eddyb) try to remove the lifetime from `BridgeConfig`, that'd help. - fn reify_to_extern_c_fn_hrt_bridge for extern "C" fn(bridge: super::BridgeConfig<'_>) -> R; + fn reify_to_extern_c_fn_hrt_bridge for extern "C" fn(bridge: crate::backend::BridgeConfig<'_>) -> R; } diff --git a/library/proc_macro/src/bridge/symbol.rs b/library/proc_macro/src/backend/symbol.rs similarity index 97% rename from library/proc_macro/src/bridge/symbol.rs rename to library/proc_macro/src/backend/symbol.rs index 57ca7db9fcdd7..27b0e833b489e 100644 --- a/library/proc_macro/src/bridge/symbol.rs +++ b/library/proc_macro/src/backend/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: Arena::new(), + names: 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: 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: 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 = Arena::new(); } } diff --git a/library/proc_macro/src/lib.rs b/library/proc_macro/src/lib.rs index 613abd7024e3f..8f5110b822190 100644 --- a/library/proc_macro/src/lib.rs +++ b/library/proc_macro/src/lib.rs @@ -38,7 +38,16 @@ #[unstable(feature = "proc_macro_internals", issue = "27812")] #[doc(hidden)] -pub mod bridge; +mod backend; + +#[unstable(feature = "proc_macro_internals", issue = "27812")] +#[doc(hidden)] +pub mod bridge { + pub use super::backend::{ + DelimSpan, Diagnostic, ExpnGlobals, Group, Ident, LitKind, Literal, PanicMessage, Punct, + TokenTree, client, server, + }; +} mod diagnostic; mod escape; @@ -86,7 +95,7 @@ pub enum ConversionErrorKind { /// 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::client::is_available() } /// The main type provided by this crate, representing an abstract stream of @@ -99,7 +108,7 @@ pub fn is_available() -> bool { #[cfg_attr(feature = "rustc-dep-of-std", 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 {} @@ -175,7 +184,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::client::TokenStream::expand_expr(stream) { Ok(stream) => Ok(TokenStream(Some(stream))), Err(_) => Err(ExpandError), } @@ -194,7 +203,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::client::TokenStream::from_str(src)))) } } @@ -241,12 +250,13 @@ pub use quote::{HasIterator, RepInterp, ThereIsNoIteratorInRepetition, ext, quot fn tree_to_bridge_tree( tree: TokenTree, -) -> bridge::TokenTree { +) -> backend::TokenTree +{ 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::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), } } @@ -254,7 +264,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(bridge::client::TokenStream::from_token_tree(tree_to_bridge_tree(tree)))) + TokenStream(Some(backend::client::TokenStream::from_token_tree(tree_to_bridge_tree(tree)))) } } @@ -262,10 +272,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::TokenTree< + backend::client::TokenStream, + backend::client::Span, + backend::client::Symbol, >, >, } @@ -283,7 +293,7 @@ impl ConcatTreesHelper { if self.trees.is_empty() { TokenStream(None) } else { - TokenStream(Some(bridge::client::TokenStream::concat_trees(None, self.trees))) + TokenStream(Some(backend::client::TokenStream::concat_trees(None, self.trees))) } } @@ -291,14 +301,14 @@ 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::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 { @@ -316,7 +326,7 @@ 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::client::TokenStream::concat_streams(None, self.streams))) } } @@ -328,7 +338,7 @@ 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::client::TokenStream::concat_streams(base, self.streams)); } } } @@ -379,7 +389,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::{Group, Ident, Literal, Punct, TokenStream, TokenTree, bridge}; + 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, @@ -388,10 +398,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, >, >, ); @@ -402,10 +412,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)), }) } @@ -449,7 +459,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::client::Span); #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl !Send for Span {} @@ -471,7 +481,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::client::Span::def_site()) } /// The span of the invocation of the current procedural macro. @@ -480,7 +490,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::client::Span::call_site()) } /// A span that represents `macro_rules` hygiene, and sometimes resolves at the macro @@ -489,7 +499,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::client::Span::mixed_site()) } /// The `Span` for the tokens in the previous macro expansion from which @@ -611,7 +621,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::client::Span::recover_proc_macro_span(id)) } diagnostic_method!(error, Level::Error); @@ -752,7 +762,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(bridge::Group); +pub struct Group(backend::Group); #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl !Send for Group {} @@ -801,10 +811,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::Group { delimiter, stream: stream.0, - span: bridge::DelimSpan::from_single(Span::call_site().0), + span: backend::DelimSpan::from_single(Span::call_site().0), }) } @@ -865,7 +875,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::DelimSpan::from_single(span.0); } } @@ -897,7 +907,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::Punct); #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl !Send for Punct {} @@ -948,7 +958,7 @@ impl Punct { if !LEGAL_CHARS.contains(&ch) { panic!("unsupported character `{:?}`", ch); } - Punct(bridge::Punct { + Punct(backend::Punct { ch: ch as u8, joint: spacing == Spacing::Joint, span: Span::call_site().0, @@ -1019,7 +1029,7 @@ 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::Ident); impl Ident { /// Creates a new `Ident` with the given `string` as well as the specified @@ -1043,8 +1053,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::Ident { + sym: backend::client::Symbol::new_ident(string, false), is_raw: false, span: span.0, }) @@ -1056,8 +1066,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::Ident { + sym: backend::client::Symbol::new_ident(string, true), is_raw: true, span: span.0, }) @@ -1105,7 +1115,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(bridge::Literal); +pub struct Literal(backend::Literal); macro_rules! suffixed_int_literals { ($($name:ident => $kind:ident,)*) => ($( @@ -1122,10 +1132,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::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, }) } @@ -1149,9 +1159,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::Literal { + kind: backend::LitKind::Integer, + symbol: backend::client::Symbol::new(&n.to_string()), suffix: None, span: Span::call_site().0, }) @@ -1160,11 +1170,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::LitKind, value: &str, suffix: Option<&str>) -> Self { + Literal(backend::Literal { kind, - symbol: bridge::client::Symbol::new(value), - suffix: suffix.map(bridge::client::Symbol::new), + symbol: backend::client::Symbol::new(value), + suffix: suffix.map(backend::client::Symbol::new), span: Span::call_site().0, }) } @@ -1220,7 +1230,7 @@ impl Literal { if !repr.contains('.') { repr.push_str(".0"); } - Literal::new(bridge::LitKind::Float, &repr, None) + Literal::new(backend::LitKind::Float, &repr, None) } /// Creates a new suffixed floating-point literal. @@ -1241,7 +1251,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::LitKind::Float, &n.to_string(), Some("f32")) } /// Creates a new unsuffixed floating-point literal. @@ -1265,7 +1275,7 @@ impl Literal { if !repr.contains('.') { repr.push_str(".0"); } - Literal::new(bridge::LitKind::Float, &repr, None) + Literal::new(backend::LitKind::Float, &repr, None) } /// Creates a new suffixed floating-point literal. @@ -1286,7 +1296,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::LitKind::Float, &n.to_string(), Some("f64")) } /// String literal. @@ -1298,7 +1308,7 @@ impl Literal { escape_nonascii: false, }; let repr = escape_bytes(string.as_bytes(), escape); - Literal::new(bridge::LitKind::Str, &repr, None) + Literal::new(backend::LitKind::Str, &repr, None) } /// Character literal. @@ -1310,7 +1320,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::LitKind::Char, &repr, None) } /// Byte character literal. @@ -1322,7 +1332,7 @@ impl Literal { escape_nonascii: true, }; let repr = escape_bytes(&[byte], escape); - Literal::new(bridge::LitKind::Byte, &repr, None) + Literal::new(backend::LitKind::Byte, &repr, None) } /// Byte string literal. @@ -1334,7 +1344,7 @@ impl Literal { escape_nonascii: true, }; let repr = escape_bytes(bytes, escape); - Literal::new(bridge::LitKind::ByteStr, &repr, None) + Literal::new(backend::LitKind::ByteStr, &repr, None) } /// C string literal. @@ -1346,7 +1356,7 @@ impl Literal { escape_nonascii: false, }; let repr = escape_bytes(string.to_bytes(), escape); - Literal::new(bridge::LitKind::CStr, &repr, None) + Literal::new(backend::LitKind::CStr, &repr, None) } /// Returns the span encompassing this literal. @@ -1404,25 +1414,25 @@ 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::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]) } - bridge::LitKind::ByteStr => f(&["b\"", symbol, "\"", suffix]), - 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]) } - bridge::LitKind::CStr => f(&["c\"", symbol, "\"", suffix]), - 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]) } - bridge::LitKind::Integer | bridge::LitKind::Float | bridge::LitKind::ErrWithGuar => { + backend::LitKind::Integer | backend::LitKind::Float | backend::LitKind::ErrWithGuar => { f(&[symbol, suffix]) } }) @@ -1432,7 +1442,7 @@ impl Literal { #[unstable(feature = "proc_macro_value", issue = "136652")] pub fn str_value(&self) -> Result { self.0.symbol.with(|symbol| match self.0.kind { - bridge::LitKind::Str => { + backend::LitKind::Str => { if symbol.contains('\\') { let mut buf = String::with_capacity(symbol.len()); let mut error = None; @@ -1456,7 +1466,7 @@ impl Literal { Ok(symbol.to_string()) } } - bridge::LitKind::StrRaw(_) => Ok(symbol.to_string()), + backend::LitKind::StrRaw(_) => Ok(symbol.to_string()), _ => Err(ConversionErrorKind::InvalidLiteralKind), }) } @@ -1466,7 +1476,7 @@ impl Literal { #[unstable(feature = "proc_macro_value", issue = "136652")] pub fn cstr_value(&self) -> Result, ConversionErrorKind> { self.0.symbol.with(|symbol| match self.0.kind { - bridge::LitKind::CStr => { + backend::LitKind::CStr => { let mut error = None; let mut buf = Vec::with_capacity(symbol.len()); @@ -1488,7 +1498,7 @@ impl Literal { Ok(buf) } } - bridge::LitKind::CStrRaw(_) => { + backend::LitKind::CStrRaw(_) => { // Raw strings have no escapes so we can convert the symbol // directly to a `Lrc` after appending the terminating NUL // char. @@ -1505,7 +1515,7 @@ impl Literal { #[unstable(feature = "proc_macro_value", issue = "136652")] pub fn byte_str_value(&self) -> Result, ConversionErrorKind> { self.0.symbol.with(|symbol| match self.0.kind { - bridge::LitKind::ByteStr => { + backend::LitKind::ByteStr => { let mut buf = Vec::with_capacity(symbol.len()); let mut error = None; @@ -1519,7 +1529,7 @@ impl Literal { }); if let Some(error) = error { Err(error) } else { Ok(buf) } } - bridge::LitKind::ByteStrRaw(_) => { + backend::LitKind::ByteStrRaw(_) => { // Raw strings have no escapes so we can convert the symbol // directly to a `Lrc`. Ok(symbol.to_owned().into_bytes()) @@ -1544,7 +1554,7 @@ impl FromStr for Literal { type Err = LexError; fn from_str(src: &str) -> Result { - match bridge::client::FreeFunctions::literal_from_str(src) { + match backend::client::FreeFunctions::literal_from_str(src) { Ok(literal) => Ok(Literal(literal)), Err(()) => Err(LexError), } @@ -1593,9 +1603,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::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::client::FreeFunctions::track_env_var(key, value.as_deref().ok()); value } } @@ -1610,6 +1620,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::client::FreeFunctions::track_path(path); } } diff --git a/tests/ui/proc-macro/bad-projection.stderr b/tests/ui/proc-macro/bad-projection.stderr index f2981499367b8..ab561c8240c59 100644 --- a/tests/ui/proc-macro/bad-projection.stderr +++ b/tests/ui/proc-macro/bad-projection.stderr @@ -34,7 +34,7 @@ LL | pub fn uwu() -> <() as Project>::Assoc {} | required by a bound introduced by this call | note: required by a bound in `ProcMacro::bang` - --> $SRC_DIR/proc_macro/src/bridge/client.rs:LL:COL + --> $SRC_DIR/proc_macro/src/backend/client.rs:LL:COL error[E0277]: the trait bound `(): Project` is not satisfied --> $DIR/bad-projection.rs:14:1