From 41c10dde95b447b160a39ae2b7ebfd81faad5e0a Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 17 May 2022 07:42:57 +1000 Subject: [PATCH] Cut down `associated_item`. The part of it dealing with types obfuscates and makes the code less concise. This commit removes that part. --- library/proc_macro/src/bridge/server.rs | 38 ++++++++++++------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/library/proc_macro/src/bridge/server.rs b/library/proc_macro/src/bridge/server.rs index b15afa3298755..12c754682a0ef 100644 --- a/library/proc_macro/src/bridge/server.rs +++ b/library/proc_macro/src/bridge/server.rs @@ -5,22 +5,24 @@ use super::*; // FIXME(eddyb) generate the definition of `HandleStore` in `server.rs`. use super::client::HandleStore; -/// Declare an associated item of one of the traits below, optionally -/// adjusting it (i.e., adding bounds to types and default bodies to methods). -macro_rules! associated_item { - (type FreeFunctions) => (type FreeFunctions: 'static;); - (type TokenStream) => (type TokenStream: 'static + Clone;); - (type TokenStreamBuilder) => (type TokenStreamBuilder: 'static;); - (type TokenStreamIter) => (type TokenStreamIter: 'static + Clone;); - (type Group) => (type Group: 'static + Clone;); - (type Punct) => (type Punct: 'static + Copy + Eq + Hash;); - (type Ident) => (type Ident: 'static + Copy + Eq + Hash;); - (type Literal) => (type Literal: 'static + Clone;); - (type SourceFile) => (type SourceFile: 'static + Clone;); - (type MultiSpan) => (type MultiSpan: 'static;); - (type Diagnostic) => (type Diagnostic: 'static;); - (type Span) => (type Span: 'static + Copy + Eq + Hash;); +pub trait Types { + type FreeFunctions: 'static; + type TokenStream: 'static + Clone; + type TokenStreamBuilder: 'static; + type TokenStreamIter: 'static + Clone; + type Group: 'static + Clone; + type Punct: 'static + Copy + Eq + Hash; + type Ident: 'static + Copy + Eq + Hash; + type Literal: 'static + Clone; + type SourceFile: 'static + Clone; + type MultiSpan: 'static; + type Diagnostic: 'static; + type Span: 'static + Copy + Eq + Hash; +} +/// Declare an associated fn of one of the traits below, adding necessary +/// default bodies. +macro_rules! associated_fn { (fn drop(&mut self, $arg:ident: $arg_ty:ty)) => (fn drop(&mut self, $arg: $arg_ty) { mem::drop($arg) }); @@ -34,12 +36,8 @@ macro_rules! declare_server_traits { ($($name:ident { $(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)?;)* }),* $(,)?) => { - pub trait Types { - $(associated_item!(type $name);)* - } - $(pub trait $name: Types { - $(associated_item!(fn $method(&mut self, $($arg: $arg_ty),*) $(-> $ret_ty)?);)* + $(associated_fn!(fn $method(&mut self, $($arg: $arg_ty),*) $(-> $ret_ty)?);)* })* pub trait Server: Types $(+ $name)* {}