#![feature(staged_api)]
#![feature(allow_internal_unstable)]
#![feature(decl_macro)]
+#![feature(local_key_cell_methods)]
+#![feature(maybe_uninit_write_slice)]
#![feature(negative_impls)]
+#![feature(new_uninit)]
#![feature(restricted_std)]
#![feature(rustc_attrs)]
#![feature(min_specialization)]
+#![feature(strict_provenance)]
#![recursion_limit = "256"]
#[unstable(feature = "proc_macro_internals", issue = "27812")]
fn tree_to_bridge_tree(
tree: TokenTree,
) -> bridge::TokenTree<
- bridge::client::Group,
- bridge::client::Punct,
- bridge::client::Ident,
+ bridge::client::TokenStream,
+ bridge::client::Span,
+ bridge::client::Symbol,
bridge::client::Literal,
> {
match tree {
struct ConcatTreesHelper {
trees: Vec<
bridge::TokenTree<
- bridge::client::Group,
- bridge::client::Punct,
- bridge::client::Ident,
+ bridge::client::TokenStream,
+ bridge::client::Span,
+ bridge::client::Symbol,
bridge::client::Literal,
>,
>,
pub struct IntoIter(
std::vec::IntoIter<
bridge::TokenTree<
- bridge::client::Group,
- bridge::client::Punct,
- bridge::client::Ident,
+ bridge::client::TokenStream,
+ bridge::client::Span,
+ bridge::client::Symbol,
bridge::client::Literal,
>,
>,
/// 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::client::Group);
+pub struct Group(bridge::Group<bridge::client::TokenStream, bridge::client::Span>);
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
impl !Send for Group {}
/// method below.
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
pub fn new(delimiter: Delimiter, stream: TokenStream) -> Group {
- Group(bridge::client::Group::new(delimiter, stream.0))
+ Group(bridge::Group {
+ delimiter,
+ stream: stream.0,
+ span: bridge::DelimSpan::from_single(Span::call_site().0),
+ })
}
/// Returns the delimiter of this `Group`
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
pub fn delimiter(&self) -> Delimiter {
- self.0.delimiter()
+ self.0.delimiter
}
/// Returns the `TokenStream` of tokens that are delimited in this `Group`.
/// returned above.
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
pub fn stream(&self) -> TokenStream {
- TokenStream(Some(self.0.stream()))
+ TokenStream(self.0.stream.clone())
}
/// Returns the span for the delimiters of this token stream, spanning the
/// ```
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
pub fn span(&self) -> Span {
- Span(self.0.span())
+ Span(self.0.span.entire)
}
/// Returns the span pointing to the opening delimiter of this group.
/// ```
#[stable(feature = "proc_macro_group_span", since = "1.55.0")]
pub fn span_open(&self) -> Span {
- Span(self.0.span_open())
+ Span(self.0.span.open)
}
/// Returns the span pointing to the closing delimiter of this group.
/// ```
#[stable(feature = "proc_macro_group_span", since = "1.55.0")]
pub fn span_close(&self) -> Span {
- Span(self.0.span_close())
+ Span(self.0.span.close)
}
/// Configures the span for this `Group`'s delimiters, but not its internal
/// 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.set_span(span.0);
+ self.0.span = bridge::DelimSpan::from_single(span.0);
}
}
/// forms of `Spacing` returned.
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
#[derive(Clone)]
-pub struct Punct(bridge::client::Punct);
+pub struct Punct(bridge::Punct<bridge::client::Span>);
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
impl !Send for Punct {}
/// which can be further configured with the `set_span` method below.
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
pub fn new(ch: char, spacing: Spacing) -> Punct {
- Punct(bridge::client::Punct::new(ch, spacing))
+ const LEGAL_CHARS: &[char] = &[
+ '=', '<', '>', '!', '~', '+', '-', '*', '/', '%', '^', '&', '|', '@', '.', ',', ';',
+ ':', '#', '$', '?', '\'',
+ ];
+ if !LEGAL_CHARS.contains(&ch) {
+ panic!("unsupported character `{:?}`", ch);
+ }
+ Punct(bridge::Punct {
+ ch: ch as u8,
+ joint: spacing == Spacing::Joint,
+ span: Span::call_site().0,
+ })
}
/// Returns the value of this punctuation character as `char`.
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
pub fn as_char(&self) -> char {
- self.0.as_char()
+ self.0.ch as char
}
/// Returns the spacing of this punctuation character, indicating whether it's immediately
/// (`Alone`) so the operator has certainly ended.
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
pub fn spacing(&self) -> Spacing {
- self.0.spacing()
+ if self.0.joint { Spacing::Joint } else { Spacing::Alone }
}
/// Returns the span for this punctuation character.
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
pub fn span(&self) -> Span {
- Span(self.0.span())
+ Span(self.0.span)
}
/// Configure the span for this punctuation character.
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
pub fn set_span(&mut self, span: Span) {
- self.0 = self.0.with_span(span.0);
+ self.0.span = span.0;
}
}
-// N.B., the bridge only provides `to_string`, implement `fmt::Display`
-// based on it (the reverse of the usual relationship between the two).
-#[stable(feature = "proc_macro_lib", since = "1.15.0")]
+#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
impl ToString for Punct {
fn to_string(&self) -> String {
- TokenStream::from(TokenTree::from(self.clone())).to_string()
+ self.as_char().to_string()
}
}
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
impl fmt::Display for Punct {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- f.write_str(&self.to_string())
+ write!(f, "{}", self.as_char())
}
}
/// An identifier (`ident`).
#[derive(Clone)]
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
-pub struct Ident(bridge::client::Ident);
+pub struct Ident(bridge::Ident<bridge::client::Span, bridge::client::Symbol>);
impl Ident {
/// Creates a new `Ident` with the given `string` as well as the specified
/// 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::client::Ident::new(string, span.0, false))
+ Ident(bridge::Ident {
+ sym: bridge::client::Symbol::new_ident(string, false),
+ is_raw: false,
+ span: span.0,
+ })
}
/// Same as `Ident::new`, but creates a raw identifier (`r#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::client::Ident::new(string, span.0, true))
+ Ident(bridge::Ident {
+ sym: bridge::client::Symbol::new_ident(string, true),
+ is_raw: true,
+ span: span.0,
+ })
}
/// Returns the span of this `Ident`, encompassing the entire string returned
- /// by [`to_string`](Self::to_string).
+ /// by [`to_string`](ToString::to_string).
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
pub fn span(&self) -> Span {
- Span(self.0.span())
+ Span(self.0.span)
}
/// Configures the span of this `Ident`, possibly changing its hygiene context.
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
pub fn set_span(&mut self, span: Span) {
- self.0 = self.0.with_span(span.0);
+ self.0.span = span.0;
}
}
-// N.B., the bridge only provides `to_string`, implement `fmt::Display`
-// based on it (the reverse of the usual relationship between the two).
-#[stable(feature = "proc_macro_lib", since = "1.15.0")]
+/// Converts the identifier to a string that should be losslessly convertible
+/// back into the same identifier.
+#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
impl ToString for Ident {
fn to_string(&self) -> String {
- TokenStream::from(TokenTree::from(self.clone())).to_string()
+ self.0.sym.with(|sym| if self.0.is_raw { ["r#", sym].concat() } else { sym.to_owned() })
}
}
-/// Prints the identifier as a string that should be losslessly convertible
-/// back into the same identifier.
+/// Prints the identifier as a string that should be losslessly convertible back
+/// into the same identifier.
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
impl fmt::Display for Ident {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- f.write_str(&self.to_string())
+ if self.0.is_raw {
+ f.write_str("r#")?;
+ }
+ fmt::Display::fmt(&self.0.sym, f)
}
}