#![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")]
) -> bridge::TokenTree<
bridge::client::TokenStream,
bridge::client::Span,
- bridge::client::Ident,
+ bridge::client::Symbol,
bridge::client::Literal,
> {
match tree {
bridge::TokenTree<
bridge::client::TokenStream,
bridge::client::Span,
- bridge::client::Ident,
+ bridge::client::Symbol,
bridge::client::Literal,
>,
>,
bridge::TokenTree<
bridge::client::TokenStream,
bridge::client::Span,
- bridge::client::Ident,
+ bridge::client::Symbol,
bridge::client::Literal,
>,
>,
/// 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)
}
}