Skip to main content

rustc_proc_macro/bridge/
mod.rs

1//! Internal interface for communicating between a `proc_macro` client
2//! (a proc macro crate) and a `proc_macro` server (a compiler front-end).
3//!
4//! Serialization (with C ABI buffers) and unique integer handles are employed
5//! to allow safely interfacing between two copies of `proc_macro` built
6//! (from the same source) by different compilers with potentially mismatching
7//! Rust ABIs (e.g., stage0/bin/rustc vs stage1/bin/rustc during bootstrap).
8
9#![deny(unsafe_code)]
10
11use std::hash::Hash;
12use std::marker;
13use std::ops::{Bound, Range};
14
15use crate::{Delimiter, Level};
16
17/// Higher-order macro describing the server RPC API, allowing automatic
18/// generation of type-safe Rust APIs, both client-side and server-side.
19///
20/// `with_api!(my_macro, MyTokenStream, MySpan, MySymbol)` expands to:
21/// ```rust,ignore (pseudo-code)
22/// my_macro! {
23///     fn ts_clone(stream: &MyTokenStream) -> MyTokenStream;
24///     fn span_debug(span: &MySpan) -> String;
25///     // ...
26/// }
27/// ```
28///
29/// The second (`TokenStream`), third (`Span`) and fourth (`Symbol`)
30/// argument serve to customize the argument/return types that need
31/// special handling, to enable several different representations of
32/// these types.
33macro_rules! with_api {
34    ($m:ident, $TokenStream: path, $Span: path, $Symbol: path) => {
35        $m! {
36            fn track_env_var(var: &str, value: Option<&str>);
37            fn track_path(path: &str);
38            fn literal_from_str(s: &str) -> Result<Literal<$Span, $Symbol>, String>;
39            fn emit_diagnostic(diagnostic: Diagnostic<$Span>);
40
41            fn ts_drop(stream: $TokenStream);
42            fn ts_clone(stream: &$TokenStream) -> $TokenStream;
43            fn ts_is_empty(stream: &$TokenStream) -> bool;
44            fn ts_expand_expr(stream: &$TokenStream) -> Result<$TokenStream, ()>;
45            fn ts_from_str(src: &str) -> Result<$TokenStream, String>;
46            fn ts_to_string(stream: &$TokenStream) -> String;
47            fn ts_from_token_tree(
48                tree: TokenTree<$TokenStream, $Span, $Symbol>,
49            ) -> $TokenStream;
50            fn ts_concat_trees(
51                base: Option<$TokenStream>,
52                trees: Vec<TokenTree<$TokenStream, $Span, $Symbol>>,
53            ) -> $TokenStream;
54            fn ts_concat_streams(
55                base: Option<$TokenStream>,
56                streams: Vec<$TokenStream>,
57            ) -> $TokenStream;
58            fn ts_into_trees(
59                stream: $TokenStream
60            ) -> Vec<TokenTree<$TokenStream, $Span, $Symbol>>;
61
62            fn span_debug(span: $Span) -> String;
63            fn span_parent(span: $Span) -> Option<$Span>;
64            fn span_source(span: $Span) -> $Span;
65            fn span_byte_range(span: $Span) -> Range<usize>;
66            fn span_start(span: $Span) -> $Span;
67            fn span_end(span: $Span) -> $Span;
68            fn span_line(span: $Span) -> usize;
69            fn span_column(span: $Span) -> usize;
70            fn span_file(span: $Span) -> String;
71            fn span_local_file(span: $Span) -> Option<String>;
72            fn span_join(span: $Span, other: $Span) -> Option<$Span>;
73            fn span_subspan(span: $Span, start: Bound<usize>, end: Bound<usize>) -> Option<$Span>;
74            fn span_resolved_at(span: $Span, at: $Span) -> $Span;
75            fn span_source_text(span: $Span) -> Option<String>;
76            fn span_save_span(span: $Span) -> usize;
77            fn span_recover_proc_macro_span(id: usize) -> $Span;
78
79            fn symbol_normalize_and_validate_ident(string: &str) -> Result<$Symbol, ()>;
80        }
81    };
82}
83
84pub(crate) struct Methods;
85
86#[allow(unsafe_code)]
87mod arena;
88#[allow(unsafe_code)]
89mod buffer;
90#[deny(unsafe_code)]
91pub mod client;
92#[allow(unsafe_code)]
93mod closure;
94#[forbid(unsafe_code)]
95mod fxhash;
96#[forbid(unsafe_code)]
97mod handle;
98#[macro_use]
99#[forbid(unsafe_code)]
100mod rpc;
101#[forbid(unsafe_code)]
102mod panic_message;
103#[allow(unsafe_code)]
104mod selfless_reify;
105#[forbid(unsafe_code)]
106pub mod server;
107#[allow(unsafe_code)]
108mod symbol;
109
110use buffer::Buffer;
111pub use panic_message::PanicMessage;
112use rpc::{Decode, Encode};
113
114/// Configuration for establishing an active connection between a server and a
115/// client.  The server creates the bridge config (`run_server` in `server.rs`),
116/// then passes it to the client through the function pointer in the `run` field
117/// of `client::Client`. The client constructs a local `Bridge` from the config
118/// in TLS during its execution (`Bridge::{enter, with}` in `client.rs`).
119#[repr(C)]
120pub struct BridgeConfig<'a> {
121    /// Buffer used to pass initial input to the client.
122    input: Buffer,
123
124    /// Server-side function that the client uses to make requests.
125    dispatch: closure::Closure<'a>,
126
127    /// If 'true', always invoke the default panic hook
128    force_show_panics: bool,
129}
130
131impl !Send for BridgeConfig<'_> {}
132impl !Sync for BridgeConfig<'_> {}
133
134macro_rules! declare_tags {
135    (
136        $(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)?;)*
137    ) => {
138        #[allow(non_camel_case_types)]
139        pub(super) enum ApiTags {
140            $($method),*
141        }
142        rpc_encode_decode!(enum ApiTags { $($method),* });
143    }
144}
145#[allow(non_camel_case_types)]
pub(super) enum ApiTags {
    track_env_var,
    track_path,
    literal_from_str,
    emit_diagnostic,
    ts_drop,
    ts_clone,
    ts_is_empty,
    ts_expand_expr,
    ts_from_str,
    ts_to_string,
    ts_from_token_tree,
    ts_concat_trees,
    ts_concat_streams,
    ts_into_trees,
    span_debug,
    span_parent,
    span_source,
    span_byte_range,
    span_start,
    span_end,
    span_line,
    span_column,
    span_file,
    span_local_file,
    span_join,
    span_subspan,
    span_resolved_at,
    span_source_text,
    span_save_span,
    span_recover_proc_macro_span,
    symbol_normalize_and_validate_ident,
}
#[allow(non_upper_case_globals, non_camel_case_types)]
const _: () =
    {
        #[repr(u8)]
        enum Tag {
            track_env_var,
            track_path,
            literal_from_str,
            emit_diagnostic,
            ts_drop,
            ts_clone,
            ts_is_empty,
            ts_expand_expr,
            ts_from_str,
            ts_to_string,
            ts_from_token_tree,
            ts_concat_trees,
            ts_concat_streams,
            ts_into_trees,
            span_debug,
            span_parent,
            span_source,
            span_byte_range,
            span_start,
            span_end,
            span_line,
            span_column,
            span_file,
            span_local_file,
            span_join,
            span_subspan,
            span_resolved_at,
            span_source_text,
            span_save_span,
            span_recover_proc_macro_span,
            symbol_normalize_and_validate_ident,
        }
        const track_env_var: u8 = Tag::track_env_var as u8;
        const track_path: u8 = Tag::track_path as u8;
        const literal_from_str: u8 = Tag::literal_from_str as u8;
        const emit_diagnostic: u8 = Tag::emit_diagnostic as u8;
        const ts_drop: u8 = Tag::ts_drop as u8;
        const ts_clone: u8 = Tag::ts_clone as u8;
        const ts_is_empty: u8 = Tag::ts_is_empty as u8;
        const ts_expand_expr: u8 = Tag::ts_expand_expr as u8;
        const ts_from_str: u8 = Tag::ts_from_str as u8;
        const ts_to_string: u8 = Tag::ts_to_string as u8;
        const ts_from_token_tree: u8 = Tag::ts_from_token_tree as u8;
        const ts_concat_trees: u8 = Tag::ts_concat_trees as u8;
        const ts_concat_streams: u8 = Tag::ts_concat_streams as u8;
        const ts_into_trees: u8 = Tag::ts_into_trees as u8;
        const span_debug: u8 = Tag::span_debug as u8;
        const span_parent: u8 = Tag::span_parent as u8;
        const span_source: u8 = Tag::span_source as u8;
        const span_byte_range: u8 = Tag::span_byte_range as u8;
        const span_start: u8 = Tag::span_start as u8;
        const span_end: u8 = Tag::span_end as u8;
        const span_line: u8 = Tag::span_line as u8;
        const span_column: u8 = Tag::span_column as u8;
        const span_file: u8 = Tag::span_file as u8;
        const span_local_file: u8 = Tag::span_local_file as u8;
        const span_join: u8 = Tag::span_join as u8;
        const span_subspan: u8 = Tag::span_subspan as u8;
        const span_resolved_at: u8 = Tag::span_resolved_at as u8;
        const span_source_text: u8 = Tag::span_source_text as u8;
        const span_save_span: u8 = Tag::span_save_span as u8;
        const span_recover_proc_macro_span: u8 =
            Tag::span_recover_proc_macro_span as u8;
        const symbol_normalize_and_validate_ident: u8 =
            Tag::symbol_normalize_and_validate_ident as u8;
        impl<S> Encode<S> for ApiTags {
            #[inline]
            fn encode(self, w: &mut Buffer, s: &mut S) {
                match self {
                    ApiTags::track_env_var => { track_env_var.encode(w, s); }
                    ApiTags::track_path => { track_path.encode(w, s); }
                    ApiTags::literal_from_str => {
                        literal_from_str.encode(w, s);
                    }
                    ApiTags::emit_diagnostic => {
                        emit_diagnostic.encode(w, s);
                    }
                    ApiTags::ts_drop => { ts_drop.encode(w, s); }
                    ApiTags::ts_clone => { ts_clone.encode(w, s); }
                    ApiTags::ts_is_empty => { ts_is_empty.encode(w, s); }
                    ApiTags::ts_expand_expr => { ts_expand_expr.encode(w, s); }
                    ApiTags::ts_from_str => { ts_from_str.encode(w, s); }
                    ApiTags::ts_to_string => { ts_to_string.encode(w, s); }
                    ApiTags::ts_from_token_tree => {
                        ts_from_token_tree.encode(w, s);
                    }
                    ApiTags::ts_concat_trees => {
                        ts_concat_trees.encode(w, s);
                    }
                    ApiTags::ts_concat_streams => {
                        ts_concat_streams.encode(w, s);
                    }
                    ApiTags::ts_into_trees => { ts_into_trees.encode(w, s); }
                    ApiTags::span_debug => { span_debug.encode(w, s); }
                    ApiTags::span_parent => { span_parent.encode(w, s); }
                    ApiTags::span_source => { span_source.encode(w, s); }
                    ApiTags::span_byte_range => {
                        span_byte_range.encode(w, s);
                    }
                    ApiTags::span_start => { span_start.encode(w, s); }
                    ApiTags::span_end => { span_end.encode(w, s); }
                    ApiTags::span_line => { span_line.encode(w, s); }
                    ApiTags::span_column => { span_column.encode(w, s); }
                    ApiTags::span_file => { span_file.encode(w, s); }
                    ApiTags::span_local_file => {
                        span_local_file.encode(w, s);
                    }
                    ApiTags::span_join => { span_join.encode(w, s); }
                    ApiTags::span_subspan => { span_subspan.encode(w, s); }
                    ApiTags::span_resolved_at => {
                        span_resolved_at.encode(w, s);
                    }
                    ApiTags::span_source_text => {
                        span_source_text.encode(w, s);
                    }
                    ApiTags::span_save_span => { span_save_span.encode(w, s); }
                    ApiTags::span_recover_proc_macro_span => {
                        span_recover_proc_macro_span.encode(w, s);
                    }
                    ApiTags::symbol_normalize_and_validate_ident => {
                        symbol_normalize_and_validate_ident.encode(w, s);
                    }
                }
            }
        }
        impl<'a, S> Decode<'a, '_, S> for ApiTags {
            #[inline]
            fn decode(r: &mut &'a [u8], s: &mut S) -> Self {
                match u8::decode(r, s) {
                    track_env_var => { ApiTags::track_env_var }
                    track_path => { ApiTags::track_path }
                    literal_from_str => { ApiTags::literal_from_str }
                    emit_diagnostic => { ApiTags::emit_diagnostic }
                    ts_drop => { ApiTags::ts_drop }
                    ts_clone => { ApiTags::ts_clone }
                    ts_is_empty => { ApiTags::ts_is_empty }
                    ts_expand_expr => { ApiTags::ts_expand_expr }
                    ts_from_str => { ApiTags::ts_from_str }
                    ts_to_string => { ApiTags::ts_to_string }
                    ts_from_token_tree => { ApiTags::ts_from_token_tree }
                    ts_concat_trees => { ApiTags::ts_concat_trees }
                    ts_concat_streams => { ApiTags::ts_concat_streams }
                    ts_into_trees => { ApiTags::ts_into_trees }
                    span_debug => { ApiTags::span_debug }
                    span_parent => { ApiTags::span_parent }
                    span_source => { ApiTags::span_source }
                    span_byte_range => { ApiTags::span_byte_range }
                    span_start => { ApiTags::span_start }
                    span_end => { ApiTags::span_end }
                    span_line => { ApiTags::span_line }
                    span_column => { ApiTags::span_column }
                    span_file => { ApiTags::span_file }
                    span_local_file => { ApiTags::span_local_file }
                    span_join => { ApiTags::span_join }
                    span_subspan => { ApiTags::span_subspan }
                    span_resolved_at => { ApiTags::span_resolved_at }
                    span_source_text => { ApiTags::span_source_text }
                    span_save_span => { ApiTags::span_save_span }
                    span_recover_proc_macro_span => {
                        ApiTags::span_recover_proc_macro_span
                    }
                    symbol_normalize_and_validate_ident => {
                        ApiTags::symbol_normalize_and_validate_ident
                    }
                    _ =>
                        ::core::panicking::panic("internal error: entered unreachable code"),
                }
            }
        }
    };with_api!(declare_tags, __, __, __);
146
147/// Helper to wrap associated types to allow trait impl dispatch.
148/// That is, normally a pair of impls for `T::Foo` and `T::Bar`
149/// can overlap, but if the impls are, instead, on types like
150/// `Marked<T::Foo, Foo>` and `Marked<T::Bar, Bar>`, they can't.
151trait Mark {
152    type Unmarked;
153    fn mark(unmarked: Self::Unmarked) -> Self;
154    fn unmark(self) -> Self::Unmarked;
155}
156
157#[derive(#[automatically_derived]
impl<T: ::core::marker::Copy, M: ::core::marker::Copy> ::core::marker::Copy
    for Marked<T, M> {
}Copy, #[automatically_derived]
impl<T: ::core::clone::Clone, M: ::core::clone::Clone> ::core::clone::Clone
    for Marked<T, M> {
    #[inline]
    fn clone(&self) -> Marked<T, M> {
        Marked {
            value: ::core::clone::Clone::clone(&self.value),
            _marker: ::core::clone::Clone::clone(&self._marker),
        }
    }
}Clone, #[automatically_derived]
impl<T: ::core::cmp::PartialEq, M: ::core::cmp::PartialEq>
    ::core::marker::StructuralPartialEq for Marked<T, M> {
}
#[automatically_derived]
impl<T: ::core::cmp::PartialEq, M: ::core::cmp::PartialEq>
    ::core::cmp::PartialEq for Marked<T, M> {
    #[inline]
    fn eq(&self, other: &Marked<T, M>) -> bool {
        self.value == other.value && self._marker == other._marker
    }
}PartialEq, #[automatically_derived]
impl<T: ::core::cmp::Eq, M: ::core::cmp::Eq> ::core::cmp::Eq for Marked<T, M>
    {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<T>;
        let _: ::core::cmp::AssertParamIsEq<marker::PhantomData<M>>;
    }
}Eq, #[automatically_derived]
impl<T: ::core::hash::Hash, M: ::core::hash::Hash> ::core::hash::Hash for
    Marked<T, M> {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        ::core::hash::Hash::hash(&self.value, state);
        ::core::hash::Hash::hash(&self._marker, state)
    }
}Hash)]
158struct Marked<T, M> {
159    value: T,
160    _marker: marker::PhantomData<M>,
161}
162
163impl<T, M> Mark for Marked<T, M> {
164    type Unmarked = T;
165    #[inline]
166    fn mark(unmarked: Self::Unmarked) -> Self {
167        Marked { value: unmarked, _marker: marker::PhantomData }
168    }
169    #[inline]
170    fn unmark(self) -> Self::Unmarked {
171        self.value
172    }
173}
174impl<'a, T> Mark for &'a Marked<T, client::TokenStream> {
175    type Unmarked = &'a T;
176    fn mark(_: Self::Unmarked) -> Self {
177        ::core::panicking::panic("internal error: entered unreachable code")unreachable!()
178    }
179    #[inline]
180    fn unmark(self) -> Self::Unmarked {
181        &self.value
182    }
183}
184
185impl<T: Mark> Mark for Vec<T> {
186    type Unmarked = Vec<T::Unmarked>;
187    #[inline]
188    fn mark(unmarked: Self::Unmarked) -> Self {
189        // Should be a no-op due to std's in-place collect optimizations.
190        unmarked.into_iter().map(T::mark).collect()
191    }
192    #[inline]
193    fn unmark(self) -> Self::Unmarked {
194        // Should be a no-op due to std's in-place collect optimizations.
195        self.into_iter().map(T::unmark).collect()
196    }
197}
198
199macro_rules! mark_noop {
200    ($($ty:ty),* $(,)?) => {
201        $(
202            impl Mark for $ty {
203                type Unmarked = Self;
204                #[inline]
205                fn mark(unmarked: Self::Unmarked) -> Self {
206                    unmarked
207                }
208                #[inline]
209                fn unmark(self) -> Self::Unmarked {
210                    self
211                }
212            }
213        )*
214    }
215}
216impl Mark for () {
    type Unmarked = Self;
    #[inline]
    fn mark(unmarked: Self::Unmarked) -> Self { unmarked }
    #[inline]
    fn unmark(self) -> Self::Unmarked { self }
}
impl Mark for bool {
    type Unmarked = Self;
    #[inline]
    fn mark(unmarked: Self::Unmarked) -> Self { unmarked }
    #[inline]
    fn unmark(self) -> Self::Unmarked { self }
}
impl Mark for &'_ str {
    type Unmarked = Self;
    #[inline]
    fn mark(unmarked: Self::Unmarked) -> Self { unmarked }
    #[inline]
    fn unmark(self) -> Self::Unmarked { self }
}
impl Mark for String {
    type Unmarked = Self;
    #[inline]
    fn mark(unmarked: Self::Unmarked) -> Self { unmarked }
    #[inline]
    fn unmark(self) -> Self::Unmarked { self }
}
impl Mark for u8 {
    type Unmarked = Self;
    #[inline]
    fn mark(unmarked: Self::Unmarked) -> Self { unmarked }
    #[inline]
    fn unmark(self) -> Self::Unmarked { self }
}
impl Mark for usize {
    type Unmarked = Self;
    #[inline]
    fn mark(unmarked: Self::Unmarked) -> Self { unmarked }
    #[inline]
    fn unmark(self) -> Self::Unmarked { self }
}
impl Mark for Delimiter {
    type Unmarked = Self;
    #[inline]
    fn mark(unmarked: Self::Unmarked) -> Self { unmarked }
    #[inline]
    fn unmark(self) -> Self::Unmarked { self }
}
impl Mark for LitKind {
    type Unmarked = Self;
    #[inline]
    fn mark(unmarked: Self::Unmarked) -> Self { unmarked }
    #[inline]
    fn unmark(self) -> Self::Unmarked { self }
}
impl Mark for Level {
    type Unmarked = Self;
    #[inline]
    fn mark(unmarked: Self::Unmarked) -> Self { unmarked }
    #[inline]
    fn unmark(self) -> Self::Unmarked { self }
}
impl Mark for Bound<usize> {
    type Unmarked = Self;
    #[inline]
    fn mark(unmarked: Self::Unmarked) -> Self { unmarked }
    #[inline]
    fn unmark(self) -> Self::Unmarked { self }
}
impl Mark for Range<usize> {
    type Unmarked = Self;
    #[inline]
    fn mark(unmarked: Self::Unmarked) -> Self { unmarked }
    #[inline]
    fn unmark(self) -> Self::Unmarked { self }
}mark_noop! {
217    (),
218    bool,
219    &'_ str,
220    String,
221    u8,
222    usize,
223    Delimiter,
224    LitKind,
225    Level,
226    Bound<usize>,
227    Range<usize>,
228}
229
230#[allow(non_upper_case_globals, non_camel_case_types)]
const _: () =
    {
        #[repr(u8)]
        enum Tag { Parenthesis, Brace, Bracket, None, }
        const Parenthesis: u8 = Tag::Parenthesis as u8;
        const Brace: u8 = Tag::Brace as u8;
        const Bracket: u8 = Tag::Bracket as u8;
        const None: u8 = Tag::None as u8;
        impl<S> Encode<S> for Delimiter {
            #[inline]
            fn encode(self, w: &mut Buffer, s: &mut S) {
                match self {
                    Delimiter::Parenthesis => { Parenthesis.encode(w, s); }
                    Delimiter::Brace => { Brace.encode(w, s); }
                    Delimiter::Bracket => { Bracket.encode(w, s); }
                    Delimiter::None => { None.encode(w, s); }
                }
            }
        }
        impl<'a, S> Decode<'a, '_, S> for Delimiter {
            #[inline]
            fn decode(r: &mut &'a [u8], s: &mut S) -> Self {
                match u8::decode(r, s) {
                    Parenthesis => { Delimiter::Parenthesis }
                    Brace => { Delimiter::Brace }
                    Bracket => { Delimiter::Bracket }
                    None => { Delimiter::None }
                    _ =>
                        ::core::panicking::panic("internal error: entered unreachable code"),
                }
            }
        }
    };rpc_encode_decode!(
231    enum Delimiter {
232        Parenthesis,
233        Brace,
234        Bracket,
235        None,
236    }
237);
238#[allow(non_upper_case_globals, non_camel_case_types)]
const _: () =
    {
        #[repr(u8)]
        enum Tag { Error, Warning, Note, Help, }
        const Error: u8 = Tag::Error as u8;
        const Warning: u8 = Tag::Warning as u8;
        const Note: u8 = Tag::Note as u8;
        const Help: u8 = Tag::Help as u8;
        impl<S> Encode<S> for Level {
            #[inline]
            fn encode(self, w: &mut Buffer, s: &mut S) {
                match self {
                    Level::Error => { Error.encode(w, s); }
                    Level::Warning => { Warning.encode(w, s); }
                    Level::Note => { Note.encode(w, s); }
                    Level::Help => { Help.encode(w, s); }
                }
            }
        }
        impl<'a, S> Decode<'a, '_, S> for Level {
            #[inline]
            fn decode(r: &mut &'a [u8], s: &mut S) -> Self {
                match u8::decode(r, s) {
                    Error => { Level::Error }
                    Warning => { Level::Warning }
                    Note => { Level::Note }
                    Help => { Level::Help }
                    _ =>
                        ::core::panicking::panic("internal error: entered unreachable code"),
                }
            }
        }
    };rpc_encode_decode!(
239    enum Level {
240        Error,
241        Warning,
242        Note,
243        Help,
244    }
245);
246
247#[derive(#[automatically_derived]
impl ::core::marker::Copy for LitKind { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for LitKind { }
#[automatically_derived]
impl ::core::clone::Clone for LitKind {
    #[inline]
    fn clone(&self) -> LitKind {
        let _: ::core::clone::AssertParamIsClone<u8>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::cmp::Eq for LitKind {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<u8>;
    }
}Eq, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for LitKind { }
#[automatically_derived]
impl ::core::cmp::PartialEq for LitKind {
    #[inline]
    fn eq(&self, other: &LitKind) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (LitKind::StrRaw(__self_0), LitKind::StrRaw(__arg1_0)) =>
                    __self_0 == __arg1_0,
                (LitKind::ByteStrRaw(__self_0), LitKind::ByteStrRaw(__arg1_0))
                    => __self_0 == __arg1_0,
                (LitKind::CStrRaw(__self_0), LitKind::CStrRaw(__arg1_0)) =>
                    __self_0 == __arg1_0,
                _ => true,
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::fmt::Debug for LitKind {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            LitKind::Byte => ::core::fmt::Formatter::write_str(f, "Byte"),
            LitKind::Char => ::core::fmt::Formatter::write_str(f, "Char"),
            LitKind::Integer =>
                ::core::fmt::Formatter::write_str(f, "Integer"),
            LitKind::Float => ::core::fmt::Formatter::write_str(f, "Float"),
            LitKind::Str => ::core::fmt::Formatter::write_str(f, "Str"),
            LitKind::StrRaw(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "StrRaw",
                    &__self_0),
            LitKind::ByteStr =>
                ::core::fmt::Formatter::write_str(f, "ByteStr"),
            LitKind::ByteStrRaw(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "ByteStrRaw", &__self_0),
            LitKind::CStr => ::core::fmt::Formatter::write_str(f, "CStr"),
            LitKind::CStrRaw(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "CStrRaw", &__self_0),
            LitKind::ErrWithGuar =>
                ::core::fmt::Formatter::write_str(f, "ErrWithGuar"),
        }
    }
}Debug)]
248pub enum LitKind {
249    Byte,
250    Char,
251    Integer,
252    Float,
253    Str,
254    StrRaw(u8),
255    ByteStr,
256    ByteStrRaw(u8),
257    CStr,
258    CStrRaw(u8),
259    // This should have an `ErrorGuaranteed`, except that type isn't available
260    // in this crate. (Imagine it is there.) Hence the `WithGuar` suffix. Must
261    // only be constructed in `LitKind::from_internal`, where an
262    // `ErrorGuaranteed` is available.
263    ErrWithGuar,
264}
265
266#[allow(non_upper_case_globals, non_camel_case_types)]
const _: () =
    {
        #[repr(u8)]
        enum Tag {
            Byte,
            Char,
            Integer,
            Float,
            Str,
            StrRaw,
            ByteStr,
            ByteStrRaw,
            CStr,
            CStrRaw,
            ErrWithGuar,
        }
        const Byte: u8 = Tag::Byte as u8;
        const Char: u8 = Tag::Char as u8;
        const Integer: u8 = Tag::Integer as u8;
        const Float: u8 = Tag::Float as u8;
        const Str: u8 = Tag::Str as u8;
        const StrRaw: u8 = Tag::StrRaw as u8;
        const ByteStr: u8 = Tag::ByteStr as u8;
        const ByteStrRaw: u8 = Tag::ByteStrRaw as u8;
        const CStr: u8 = Tag::CStr as u8;
        const CStrRaw: u8 = Tag::CStrRaw as u8;
        const ErrWithGuar: u8 = Tag::ErrWithGuar as u8;
        impl<S> Encode<S> for LitKind {
            #[inline]
            fn encode(self, w: &mut Buffer, s: &mut S) {
                match self {
                    LitKind::Byte => { Byte.encode(w, s); }
                    LitKind::Char => { Char.encode(w, s); }
                    LitKind::Integer => { Integer.encode(w, s); }
                    LitKind::Float => { Float.encode(w, s); }
                    LitKind::Str => { Str.encode(w, s); }
                    LitKind::StrRaw(n) => {
                        StrRaw.encode(w, s);
                        n.encode(w, s);
                    }
                    LitKind::ByteStr => { ByteStr.encode(w, s); }
                    LitKind::ByteStrRaw(n) => {
                        ByteStrRaw.encode(w, s);
                        n.encode(w, s);
                    }
                    LitKind::CStr => { CStr.encode(w, s); }
                    LitKind::CStrRaw(n) => {
                        CStrRaw.encode(w, s);
                        n.encode(w, s);
                    }
                    LitKind::ErrWithGuar => { ErrWithGuar.encode(w, s); }
                }
            }
        }
        impl<'a, S> Decode<'a, '_, S> for LitKind {
            #[inline]
            fn decode(r: &mut &'a [u8], s: &mut S) -> Self {
                match u8::decode(r, s) {
                    Byte => { LitKind::Byte }
                    Char => { LitKind::Char }
                    Integer => { LitKind::Integer }
                    Float => { LitKind::Float }
                    Str => { LitKind::Str }
                    StrRaw => {
                        let n = Decode::decode(r, s);
                        LitKind::StrRaw(n)
                    }
                    ByteStr => { LitKind::ByteStr }
                    ByteStrRaw => {
                        let n = Decode::decode(r, s);
                        LitKind::ByteStrRaw(n)
                    }
                    CStr => { LitKind::CStr }
                    CStrRaw => {
                        let n = Decode::decode(r, s);
                        LitKind::CStrRaw(n)
                    }
                    ErrWithGuar => { LitKind::ErrWithGuar }
                    _ =>
                        ::core::panicking::panic("internal error: entered unreachable code"),
                }
            }
        }
    };rpc_encode_decode!(
267    enum LitKind {
268        Byte,
269        Char,
270        Integer,
271        Float,
272        Str,
273        StrRaw(n),
274        ByteStr,
275        ByteStrRaw(n),
276        CStr,
277        CStrRaw(n),
278        ErrWithGuar,
279    }
280);
281
282macro_rules! mark_compound {
283    (struct $name:ident <$($T:ident),+> { $($field:ident),* $(,)? }) => {
284        impl<$($T: Mark),+> Mark for $name <$($T),+> {
285            type Unmarked = $name <$($T::Unmarked),+>;
286            #[inline]
287            fn mark(unmarked: Self::Unmarked) -> Self {
288                $name {
289                    $($field: Mark::mark(unmarked.$field)),*
290                }
291            }
292            #[inline]
293            fn unmark(self) -> Self::Unmarked {
294                $name {
295                    $($field: Mark::unmark(self.$field)),*
296                }
297            }
298        }
299    };
300    (enum $name:ident <$($T:ident),+> { $($variant:ident $(($field:ident))?),* $(,)? }) => {
301        impl<$($T: Mark),+> Mark for $name <$($T),+> {
302            type Unmarked = $name <$($T::Unmarked),+>;
303            #[inline]
304            fn mark(unmarked: Self::Unmarked) -> Self {
305                match unmarked {
306                    $($name::$variant $(($field))? => {
307                        $name::$variant $((Mark::mark($field)))?
308                    })*
309                }
310            }
311            #[inline]
312            fn unmark(self) -> Self::Unmarked {
313                match self {
314                    $($name::$variant $(($field))? => {
315                        $name::$variant $((Mark::unmark($field)))?
316                    })*
317                }
318            }
319        }
320    }
321}
322
323macro_rules! compound_traits {
324    ($($t:tt)*) => {
325        rpc_encode_decode!($($t)*);
326        mark_compound!($($t)*);
327    };
328}
329
330#[allow(non_upper_case_globals, non_camel_case_types)]
const _: () =
    {
        #[repr(u8)]
        enum Tag { Included, Excluded, Unbounded, }
        const Included: u8 = Tag::Included as u8;
        const Excluded: u8 = Tag::Excluded as u8;
        const Unbounded: u8 = Tag::Unbounded as u8;
        impl<S, T: Encode<S>> Encode<S> for Bound<T> {
            #[inline]
            fn encode(self, w: &mut Buffer, s: &mut S) {
                match self {
                    Bound::Included(x) => {
                        Included.encode(w, s);
                        x.encode(w, s);
                    }
                    Bound::Excluded(x) => {
                        Excluded.encode(w, s);
                        x.encode(w, s);
                    }
                    Bound::Unbounded => { Unbounded.encode(w, s); }
                }
            }
        }
        impl<'a, S, T: for<'s> Decode<'a, 's, S>> Decode<'a, '_, S> for
            Bound<T> {
            #[inline]
            fn decode(r: &mut &'a [u8], s: &mut S) -> Self {
                match u8::decode(r, s) {
                    Included => {
                        let x = Decode::decode(r, s);
                        Bound::Included(x)
                    }
                    Excluded => {
                        let x = Decode::decode(r, s);
                        Bound::Excluded(x)
                    }
                    Unbounded => { Bound::Unbounded }
                    _ =>
                        ::core::panicking::panic("internal error: entered unreachable code"),
                }
            }
        }
    };rpc_encode_decode!(
331    enum Bound<T> {
332        Included(x),
333        Excluded(x),
334        Unbounded,
335    }
336);
337
338#[allow(non_upper_case_globals, non_camel_case_types)]
const _: () =
    {
        #[repr(u8)]
        enum Tag { Some, None, }
        const Some: u8 = Tag::Some as u8;
        const None: u8 = Tag::None as u8;
        impl<S, T: Encode<S>> Encode<S> for Option<T> {
            #[inline]
            fn encode(self, w: &mut Buffer, s: &mut S) {
                match self {
                    Option::Some(t) => { Some.encode(w, s); t.encode(w, s); }
                    Option::None => { None.encode(w, s); }
                }
            }
        }
        impl<'a, S, T: for<'s> Decode<'a, 's, S>> Decode<'a, '_, S> for
            Option<T> {
            #[inline]
            fn decode(r: &mut &'a [u8], s: &mut S) -> Self {
                match u8::decode(r, s) {
                    Some => { let t = Decode::decode(r, s); Option::Some(t) }
                    None => { Option::None }
                    _ =>
                        ::core::panicking::panic("internal error: entered unreachable code"),
                }
            }
        }
    };
impl<T: Mark> Mark for Option<T> {
    type Unmarked = Option<T::Unmarked>;
    #[inline]
    fn mark(unmarked: Self::Unmarked) -> Self {
        match unmarked {
            Option::Some(t) => { Option::Some(Mark::mark(t)) }
            Option::None => { Option::None }
        }
    }
    #[inline]
    fn unmark(self) -> Self::Unmarked {
        match self {
            Option::Some(t) => { Option::Some(Mark::unmark(t)) }
            Option::None => { Option::None }
        }
    }
}compound_traits!(
339    enum Option<T> {
340        Some(t),
341        None,
342    }
343);
344
345#[allow(non_upper_case_globals, non_camel_case_types)]
const _: () =
    {
        #[repr(u8)]
        enum Tag { Ok, Err, }
        const Ok: u8 = Tag::Ok as u8;
        const Err: u8 = Tag::Err as u8;
        impl<S, T: Encode<S>, E: Encode<S>> Encode<S> for Result<T, E> {
            #[inline]
            fn encode(self, w: &mut Buffer, s: &mut S) {
                match self {
                    Result::Ok(t) => { Ok.encode(w, s); t.encode(w, s); }
                    Result::Err(e) => { Err.encode(w, s); e.encode(w, s); }
                }
            }
        }
        impl<'a, S, T: for<'s> Decode<'a, 's, S>,
            E: for<'s> Decode<'a, 's, S>> Decode<'a, '_, S> for Result<T, E> {
            #[inline]
            fn decode(r: &mut &'a [u8], s: &mut S) -> Self {
                match u8::decode(r, s) {
                    Ok => { let t = Decode::decode(r, s); Result::Ok(t) }
                    Err => { let e = Decode::decode(r, s); Result::Err(e) }
                    _ =>
                        ::core::panicking::panic("internal error: entered unreachable code"),
                }
            }
        }
    };
impl<T: Mark, E: Mark> Mark for Result<T, E> {
    type Unmarked = Result<T::Unmarked, E::Unmarked>;
    #[inline]
    fn mark(unmarked: Self::Unmarked) -> Self {
        match unmarked {
            Result::Ok(t) => { Result::Ok(Mark::mark(t)) }
            Result::Err(e) => { Result::Err(Mark::mark(e)) }
        }
    }
    #[inline]
    fn unmark(self) -> Self::Unmarked {
        match self {
            Result::Ok(t) => { Result::Ok(Mark::unmark(t)) }
            Result::Err(e) => { Result::Err(Mark::unmark(e)) }
        }
    }
}compound_traits!(
346    enum Result<T, E> {
347        Ok(t),
348        Err(e),
349    }
350);
351
352#[derive(#[automatically_derived]
impl<Span: ::core::marker::Copy> ::core::marker::Copy for DelimSpan<Span> { }Copy, #[automatically_derived]
impl<Span: ::core::clone::Clone> ::core::clone::Clone for DelimSpan<Span> {
    #[inline]
    fn clone(&self) -> DelimSpan<Span> {
        DelimSpan {
            open: ::core::clone::Clone::clone(&self.open),
            close: ::core::clone::Clone::clone(&self.close),
            entire: ::core::clone::Clone::clone(&self.entire),
        }
    }
}Clone)]
353pub struct DelimSpan<Span> {
354    pub open: Span,
355    pub close: Span,
356    pub entire: Span,
357}
358
359impl<Span: Copy> DelimSpan<Span> {
360    pub fn from_single(span: Span) -> Self {
361        DelimSpan { open: span, close: span, entire: span }
362    }
363}
364
365impl<S, Span: Encode<S>> Encode<S> for DelimSpan<Span> {
    fn encode(self, w: &mut Buffer, s: &mut S) {
        self.open.encode(w, s);
        self.close.encode(w, s);
        self.entire.encode(w, s);
    }
}
impl<'a, S, Span: for<'s> Decode<'a, 's, S>> Decode<'a, '_, S> for
    DelimSpan<Span> {
    #[inline]
    fn decode(r: &mut &'a [u8], s: &mut S) -> Self {
        DelimSpan {
            open: Decode::decode(r, s),
            close: Decode::decode(r, s),
            entire: Decode::decode(r, s),
        }
    }
}
impl<Span: Mark> Mark for DelimSpan<Span> {
    type Unmarked = DelimSpan<Span::Unmarked>;
    #[inline]
    fn mark(unmarked: Self::Unmarked) -> Self {
        DelimSpan {
            open: Mark::mark(unmarked.open),
            close: Mark::mark(unmarked.close),
            entire: Mark::mark(unmarked.entire),
        }
    }
    #[inline]
    fn unmark(self) -> Self::Unmarked {
        DelimSpan {
            open: Mark::unmark(self.open),
            close: Mark::unmark(self.close),
            entire: Mark::unmark(self.entire),
        }
    }
}compound_traits!(struct DelimSpan<Span> { open, close, entire });
366
367#[derive(#[automatically_derived]
impl<TokenStream: ::core::clone::Clone, Span: ::core::clone::Clone>
    ::core::clone::Clone for Group<TokenStream, Span> {
    #[inline]
    fn clone(&self) -> Group<TokenStream, Span> {
        Group {
            delimiter: ::core::clone::Clone::clone(&self.delimiter),
            stream: ::core::clone::Clone::clone(&self.stream),
            span: ::core::clone::Clone::clone(&self.span),
        }
    }
}Clone)]
368pub struct Group<TokenStream, Span> {
369    pub delimiter: Delimiter,
370    pub stream: Option<TokenStream>,
371    pub span: DelimSpan<Span>,
372}
373
374impl<S, TokenStream: Encode<S>, Span: Encode<S>> Encode<S> for
    Group<TokenStream, Span> {
    fn encode(self, w: &mut Buffer, s: &mut S) {
        self.delimiter.encode(w, s);
        self.stream.encode(w, s);
        self.span.encode(w, s);
    }
}
impl<'a, S, TokenStream: for<'s> Decode<'a, 's, S>,
    Span: for<'s> Decode<'a, 's, S>> Decode<'a, '_, S> for
    Group<TokenStream, Span> {
    #[inline]
    fn decode(r: &mut &'a [u8], s: &mut S) -> Self {
        Group {
            delimiter: Decode::decode(r, s),
            stream: Decode::decode(r, s),
            span: Decode::decode(r, s),
        }
    }
}
impl<TokenStream: Mark, Span: Mark> Mark for Group<TokenStream, Span> {
    type Unmarked = Group<TokenStream::Unmarked, Span::Unmarked>;
    #[inline]
    fn mark(unmarked: Self::Unmarked) -> Self {
        Group {
            delimiter: Mark::mark(unmarked.delimiter),
            stream: Mark::mark(unmarked.stream),
            span: Mark::mark(unmarked.span),
        }
    }
    #[inline]
    fn unmark(self) -> Self::Unmarked {
        Group {
            delimiter: Mark::unmark(self.delimiter),
            stream: Mark::unmark(self.stream),
            span: Mark::unmark(self.span),
        }
    }
}compound_traits!(struct Group<TokenStream, Span> { delimiter, stream, span });
375
376#[derive(#[automatically_derived]
impl<Span: ::core::clone::Clone> ::core::clone::Clone for Punct<Span> {
    #[inline]
    fn clone(&self) -> Punct<Span> {
        Punct {
            ch: ::core::clone::Clone::clone(&self.ch),
            joint: ::core::clone::Clone::clone(&self.joint),
            span: ::core::clone::Clone::clone(&self.span),
        }
    }
}Clone)]
377pub struct Punct<Span> {
378    pub ch: u8,
379    pub joint: bool,
380    pub span: Span,
381}
382
383impl<S, Span: Encode<S>> Encode<S> for Punct<Span> {
    fn encode(self, w: &mut Buffer, s: &mut S) {
        self.ch.encode(w, s);
        self.joint.encode(w, s);
        self.span.encode(w, s);
    }
}
impl<'a, S, Span: for<'s> Decode<'a, 's, S>> Decode<'a, '_, S> for Punct<Span>
    {
    #[inline]
    fn decode(r: &mut &'a [u8], s: &mut S) -> Self {
        Punct {
            ch: Decode::decode(r, s),
            joint: Decode::decode(r, s),
            span: Decode::decode(r, s),
        }
    }
}
impl<Span: Mark> Mark for Punct<Span> {
    type Unmarked = Punct<Span::Unmarked>;
    #[inline]
    fn mark(unmarked: Self::Unmarked) -> Self {
        Punct {
            ch: Mark::mark(unmarked.ch),
            joint: Mark::mark(unmarked.joint),
            span: Mark::mark(unmarked.span),
        }
    }
    #[inline]
    fn unmark(self) -> Self::Unmarked {
        Punct {
            ch: Mark::unmark(self.ch),
            joint: Mark::unmark(self.joint),
            span: Mark::unmark(self.span),
        }
    }
}compound_traits!(struct Punct<Span> { ch, joint, span });
384
385#[derive(#[automatically_derived]
impl<Span: ::core::marker::Copy, Symbol: ::core::marker::Copy>
    ::core::marker::Copy for Ident<Span, Symbol> {
}Copy, #[automatically_derived]
impl<Span: ::core::clone::Clone, Symbol: ::core::clone::Clone>
    ::core::clone::Clone for Ident<Span, Symbol> {
    #[inline]
    fn clone(&self) -> Ident<Span, Symbol> {
        Ident {
            sym: ::core::clone::Clone::clone(&self.sym),
            is_raw: ::core::clone::Clone::clone(&self.is_raw),
            span: ::core::clone::Clone::clone(&self.span),
        }
    }
}Clone, #[automatically_derived]
impl<Span: ::core::cmp::Eq, Symbol: ::core::cmp::Eq> ::core::cmp::Eq for
    Ident<Span, Symbol> {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<Symbol>;
        let _: ::core::cmp::AssertParamIsEq<bool>;
        let _: ::core::cmp::AssertParamIsEq<Span>;
    }
}Eq, #[automatically_derived]
impl<Span: ::core::cmp::PartialEq, Symbol: ::core::cmp::PartialEq>
    ::core::marker::StructuralPartialEq for Ident<Span, Symbol> {
}
#[automatically_derived]
impl<Span: ::core::cmp::PartialEq, Symbol: ::core::cmp::PartialEq>
    ::core::cmp::PartialEq for Ident<Span, Symbol> {
    #[inline]
    fn eq(&self, other: &Ident<Span, Symbol>) -> bool {
        self.is_raw == other.is_raw && self.sym == other.sym &&
            self.span == other.span
    }
}PartialEq)]
386pub struct Ident<Span, Symbol> {
387    pub sym: Symbol,
388    pub is_raw: bool,
389    pub span: Span,
390}
391
392impl<S, Span: Encode<S>, Symbol: Encode<S>> Encode<S> for Ident<Span, Symbol>
    {
    fn encode(self, w: &mut Buffer, s: &mut S) {
        self.sym.encode(w, s);
        self.is_raw.encode(w, s);
        self.span.encode(w, s);
    }
}
impl<'a, S, Span: for<'s> Decode<'a, 's, S>,
    Symbol: for<'s> Decode<'a, 's, S>> Decode<'a, '_, S> for
    Ident<Span, Symbol> {
    #[inline]
    fn decode(r: &mut &'a [u8], s: &mut S) -> Self {
        Ident {
            sym: Decode::decode(r, s),
            is_raw: Decode::decode(r, s),
            span: Decode::decode(r, s),
        }
    }
}
impl<Span: Mark, Symbol: Mark> Mark for Ident<Span, Symbol> {
    type Unmarked = Ident<Span::Unmarked, Symbol::Unmarked>;
    #[inline]
    fn mark(unmarked: Self::Unmarked) -> Self {
        Ident {
            sym: Mark::mark(unmarked.sym),
            is_raw: Mark::mark(unmarked.is_raw),
            span: Mark::mark(unmarked.span),
        }
    }
    #[inline]
    fn unmark(self) -> Self::Unmarked {
        Ident {
            sym: Mark::unmark(self.sym),
            is_raw: Mark::unmark(self.is_raw),
            span: Mark::unmark(self.span),
        }
    }
}compound_traits!(struct Ident<Span, Symbol> { sym, is_raw, span });
393
394#[derive(#[automatically_derived]
impl<Span: ::core::clone::Clone, Symbol: ::core::clone::Clone>
    ::core::clone::Clone for Literal<Span, Symbol> {
    #[inline]
    fn clone(&self) -> Literal<Span, Symbol> {
        Literal {
            kind: ::core::clone::Clone::clone(&self.kind),
            symbol: ::core::clone::Clone::clone(&self.symbol),
            suffix: ::core::clone::Clone::clone(&self.suffix),
            span: ::core::clone::Clone::clone(&self.span),
        }
    }
}Clone, #[automatically_derived]
impl<Span: ::core::cmp::Eq, Symbol: ::core::cmp::Eq> ::core::cmp::Eq for
    Literal<Span, Symbol> {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<LitKind>;
        let _: ::core::cmp::AssertParamIsEq<Symbol>;
        let _: ::core::cmp::AssertParamIsEq<Option<Symbol>>;
        let _: ::core::cmp::AssertParamIsEq<Span>;
    }
}Eq, #[automatically_derived]
impl<Span: ::core::cmp::PartialEq, Symbol: ::core::cmp::PartialEq>
    ::core::marker::StructuralPartialEq for Literal<Span, Symbol> {
}
#[automatically_derived]
impl<Span: ::core::cmp::PartialEq, Symbol: ::core::cmp::PartialEq>
    ::core::cmp::PartialEq for Literal<Span, Symbol> {
    #[inline]
    fn eq(&self, other: &Literal<Span, Symbol>) -> bool {
        self.kind == other.kind && self.symbol == other.symbol &&
                self.suffix == other.suffix && self.span == other.span
    }
}PartialEq)]
395pub struct Literal<Span, Symbol> {
396    pub kind: LitKind,
397    pub symbol: Symbol,
398    pub suffix: Option<Symbol>,
399    pub span: Span,
400}
401
402impl<S, Span: Encode<S>, Symbol: Encode<S>> Encode<S> for
    Literal<Span, Symbol> {
    fn encode(self, w: &mut Buffer, s: &mut S) {
        self.kind.encode(w, s);
        self.symbol.encode(w, s);
        self.suffix.encode(w, s);
        self.span.encode(w, s);
    }
}
impl<'a, S, Span: for<'s> Decode<'a, 's, S>,
    Symbol: for<'s> Decode<'a, 's, S>> Decode<'a, '_, S> for
    Literal<Span, Symbol> {
    #[inline]
    fn decode(r: &mut &'a [u8], s: &mut S) -> Self {
        Literal {
            kind: Decode::decode(r, s),
            symbol: Decode::decode(r, s),
            suffix: Decode::decode(r, s),
            span: Decode::decode(r, s),
        }
    }
}
impl<Span: Mark, Symbol: Mark> Mark for Literal<Span, Symbol> {
    type Unmarked = Literal<Span::Unmarked, Symbol::Unmarked>;
    #[inline]
    fn mark(unmarked: Self::Unmarked) -> Self {
        Literal {
            kind: Mark::mark(unmarked.kind),
            symbol: Mark::mark(unmarked.symbol),
            suffix: Mark::mark(unmarked.suffix),
            span: Mark::mark(unmarked.span),
        }
    }
    #[inline]
    fn unmark(self) -> Self::Unmarked {
        Literal {
            kind: Mark::unmark(self.kind),
            symbol: Mark::unmark(self.symbol),
            suffix: Mark::unmark(self.suffix),
            span: Mark::unmark(self.span),
        }
    }
}compound_traits!(struct Literal<Span, Symbol> { kind, symbol, suffix, span });
403
404#[derive(#[automatically_derived]
impl<TokenStream: ::core::clone::Clone, Span: ::core::clone::Clone,
    Symbol: ::core::clone::Clone> ::core::clone::Clone for
    TokenTree<TokenStream, Span, Symbol> {
    #[inline]
    fn clone(&self) -> TokenTree<TokenStream, Span, Symbol> {
        match self {
            TokenTree::Group(__self_0) =>
                TokenTree::Group(::core::clone::Clone::clone(__self_0)),
            TokenTree::Punct(__self_0) =>
                TokenTree::Punct(::core::clone::Clone::clone(__self_0)),
            TokenTree::Ident(__self_0) =>
                TokenTree::Ident(::core::clone::Clone::clone(__self_0)),
            TokenTree::Literal(__self_0) =>
                TokenTree::Literal(::core::clone::Clone::clone(__self_0)),
        }
    }
}Clone)]
405pub enum TokenTree<TokenStream, Span, Symbol> {
406    Group(Group<TokenStream, Span>),
407    Punct(Punct<Span>),
408    Ident(Ident<Span, Symbol>),
409    Literal(Literal<Span, Symbol>),
410}
411
412#[allow(non_upper_case_globals, non_camel_case_types)]
const _: () =
    {
        #[repr(u8)]
        enum Tag { Group, Punct, Ident, Literal, }
        const Group: u8 = Tag::Group as u8;
        const Punct: u8 = Tag::Punct as u8;
        const Ident: u8 = Tag::Ident as u8;
        const Literal: u8 = Tag::Literal as u8;
        impl<S, TokenStream: Encode<S>, Span: Encode<S>, Symbol: Encode<S>>
            Encode<S> for TokenTree<TokenStream, Span, Symbol> {
            #[inline]
            fn encode(self, w: &mut Buffer, s: &mut S) {
                match self {
                    TokenTree::Group(tt) => {
                        Group.encode(w, s);
                        tt.encode(w, s);
                    }
                    TokenTree::Punct(tt) => {
                        Punct.encode(w, s);
                        tt.encode(w, s);
                    }
                    TokenTree::Ident(tt) => {
                        Ident.encode(w, s);
                        tt.encode(w, s);
                    }
                    TokenTree::Literal(tt) => {
                        Literal.encode(w, s);
                        tt.encode(w, s);
                    }
                }
            }
        }
        impl<'a, S, TokenStream: for<'s> Decode<'a, 's, S>,
            Span: for<'s> Decode<'a, 's, S>,
            Symbol: for<'s> Decode<'a, 's, S>> Decode<'a, '_, S> for
            TokenTree<TokenStream, Span, Symbol> {
            #[inline]
            fn decode(r: &mut &'a [u8], s: &mut S) -> Self {
                match u8::decode(r, s) {
                    Group => {
                        let tt = Decode::decode(r, s);
                        TokenTree::Group(tt)
                    }
                    Punct => {
                        let tt = Decode::decode(r, s);
                        TokenTree::Punct(tt)
                    }
                    Ident => {
                        let tt = Decode::decode(r, s);
                        TokenTree::Ident(tt)
                    }
                    Literal => {
                        let tt = Decode::decode(r, s);
                        TokenTree::Literal(tt)
                    }
                    _ =>
                        ::core::panicking::panic("internal error: entered unreachable code"),
                }
            }
        }
    };
impl<TokenStream: Mark, Span: Mark, Symbol: Mark> Mark for
    TokenTree<TokenStream, Span, Symbol> {
    type Unmarked =
        TokenTree<TokenStream::Unmarked, Span::Unmarked, Symbol::Unmarked>;
    #[inline]
    fn mark(unmarked: Self::Unmarked) -> Self {
        match unmarked {
            TokenTree::Group(tt) => { TokenTree::Group(Mark::mark(tt)) }
            TokenTree::Punct(tt) => { TokenTree::Punct(Mark::mark(tt)) }
            TokenTree::Ident(tt) => { TokenTree::Ident(Mark::mark(tt)) }
            TokenTree::Literal(tt) => { TokenTree::Literal(Mark::mark(tt)) }
        }
    }
    #[inline]
    fn unmark(self) -> Self::Unmarked {
        match self {
            TokenTree::Group(tt) => { TokenTree::Group(Mark::unmark(tt)) }
            TokenTree::Punct(tt) => { TokenTree::Punct(Mark::unmark(tt)) }
            TokenTree::Ident(tt) => { TokenTree::Ident(Mark::unmark(tt)) }
            TokenTree::Literal(tt) => { TokenTree::Literal(Mark::unmark(tt)) }
        }
    }
}compound_traits!(
413    enum TokenTree<TokenStream, Span, Symbol> {
414        Group(tt),
415        Punct(tt),
416        Ident(tt),
417        Literal(tt),
418    }
419);
420
421#[derive(#[automatically_derived]
impl<Span: ::core::clone::Clone> ::core::clone::Clone for Diagnostic<Span> {
    #[inline]
    fn clone(&self) -> Diagnostic<Span> {
        Diagnostic {
            level: ::core::clone::Clone::clone(&self.level),
            message: ::core::clone::Clone::clone(&self.message),
            spans: ::core::clone::Clone::clone(&self.spans),
            children: ::core::clone::Clone::clone(&self.children),
        }
    }
}Clone, #[automatically_derived]
impl<Span: ::core::fmt::Debug> ::core::fmt::Debug for Diagnostic<Span> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field4_finish(f, "Diagnostic",
            "level", &self.level, "message", &self.message, "spans",
            &self.spans, "children", &&self.children)
    }
}Debug)]
422pub struct Diagnostic<Span> {
423    pub level: Level,
424    pub message: String,
425    pub spans: Vec<Span>,
426    pub children: Vec<Diagnostic<Span>>,
427}
428
429impl<S, Span: Encode<S>> Encode<S> for Diagnostic<Span> {
    fn encode(self, w: &mut Buffer, s: &mut S) {
        self.level.encode(w, s);
        self.message.encode(w, s);
        self.spans.encode(w, s);
        self.children.encode(w, s);
    }
}
impl<'a, S, Span: for<'s> Decode<'a, 's, S>> Decode<'a, '_, S> for
    Diagnostic<Span> {
    #[inline]
    fn decode(r: &mut &'a [u8], s: &mut S) -> Self {
        Diagnostic {
            level: Decode::decode(r, s),
            message: Decode::decode(r, s),
            spans: Decode::decode(r, s),
            children: Decode::decode(r, s),
        }
    }
}
impl<Span: Mark> Mark for Diagnostic<Span> {
    type Unmarked = Diagnostic<Span::Unmarked>;
    #[inline]
    fn mark(unmarked: Self::Unmarked) -> Self {
        Diagnostic {
            level: Mark::mark(unmarked.level),
            message: Mark::mark(unmarked.message),
            spans: Mark::mark(unmarked.spans),
            children: Mark::mark(unmarked.children),
        }
    }
    #[inline]
    fn unmark(self) -> Self::Unmarked {
        Diagnostic {
            level: Mark::unmark(self.level),
            message: Mark::unmark(self.message),
            spans: Mark::unmark(self.spans),
            children: Mark::unmark(self.children),
        }
    }
}compound_traits!(
430    struct Diagnostic<Span> { level, message, spans, children }
431);
432
433/// Globals provided alongside the initial inputs for a macro expansion.
434/// Provides values such as spans which are used frequently to avoid RPC.
435#[derive(#[automatically_derived]
impl<Span: ::core::clone::Clone> ::core::clone::Clone for ExpnGlobals<Span> {
    #[inline]
    fn clone(&self) -> ExpnGlobals<Span> {
        ExpnGlobals {
            def_site: ::core::clone::Clone::clone(&self.def_site),
            call_site: ::core::clone::Clone::clone(&self.call_site),
            mixed_site: ::core::clone::Clone::clone(&self.mixed_site),
        }
    }
}Clone)]
436pub struct ExpnGlobals<Span> {
437    pub def_site: Span,
438    pub call_site: Span,
439    pub mixed_site: Span,
440}
441
442impl<S, Span: Encode<S>> Encode<S> for ExpnGlobals<Span> {
    fn encode(self, w: &mut Buffer, s: &mut S) {
        self.def_site.encode(w, s);
        self.call_site.encode(w, s);
        self.mixed_site.encode(w, s);
    }
}
impl<'a, S, Span: for<'s> Decode<'a, 's, S>> Decode<'a, '_, S> for
    ExpnGlobals<Span> {
    #[inline]
    fn decode(r: &mut &'a [u8], s: &mut S) -> Self {
        ExpnGlobals {
            def_site: Decode::decode(r, s),
            call_site: Decode::decode(r, s),
            mixed_site: Decode::decode(r, s),
        }
    }
}
impl<Span: Mark> Mark for ExpnGlobals<Span> {
    type Unmarked = ExpnGlobals<Span::Unmarked>;
    #[inline]
    fn mark(unmarked: Self::Unmarked) -> Self {
        ExpnGlobals {
            def_site: Mark::mark(unmarked.def_site),
            call_site: Mark::mark(unmarked.call_site),
            mixed_site: Mark::mark(unmarked.mixed_site),
        }
    }
    #[inline]
    fn unmark(self) -> Self::Unmarked {
        ExpnGlobals {
            def_site: Mark::unmark(self.def_site),
            call_site: Mark::unmark(self.call_site),
            mixed_site: Mark::unmark(self.mixed_site),
        }
    }
}compound_traits!(
443    struct ExpnGlobals<Span> { def_site, call_site, mixed_site }
444);
445
446impl<S, T: Encode<S>> Encode<S> for Range<T> {
    fn encode(self, w: &mut Buffer, s: &mut S) {
        self.start.encode(w, s);
        self.end.encode(w, s);
    }
}
impl<'a, S, T: for<'s> Decode<'a, 's, S>> Decode<'a, '_, S> for Range<T> {
    #[inline]
    fn decode(r: &mut &'a [u8], s: &mut S) -> Self {
        Range { start: Decode::decode(r, s), end: Decode::decode(r, s) }
    }
}rpc_encode_decode!(
447    struct Range<T> { start, end }
448);