X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=library%2Fproc_macro%2Fsrc%2Flib.rs;h=911deaef8c97835e388503c328658eb16de0f212;hb=491fccfbe3561b0674a7dd13ac9f00820662aa59;hp=9ab5061c668078c06c8feaa27ab40ae79b31a85e;hpb=b04bfb4aea99436a62f6a98056e805eb9b0629cc;p=rust.git diff --git a/library/proc_macro/src/lib.rs b/library/proc_macro/src/lib.rs index 9ab5061c668..911deaef8c9 100644 --- a/library/proc_macro/src/lib.rs +++ b/library/proc_macro/src/lib.rs @@ -24,10 +24,14 @@ #![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")] @@ -214,7 +218,7 @@ fn tree_to_bridge_tree( ) -> bridge::TokenTree< bridge::client::TokenStream, bridge::client::Span, - bridge::client::Ident, + bridge::client::Symbol, bridge::client::Literal, > { match tree { @@ -240,7 +244,7 @@ struct ConcatTreesHelper { bridge::TokenTree< bridge::client::TokenStream, bridge::client::Span, - bridge::client::Ident, + bridge::client::Symbol, bridge::client::Literal, >, >, @@ -367,7 +371,7 @@ pub struct IntoIter( bridge::TokenTree< bridge::client::TokenStream, bridge::client::Span, - bridge::client::Ident, + bridge::client::Symbol, bridge::client::Literal, >, >, @@ -1004,6 +1008,13 @@ pub fn set_span(&mut self, span: Span) { } } +#[stable(feature = "proc_macro_lib2", since = "1.29.0")] +impl ToString for Punct { + fn to_string(&self) -> String { + self.as_char().to_string() + } +} + /// Prints the punctuation character as a string that should be losslessly convertible /// back into the same character. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] @@ -1041,7 +1052,7 @@ fn eq(&self, rhs: &Punct) -> bool { /// 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); impl Ident { /// Creates a new `Ident` with the given `string` as well as the specified @@ -1065,7 +1076,11 @@ 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::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`). @@ -1074,38 +1089,45 @@ pub fn new(string: &str, span: Span) -> 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) } }