Use ? in some macros

This commit is contained in:
Taiki Endo 2019-02-24 21:59:44 +09:00
parent 7f19f161f2
commit 871910a2c6
10 changed files with 29 additions and 29 deletions

View File

@ -326,7 +326,7 @@ pub enum Kind {
impl<'a> Builder<'a> {
fn get_step_descriptions(kind: Kind) -> Vec<StepDescription> {
macro_rules! describe {
($($rule:ty),+ $(,)*) => {{
($($rule:ty),+ $(,)?) => {{
vec![$(StepDescription::from::<$rule>()),+]
}};
}

View File

@ -222,8 +222,8 @@ impl fmt::Debug for Span {
macro_rules! define_client_side {
($($name:ident {
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)*) $(-> $ret_ty:ty)*;)*
}),* $(,)*) => {
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)*;)*
}),* $(,)?) => {
$(impl $name {
$(pub(crate) fn $method($($arg: $arg_ty),*) $(-> $ret_ty)* {
Bridge::with(|bridge| {

View File

@ -225,8 +225,8 @@ mod api_tags {
macro_rules! declare_tags {
($($name:ident {
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)*) $(-> $ret_ty:ty)*;)*
}),* $(,)*) => {
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)*;)*
}),* $(,)?) => {
$(
pub(super) enum $name {
$($method),*
@ -307,7 +307,7 @@ impl<T: Unmark> Unmark for Option<T> {
}
macro_rules! mark_noop {
($($ty:ty),* $(,)*) => {
($($ty:ty),* $(,)?) => {
$(
impl Mark for $ty {
type Unmarked = Self;

View File

@ -53,7 +53,7 @@ macro_rules! rpc_encode_decode {
}
}
};
(struct $name:ident { $($field:ident),* $(,)* }) => {
(struct $name:ident { $($field:ident),* $(,)? }) => {
impl<S> Encode<S> for $name {
fn encode(self, w: &mut Writer, s: &mut S) {
$(self.$field.encode(w, s);)*
@ -68,8 +68,8 @@ macro_rules! rpc_encode_decode {
}
}
};
(enum $name:ident $(<$($T:ident),+>)* { $($variant:ident $(($field:ident))*),* $(,)* }) => {
impl<S, $($($T: Encode<S>),+)*> Encode<S> for $name $(<$($T),+>)* {
(enum $name:ident $(<$($T:ident),+>)? { $($variant:ident $(($field:ident))*),* $(,)? }) => {
impl<S, $($($T: Encode<S>),+)?> Encode<S> for $name $(<$($T),+>)* {
fn encode(self, w: &mut Writer, s: &mut S) {
// HACK(eddyb): `Tag` enum duplicated between the
// two impls as there's no other place to stash it.

View File

@ -39,14 +39,14 @@ macro_rules! associated_item {
macro_rules! declare_server_traits {
($($name:ident {
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)*) $(-> $ret_ty:ty)*;)*
}),* $(,)*) => {
$(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_item!(fn $method(&mut self, $($arg: $arg_ty),*) $(-> $ret_ty)?);)*
})*
pub trait Server: Types $(+ $name)* {}
@ -59,14 +59,14 @@ pub(super) struct MarkedTypes<S: Types>(S);
macro_rules! define_mark_types_impls {
($($name:ident {
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)*) $(-> $ret_ty:ty)*;)*
}),* $(,)*) => {
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)?;)*
}),* $(,)?) => {
impl<S: Types> Types for MarkedTypes<S> {
$(type $name = Marked<S::$name, client::$name>;)*
}
$(impl<S: $name> $name for MarkedTypes<S> {
$(fn $method(&mut self, $($arg: $arg_ty),*) $(-> $ret_ty)* {
$(fn $method(&mut self, $($arg: $arg_ty),*) $(-> $ret_ty)? {
<_>::mark($name::$method(&mut self.0, $($arg.unmark()),*))
})*
})*
@ -81,8 +81,8 @@ struct Dispatcher<S: Types> {
macro_rules! define_dispatcher_impl {
($($name:ident {
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)*) $(-> $ret_ty:ty)*;)*
}),* $(,)*) => {
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)?;)*
}),* $(,)?) => {
// FIXME(eddyb) `pub` only for `ExecutionStrategy` below.
pub trait DispatcherTrait {
// HACK(eddyb) these are here to allow `Self::$name` to work below.

View File

@ -111,7 +111,7 @@ macro_rules! define_dep_nodes {
(<$tcx:tt>
$(
[$($attr:ident),* ]
$variant:ident $(( $tuple_arg_ty:ty $(,)* ))*
$variant:ident $(( $tuple_arg_ty:ty $(,)? ))*
$({ $($struct_arg_name:ident : $struct_arg_ty:ty),* })*
,)*
) => (

View File

@ -257,7 +257,7 @@ macro_rules! CloneTypeFoldableAndLiftImpls {
macro_rules! BraceStructLiftImpl {
(impl<$($p:tt),*> Lift<$tcx:tt> for $s:path {
type Lifted = $lifted:ty;
$($field:ident),* $(,)*
$($field:ident),* $(,)?
} $(where $($wc:tt)*)*) => {
impl<$($p),*> $crate::ty::Lift<$tcx> for $s
$(where $($wc)*)*
@ -327,7 +327,7 @@ macro_rules! EnumLiftImpl {
#[macro_export]
macro_rules! BraceStructTypeFoldableImpl {
(impl<$($p:tt),*> TypeFoldable<$tcx:tt> for $s:path {
$($field:ident),* $(,)*
$($field:ident),* $(,)?
} $(where $($wc:tt)*)*) => {
impl<$($p),*> $crate::ty::fold::TypeFoldable<$tcx> for $s
$(where $($wc)*)*
@ -354,7 +354,7 @@ macro_rules! BraceStructTypeFoldableImpl {
#[macro_export]
macro_rules! TupleStructTypeFoldableImpl {
(impl<$($p:tt),*> TypeFoldable<$tcx:tt> for $s:path {
$($field:ident),* $(,)*
$($field:ident),* $(,)?
} $(where $($wc:tt)*)*) => {
impl<$($p),*> $crate::ty::fold::TypeFoldable<$tcx> for $s
$(where $($wc)*)*
@ -426,7 +426,7 @@ macro_rules! EnumTypeFoldableImpl {
};
(@FoldVariants($this:expr, $folder:expr)
input( ($variant:path) { $($variant_arg:ident),* $(,)* } , $($input:tt)*)
input( ($variant:path) { $($variant_arg:ident),* $(,)? } , $($input:tt)*)
output( $($output:tt)*) ) => {
EnumTypeFoldableImpl!(
@FoldVariants($this, $folder)
@ -480,7 +480,7 @@ macro_rules! EnumTypeFoldableImpl {
};
(@VisitVariants($this:expr, $visitor:expr)
input( ($variant:path) { $($variant_arg:ident),* $(,)* } , $($input:tt)*)
input( ($variant:path) { $($variant_arg:ident),* $(,)? } , $($input:tt)*)
output( $($output:tt)*) ) => {
EnumTypeFoldableImpl!(
@VisitVariants($this, $visitor)

View File

@ -36,7 +36,7 @@ macro_rules! forward {
// Forward pattern for &self -> &Self
(
$(#[$attrs:meta])*
pub fn $n:ident(&self, $($name:ident: $ty:ty),* $(,)*) -> &Self
pub fn $n:ident(&self, $($name:ident: $ty:ty),* $(,)?) -> &Self
) => {
$(#[$attrs])*
pub fn $n(&self, $($name: $ty),*) -> &Self {
@ -48,7 +48,7 @@ macro_rules! forward {
// Forward pattern for &mut self -> &mut Self
(
$(#[$attrs:meta])*
pub fn $n:ident(&mut self, $($name:ident: $ty:ty),* $(,)*) -> &mut Self
pub fn $n:ident(&mut self, $($name:ident: $ty:ty),* $(,)?) -> &mut Self
) => {
$(#[$attrs])*
pub fn $n(&mut self, $($name: $ty),*) -> &mut Self {
@ -64,7 +64,7 @@ macro_rules! forward {
pub fn $n:ident<S: Into<MultiSpan>>(
&mut self,
$($name:ident: $ty:ty),*
$(,)*
$(,)?
) -> &mut Self
) => {
$(#[$attrs])*

View File

@ -431,7 +431,7 @@ mod test {
}
macro_rules! dummy_meta_item_list {
($name:ident, [$($list:ident),* $(,)*]) => {
($name:ident, [$($list:ident),* $(,)?]) => {
MetaItem {
ident: Path::from_ident(Ident::from_str(stringify!($name))),
node: MetaItemKind::List(vec![
@ -445,7 +445,7 @@ mod test {
}
};
($name:ident, [$($list:expr),* $(,)*]) => {
($name:ident, [$($list:expr),* $(,)?]) => {
MetaItem {
ident: Path::from_ident(Ident::from_str(stringify!($name))),
node: MetaItemKind::List(vec![

View File

@ -69,7 +69,7 @@ impl FromInternal<(TreeAndJoint, &'_ ParseSess, &'_ mut Vec<Self>)>
};
macro_rules! tt {
($ty:ident { $($field:ident $(: $value:expr)*),+ $(,)* }) => (
($ty:ident { $($field:ident $(: $value:expr)*),+ $(,)? }) => (
TokenTree::$ty(self::$ty {
$($field $(: $value)*,)*
span,