diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-12-22 17:42:04 -0500 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-12-22 17:42:47 -0500 |
| commit | a06baa56b95674fc626b3c3fd680d6a65357fe60 (patch) | |
| tree | cd9d867c2ca3cff5c1d6b3bd73377c44649fb075 /src/libproc_macro | |
| parent | 8eb7c58dbb7b32701af113bc58722d0d1fefb1eb (diff) | |
Format the world
Diffstat (limited to 'src/libproc_macro')
| -rw-r--r-- | src/libproc_macro/bridge/buffer.rs | 20 | ||||
| -rw-r--r-- | src/libproc_macro/bridge/client.rs | 34 | ||||
| -rw-r--r-- | src/libproc_macro/bridge/closure.rs | 5 | ||||
| -rw-r--r-- | src/libproc_macro/bridge/handle.rs | 22 | ||||
| -rw-r--r-- | src/libproc_macro/bridge/mod.rs | 7 | ||||
| -rw-r--r-- | src/libproc_macro/bridge/server.rs | 36 | ||||
| -rw-r--r-- | src/libproc_macro/diagnostic.rs | 15 | ||||
| -rw-r--r-- | src/libproc_macro/lib.rs | 58 |
8 files changed, 54 insertions, 143 deletions
diff --git a/src/libproc_macro/bridge/buffer.rs b/src/libproc_macro/bridge/buffer.rs index a51e3a9a33d..aeecbd49662 100644 --- a/src/libproc_macro/bridge/buffer.rs +++ b/src/libproc_macro/bridge/buffer.rs @@ -23,10 +23,7 @@ impl<T> Clone for Slice<'a, T> { impl<T> From<&'a [T]> for Slice<'a, T> { fn from(xs: &'a [T]) -> Self { - Slice { - data: unsafe { &*(xs.as_ptr() as *const [T; 0]) }, - len: xs.len(), - } + Slice { data: unsafe { &*(xs.as_ptr() as *const [T; 0]) }, len: xs.len() } } } @@ -128,12 +125,7 @@ impl<T: Copy> From<Vec<T>> for Buffer<T> { // be safely called on `Buffer`s created by *this* `proc_macro`. fn to_vec<T: Copy>(b: Buffer<T>) -> Vec<T> { unsafe { - let Buffer { - data, - len, - capacity, - .. - } = b; + let Buffer { data, len, capacity, .. } = b; mem::forget(b); Vec::from_raw_parts(data, len, capacity) } @@ -149,12 +141,6 @@ impl<T: Copy> From<Vec<T>> for Buffer<T> { mem::drop(to_vec(b)); } - Buffer { - data, - len, - capacity, - extend_from_slice, - drop, - } + Buffer { data, len, capacity, extend_from_slice, drop } } } diff --git a/src/libproc_macro/bridge/client.rs b/src/libproc_macro/bridge/client.rs index 9643dba997a..dd948025c91 100644 --- a/src/libproc_macro/bridge/client.rs +++ b/src/libproc_macro/bridge/client.rs @@ -393,17 +393,13 @@ impl Client<fn(crate::TokenStream) -> crate::TokenStream> { ) -> Buffer<u8> { run_client(bridge, |input| f(crate::TokenStream(input)).0) } - Client { - get_handle_counters: HandleCounters::get, - run, - f, - } + Client { get_handle_counters: HandleCounters::get, run, f } } } impl Client<fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream> { pub const fn expand2( - f: fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream + f: fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream, ) -> Self { extern "C" fn run( bridge: Bridge<'_>, @@ -413,11 +409,7 @@ impl Client<fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream> { f(crate::TokenStream(input), crate::TokenStream(input2)).0 }) } - Client { - get_handle_counters: HandleCounters::get, - run, - f, - } + Client { get_handle_counters: HandleCounters::get, run, f } } } @@ -446,7 +438,7 @@ impl ProcMacro { match self { ProcMacro::CustomDerive { trait_name, .. } => trait_name, ProcMacro::Attr { name, .. } => name, - ProcMacro::Bang { name, ..} => name + ProcMacro::Bang { name, .. } => name, } } @@ -455,30 +447,20 @@ impl ProcMacro { attributes: &'static [&'static str], expand: fn(crate::TokenStream) -> crate::TokenStream, ) -> Self { - ProcMacro::CustomDerive { - trait_name, - attributes, - client: Client::expand1(expand), - } + ProcMacro::CustomDerive { trait_name, attributes, client: Client::expand1(expand) } } pub const fn attr( name: &'static str, expand: fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream, ) -> Self { - ProcMacro::Attr { - name, - client: Client::expand2(expand), - } + ProcMacro::Attr { name, client: Client::expand2(expand) } } pub const fn bang( name: &'static str, - expand: fn(crate::TokenStream) -> crate::TokenStream + expand: fn(crate::TokenStream) -> crate::TokenStream, ) -> Self { - ProcMacro::Bang { - name, - client: Client::expand1(expand), - } + ProcMacro::Bang { name, client: Client::expand1(expand) } } } diff --git a/src/libproc_macro/bridge/closure.rs b/src/libproc_macro/bridge/closure.rs index 8d8adfa1caa..5bfe287d33a 100644 --- a/src/libproc_macro/bridge/closure.rs +++ b/src/libproc_macro/bridge/closure.rs @@ -18,10 +18,7 @@ impl<'a, A, R, F: FnMut(A) -> R> From<&'a mut F> for Closure<'a, A, R> { unsafe extern "C" fn call<A, R, F: FnMut(A) -> R>(env: &mut Env, arg: A) -> R { (*(env as *mut _ as *mut F))(arg) } - Closure { - call: call::<A, R, F>, - env: unsafe { &mut *(f as *mut _ as *mut Env) }, - } + Closure { call: call::<A, R, F>, env: unsafe { &mut *(f as *mut _ as *mut Env) } } } } diff --git a/src/libproc_macro/bridge/handle.rs b/src/libproc_macro/bridge/handle.rs index 66496ff3f1a..bcbb8681247 100644 --- a/src/libproc_macro/bridge/handle.rs +++ b/src/libproc_macro/bridge/handle.rs @@ -19,10 +19,7 @@ impl<T> OwnedStore<T> { // when `NonZeroU32::new` (aka `Handle::new`) is called in `alloc`. assert_ne!(counter.load(Ordering::SeqCst), 0); - OwnedStore { - counter, - data: BTreeMap::new(), - } + OwnedStore { counter, data: BTreeMap::new() } } } @@ -35,26 +32,20 @@ impl<T> OwnedStore<T> { } pub(super) fn take(&mut self, h: Handle) -> T { - self.data - .remove(&h) - .expect("use-after-free in `proc_macro` handle") + self.data.remove(&h).expect("use-after-free in `proc_macro` handle") } } impl<T> Index<Handle> for OwnedStore<T> { type Output = T; fn index(&self, h: Handle) -> &T { - self.data - .get(&h) - .expect("use-after-free in `proc_macro` handle") + self.data.get(&h).expect("use-after-free in `proc_macro` handle") } } impl<T> IndexMut<Handle> for OwnedStore<T> { fn index_mut(&mut self, h: Handle) -> &mut T { - self.data - .get_mut(&h) - .expect("use-after-free in `proc_macro` handle") + self.data.get_mut(&h).expect("use-after-free in `proc_macro` handle") } } @@ -65,10 +56,7 @@ pub(super) struct InternedStore<T: 'static> { impl<T: Copy + Eq + Hash> InternedStore<T> { pub(super) fn new(counter: &'static AtomicUsize) -> Self { - InternedStore { - owned: OwnedStore::new(counter), - interner: HashMap::new(), - } + InternedStore { owned: OwnedStore::new(counter), interner: HashMap::new() } } pub(super) fn alloc(&mut self, x: T) -> Handle { diff --git a/src/libproc_macro/bridge/mod.rs b/src/libproc_macro/bridge/mod.rs index c26b59f473c..a0e7d90f497 100644 --- a/src/libproc_macro/bridge/mod.rs +++ b/src/libproc_macro/bridge/mod.rs @@ -8,6 +8,7 @@ #![deny(unsafe_code)] +use crate::{Delimiter, Level, LineColumn, Spacing}; use std::fmt; use std::hash::Hash; use std::marker; @@ -17,7 +18,6 @@ use std::panic; use std::sync::atomic::AtomicUsize; use std::sync::Once; use std::thread; -use crate::{Delimiter, Level, LineColumn, Spacing}; /// Higher-order macro describing the server RPC API, allowing automatic /// generation of type-safe Rust APIs, both client-side and server-side. @@ -270,10 +270,7 @@ struct Marked<T, M> { impl<T, M> Mark for Marked<T, M> { type Unmarked = T; fn mark(unmarked: Self::Unmarked) -> Self { - Marked { - value: unmarked, - _marker: marker::PhantomData, - } + Marked { value: unmarked, _marker: marker::PhantomData } } } impl<T, M> Unmark for Marked<T, M> { diff --git a/src/libproc_macro/bridge/server.rs b/src/libproc_macro/bridge/server.rs index f303e3e8288..ca18d4459aa 100644 --- a/src/libproc_macro/bridge/server.rs +++ b/src/libproc_macro/bridge/server.rs @@ -148,13 +148,7 @@ impl ExecutionStrategy for SameThread { ) -> Buffer<u8> { let mut dispatch = |b| dispatcher.dispatch(b); - run_client( - Bridge { - cached_buffer: input, - dispatch: (&mut dispatch).into(), - }, - client_data, - ) + run_client(Bridge { cached_buffer: input, dispatch: (&mut dispatch).into() }, client_data) } } @@ -183,10 +177,7 @@ impl ExecutionStrategy for CrossThread1 { }; run_client( - Bridge { - cached_buffer: input, - dispatch: (&mut dispatch).into(), - }, + Bridge { cached_buffer: input, dispatch: (&mut dispatch).into() }, client_data, ) }); @@ -233,10 +224,7 @@ impl ExecutionStrategy for CrossThread2 { }; let r = run_client( - Bridge { - cached_buffer: input, - dispatch: (&mut dispatch).into(), - }, + Bridge { cached_buffer: input, dispatch: (&mut dispatch).into() }, client_data, ); @@ -276,10 +264,8 @@ fn run_server< run_client: extern "C" fn(Bridge<'_>, D) -> Buffer<u8>, client_data: D, ) -> Result<O, PanicMessage> { - let mut dispatcher = Dispatcher { - handle_store: HandleStore::new(handle_counters), - server: MarkedTypes(server), - }; + let mut dispatcher = + Dispatcher { handle_store: HandleStore::new(handle_counters), server: MarkedTypes(server) }; let mut b = Buffer::new(); input.encode(&mut b, &mut dispatcher.handle_store); @@ -296,11 +282,7 @@ impl client::Client<fn(crate::TokenStream) -> crate::TokenStream> { server: S, input: S::TokenStream, ) -> Result<S::TokenStream, PanicMessage> { - let client::Client { - get_handle_counters, - run, - f, - } = *self; + let client::Client { get_handle_counters, run, f } = *self; run_server( strategy, get_handle_counters(), @@ -321,11 +303,7 @@ impl client::Client<fn(crate::TokenStream, crate::TokenStream) -> crate::TokenSt input: S::TokenStream, input2: S::TokenStream, ) -> Result<S::TokenStream, PanicMessage> { - let client::Client { - get_handle_counters, - run, - f, - } = *self; + let client::Client { get_handle_counters, run, f } = *self; run_server( strategy, get_handle_counters(), diff --git a/src/libproc_macro/diagnostic.rs b/src/libproc_macro/diagnostic.rs index 65eebb5ec37..fdf252e5338 100644 --- a/src/libproc_macro/diagnostic.rs +++ b/src/libproc_macro/diagnostic.rs @@ -51,7 +51,7 @@ pub struct Diagnostic { level: Level, message: String, spans: Vec<Span>, - children: Vec<Diagnostic> + children: Vec<Diagnostic>, } macro_rules! diagnostic_child_methods { @@ -96,25 +96,22 @@ impl Diagnostic { /// Creates a new diagnostic with the given `level` and `message`. #[unstable(feature = "proc_macro_diagnostic", issue = "54140")] pub fn new<T: Into<String>>(level: Level, message: T) -> Diagnostic { - Diagnostic { - level: level, - message: message.into(), - spans: vec![], - children: vec![] - } + Diagnostic { level: level, message: message.into(), spans: vec![], children: vec![] } } /// Creates a new diagnostic with the given `level` and `message` pointing to /// the given set of `spans`. #[unstable(feature = "proc_macro_diagnostic", issue = "54140")] pub fn spanned<S, T>(spans: S, level: Level, message: T) -> Diagnostic - where S: MultiSpan, T: Into<String> + where + S: MultiSpan, + T: Into<String>, { Diagnostic { level: level, message: message.into(), spans: spans.into_spans(), - children: vec![] + children: vec![], } } diff --git a/src/libproc_macro/lib.rs b/src/libproc_macro/lib.rs index 87cd8fcb143..0b74a104da4 100644 --- a/src/libproc_macro/lib.rs +++ b/src/libproc_macro/lib.rs @@ -11,12 +11,13 @@ #![stable(feature = "proc_macro_lib", since = "1.15.0")] #![deny(missing_docs)] -#![doc(html_root_url = "https://doc.rust-lang.org/nightly/", - html_playground_url = "https://play.rust-lang.org/", - issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/", - test(no_crate_inject, attr(deny(warnings))), - test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))))] - +#![doc( + html_root_url = "https://doc.rust-lang.org/nightly/", + html_playground_url = "https://play.rust-lang.org/", + issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/", + test(no_crate_inject, attr(deny(warnings))), + test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))) +)] #![feature(nll)] #![feature(staged_api)] #![feature(allow_internal_unstable)] @@ -27,8 +28,7 @@ #![feature(optin_builtin_traits)] #![feature(rustc_attrs)] #![feature(specialization)] - -#![recursion_limit="256"] +#![recursion_limit = "256"] #[unstable(feature = "proc_macro_internals", issue = "27812")] #[doc(hidden)] @@ -39,10 +39,10 @@ mod diagnostic; #[unstable(feature = "proc_macro_diagnostic", issue = "54140")] pub use diagnostic::{Diagnostic, Level, MultiSpan}; -use std::{fmt, iter, mem}; use std::ops::{Bound, RangeBounds}; use std::path::PathBuf; use std::str::FromStr; +use std::{fmt, iter, mem}; /// The main type provided by this crate, representing an abstract stream of /// tokens, or, more specifically, a sequence of token trees. @@ -134,20 +134,20 @@ impl fmt::Debug for TokenStream { pub use quote::{quote, quote_span}; /// Creates a token stream containing a single token tree. - #[stable(feature = "proc_macro_lib2", since = "1.29.0")] +#[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl From<TokenTree> for TokenStream { fn from(tree: TokenTree) -> TokenStream { TokenStream(bridge::client::TokenStream::from_token_tree(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::Literal(tt) => bridge::TokenTree::Literal(tt.0), })) } } /// Collects a number of token trees into a single stream. - #[stable(feature = "proc_macro_lib2", since = "1.29.0")] +#[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl iter::FromIterator<TokenTree> for TokenStream { fn from_iter<I: IntoIterator<Item = TokenTree>>(trees: I) -> Self { trees.into_iter().map(TokenStream::from).collect() @@ -183,7 +183,7 @@ impl Extend<TokenStream> 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::{bridge, Group, Ident, Literal, Punct, TokenTree, TokenStream}; + use crate::{bridge, Group, Ident, Literal, Punct, TokenStream, TokenTree}; /// An iterator over `TokenStream`'s `TokenTree`s. /// The iteration is "shallow", e.g., the iterator doesn't recurse into delimited groups, @@ -226,7 +226,9 @@ pub mod token_stream { #[unstable(feature = "proc_macro_quote", issue = "54722")] #[allow_internal_unstable(proc_macro_def_site)] #[rustc_builtin_macro] -pub macro quote ($($t:tt)*) { /* compiler built-in */ } +pub macro quote($($t:tt)*) { + /* compiler built-in */ +} #[unstable(feature = "proc_macro_internals", issue = "27812")] #[doc(hidden)] @@ -375,7 +377,7 @@ pub struct LineColumn { /// The 0-indexed column (in UTF-8 characters) in the source file on which /// the span starts or ends (inclusive). #[unstable(feature = "proc_macro_span", issue = "54725")] - pub column: usize + pub column: usize, } #[unstable(feature = "proc_macro_span", issue = "54725")] @@ -415,7 +417,6 @@ impl SourceFile { } } - #[unstable(feature = "proc_macro_span", issue = "54725")] impl fmt::Debug for SourceFile { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -442,28 +443,16 @@ impl Eq for SourceFile {} pub enum TokenTree { /// A token stream surrounded by bracket delimiters. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] - Group( - #[stable(feature = "proc_macro_lib2", since = "1.29.0")] - Group - ), + Group(#[stable(feature = "proc_macro_lib2", since = "1.29.0")] Group), /// An identifier. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] - Ident( - #[stable(feature = "proc_macro_lib2", since = "1.29.0")] - Ident - ), + Ident(#[stable(feature = "proc_macro_lib2", since = "1.29.0")] Ident), /// A single punctuation character (`+`, `,`, `$`, etc.). #[stable(feature = "proc_macro_lib2", since = "1.29.0")] - Punct( - #[stable(feature = "proc_macro_lib2", since = "1.29.0")] - Punct - ), + Punct(#[stable(feature = "proc_macro_lib2", since = "1.29.0")] Punct), /// A literal character (`'a'`), string (`"hello"`), number (`2.3`), etc. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] - Literal( - #[stable(feature = "proc_macro_lib2", since = "1.29.0")] - Literal - ), + Literal(#[stable(feature = "proc_macro_lib2", since = "1.29.0")] Literal), } #[stable(feature = "proc_macro_lib2", since = "1.29.0")] @@ -1092,10 +1081,7 @@ impl Literal { } } - self.0.subspan( - cloned_bound(range.start_bound()), - cloned_bound(range.end_bound()), - ).map(Span) + self.0.subspan(cloned_bound(range.start_bound()), cloned_bound(range.end_bound())).map(Span) } } |
