Use ? in some macros
This commit is contained in:
parent
7f19f161f2
commit
871910a2c6
10 changed files with 29 additions and 29 deletions
|
@ -326,7 +326,7 @@ pub enum Kind {
|
||||||
impl<'a> Builder<'a> {
|
impl<'a> Builder<'a> {
|
||||||
fn get_step_descriptions(kind: Kind) -> Vec<StepDescription> {
|
fn get_step_descriptions(kind: Kind) -> Vec<StepDescription> {
|
||||||
macro_rules! describe {
|
macro_rules! describe {
|
||||||
($($rule:ty),+ $(,)*) => {{
|
($($rule:ty),+ $(,)?) => {{
|
||||||
vec![$(StepDescription::from::<$rule>()),+]
|
vec![$(StepDescription::from::<$rule>()),+]
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,8 +222,8 @@ impl fmt::Debug for Span {
|
||||||
|
|
||||||
macro_rules! define_client_side {
|
macro_rules! define_client_side {
|
||||||
($($name:ident {
|
($($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 {
|
$(impl $name {
|
||||||
$(pub(crate) fn $method($($arg: $arg_ty),*) $(-> $ret_ty)* {
|
$(pub(crate) fn $method($($arg: $arg_ty),*) $(-> $ret_ty)* {
|
||||||
Bridge::with(|bridge| {
|
Bridge::with(|bridge| {
|
||||||
|
|
|
@ -225,8 +225,8 @@ mod api_tags {
|
||||||
|
|
||||||
macro_rules! declare_tags {
|
macro_rules! declare_tags {
|
||||||
($($name:ident {
|
($($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 {
|
pub(super) enum $name {
|
||||||
$($method),*
|
$($method),*
|
||||||
|
@ -307,7 +307,7 @@ impl<T: Unmark> Unmark for Option<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! mark_noop {
|
macro_rules! mark_noop {
|
||||||
($($ty:ty),* $(,)*) => {
|
($($ty:ty),* $(,)?) => {
|
||||||
$(
|
$(
|
||||||
impl Mark for $ty {
|
impl Mark for $ty {
|
||||||
type Unmarked = Self;
|
type Unmarked = Self;
|
||||||
|
|
|
@ -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 {
|
impl<S> Encode<S> for $name {
|
||||||
fn encode(self, w: &mut Writer, s: &mut S) {
|
fn encode(self, w: &mut Writer, s: &mut S) {
|
||||||
$(self.$field.encode(w, s);)*
|
$(self.$field.encode(w, s);)*
|
||||||
|
@ -68,8 +68,8 @@ macro_rules! rpc_encode_decode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
(enum $name:ident $(<$($T:ident),+>)* { $($variant:ident $(($field:ident))*),* $(,)* }) => {
|
(enum $name:ident $(<$($T:ident),+>)? { $($variant:ident $(($field:ident))*),* $(,)? }) => {
|
||||||
impl<S, $($($T: Encode<S>),+)*> Encode<S> for $name $(<$($T),+>)* {
|
impl<S, $($($T: Encode<S>),+)?> Encode<S> for $name $(<$($T),+>)* {
|
||||||
fn encode(self, w: &mut Writer, s: &mut S) {
|
fn encode(self, w: &mut Writer, s: &mut S) {
|
||||||
// HACK(eddyb): `Tag` enum duplicated between the
|
// HACK(eddyb): `Tag` enum duplicated between the
|
||||||
// two impls as there's no other place to stash it.
|
// two impls as there's no other place to stash it.
|
||||||
|
|
|
@ -39,14 +39,14 @@ macro_rules! associated_item {
|
||||||
|
|
||||||
macro_rules! declare_server_traits {
|
macro_rules! declare_server_traits {
|
||||||
($($name:ident {
|
($($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 {
|
pub trait Types {
|
||||||
$(associated_item!(type $name);)*
|
$(associated_item!(type $name);)*
|
||||||
}
|
}
|
||||||
|
|
||||||
$(pub trait $name: Types {
|
$(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)* {}
|
pub trait Server: Types $(+ $name)* {}
|
||||||
|
@ -59,14 +59,14 @@ pub(super) struct MarkedTypes<S: Types>(S);
|
||||||
|
|
||||||
macro_rules! define_mark_types_impls {
|
macro_rules! define_mark_types_impls {
|
||||||
($($name:ident {
|
($($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> {
|
impl<S: Types> Types for MarkedTypes<S> {
|
||||||
$(type $name = Marked<S::$name, client::$name>;)*
|
$(type $name = Marked<S::$name, client::$name>;)*
|
||||||
}
|
}
|
||||||
|
|
||||||
$(impl<S: $name> $name for MarkedTypes<S> {
|
$(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()),*))
|
<_>::mark($name::$method(&mut self.0, $($arg.unmark()),*))
|
||||||
})*
|
})*
|
||||||
})*
|
})*
|
||||||
|
@ -81,8 +81,8 @@ struct Dispatcher<S: Types> {
|
||||||
|
|
||||||
macro_rules! define_dispatcher_impl {
|
macro_rules! define_dispatcher_impl {
|
||||||
($($name:ident {
|
($($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.
|
// FIXME(eddyb) `pub` only for `ExecutionStrategy` below.
|
||||||
pub trait DispatcherTrait {
|
pub trait DispatcherTrait {
|
||||||
// HACK(eddyb) these are here to allow `Self::$name` to work below.
|
// HACK(eddyb) these are here to allow `Self::$name` to work below.
|
||||||
|
|
|
@ -111,7 +111,7 @@ macro_rules! define_dep_nodes {
|
||||||
(<$tcx:tt>
|
(<$tcx:tt>
|
||||||
$(
|
$(
|
||||||
[$($attr:ident),* ]
|
[$($attr:ident),* ]
|
||||||
$variant:ident $(( $tuple_arg_ty:ty $(,)* ))*
|
$variant:ident $(( $tuple_arg_ty:ty $(,)? ))*
|
||||||
$({ $($struct_arg_name:ident : $struct_arg_ty:ty),* })*
|
$({ $($struct_arg_name:ident : $struct_arg_ty:ty),* })*
|
||||||
,)*
|
,)*
|
||||||
) => (
|
) => (
|
||||||
|
|
|
@ -257,7 +257,7 @@ macro_rules! CloneTypeFoldableAndLiftImpls {
|
||||||
macro_rules! BraceStructLiftImpl {
|
macro_rules! BraceStructLiftImpl {
|
||||||
(impl<$($p:tt),*> Lift<$tcx:tt> for $s:path {
|
(impl<$($p:tt),*> Lift<$tcx:tt> for $s:path {
|
||||||
type Lifted = $lifted:ty;
|
type Lifted = $lifted:ty;
|
||||||
$($field:ident),* $(,)*
|
$($field:ident),* $(,)?
|
||||||
} $(where $($wc:tt)*)*) => {
|
} $(where $($wc:tt)*)*) => {
|
||||||
impl<$($p),*> $crate::ty::Lift<$tcx> for $s
|
impl<$($p),*> $crate::ty::Lift<$tcx> for $s
|
||||||
$(where $($wc)*)*
|
$(where $($wc)*)*
|
||||||
|
@ -327,7 +327,7 @@ macro_rules! EnumLiftImpl {
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! BraceStructTypeFoldableImpl {
|
macro_rules! BraceStructTypeFoldableImpl {
|
||||||
(impl<$($p:tt),*> TypeFoldable<$tcx:tt> for $s:path {
|
(impl<$($p:tt),*> TypeFoldable<$tcx:tt> for $s:path {
|
||||||
$($field:ident),* $(,)*
|
$($field:ident),* $(,)?
|
||||||
} $(where $($wc:tt)*)*) => {
|
} $(where $($wc:tt)*)*) => {
|
||||||
impl<$($p),*> $crate::ty::fold::TypeFoldable<$tcx> for $s
|
impl<$($p),*> $crate::ty::fold::TypeFoldable<$tcx> for $s
|
||||||
$(where $($wc)*)*
|
$(where $($wc)*)*
|
||||||
|
@ -354,7 +354,7 @@ macro_rules! BraceStructTypeFoldableImpl {
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! TupleStructTypeFoldableImpl {
|
macro_rules! TupleStructTypeFoldableImpl {
|
||||||
(impl<$($p:tt),*> TypeFoldable<$tcx:tt> for $s:path {
|
(impl<$($p:tt),*> TypeFoldable<$tcx:tt> for $s:path {
|
||||||
$($field:ident),* $(,)*
|
$($field:ident),* $(,)?
|
||||||
} $(where $($wc:tt)*)*) => {
|
} $(where $($wc:tt)*)*) => {
|
||||||
impl<$($p),*> $crate::ty::fold::TypeFoldable<$tcx> for $s
|
impl<$($p),*> $crate::ty::fold::TypeFoldable<$tcx> for $s
|
||||||
$(where $($wc)*)*
|
$(where $($wc)*)*
|
||||||
|
@ -426,7 +426,7 @@ macro_rules! EnumTypeFoldableImpl {
|
||||||
};
|
};
|
||||||
|
|
||||||
(@FoldVariants($this:expr, $folder:expr)
|
(@FoldVariants($this:expr, $folder:expr)
|
||||||
input( ($variant:path) { $($variant_arg:ident),* $(,)* } , $($input:tt)*)
|
input( ($variant:path) { $($variant_arg:ident),* $(,)? } , $($input:tt)*)
|
||||||
output( $($output:tt)*) ) => {
|
output( $($output:tt)*) ) => {
|
||||||
EnumTypeFoldableImpl!(
|
EnumTypeFoldableImpl!(
|
||||||
@FoldVariants($this, $folder)
|
@FoldVariants($this, $folder)
|
||||||
|
@ -480,7 +480,7 @@ macro_rules! EnumTypeFoldableImpl {
|
||||||
};
|
};
|
||||||
|
|
||||||
(@VisitVariants($this:expr, $visitor:expr)
|
(@VisitVariants($this:expr, $visitor:expr)
|
||||||
input( ($variant:path) { $($variant_arg:ident),* $(,)* } , $($input:tt)*)
|
input( ($variant:path) { $($variant_arg:ident),* $(,)? } , $($input:tt)*)
|
||||||
output( $($output:tt)*) ) => {
|
output( $($output:tt)*) ) => {
|
||||||
EnumTypeFoldableImpl!(
|
EnumTypeFoldableImpl!(
|
||||||
@VisitVariants($this, $visitor)
|
@VisitVariants($this, $visitor)
|
||||||
|
|
|
@ -36,7 +36,7 @@ macro_rules! forward {
|
||||||
// Forward pattern for &self -> &Self
|
// Forward pattern for &self -> &Self
|
||||||
(
|
(
|
||||||
$(#[$attrs:meta])*
|
$(#[$attrs:meta])*
|
||||||
pub fn $n:ident(&self, $($name:ident: $ty:ty),* $(,)*) -> &Self
|
pub fn $n:ident(&self, $($name:ident: $ty:ty),* $(,)?) -> &Self
|
||||||
) => {
|
) => {
|
||||||
$(#[$attrs])*
|
$(#[$attrs])*
|
||||||
pub fn $n(&self, $($name: $ty),*) -> &Self {
|
pub fn $n(&self, $($name: $ty),*) -> &Self {
|
||||||
|
@ -48,7 +48,7 @@ macro_rules! forward {
|
||||||
// Forward pattern for &mut self -> &mut Self
|
// Forward pattern for &mut self -> &mut Self
|
||||||
(
|
(
|
||||||
$(#[$attrs:meta])*
|
$(#[$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])*
|
$(#[$attrs])*
|
||||||
pub fn $n(&mut self, $($name: $ty),*) -> &mut Self {
|
pub fn $n(&mut self, $($name: $ty),*) -> &mut Self {
|
||||||
|
@ -64,7 +64,7 @@ macro_rules! forward {
|
||||||
pub fn $n:ident<S: Into<MultiSpan>>(
|
pub fn $n:ident<S: Into<MultiSpan>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
$($name:ident: $ty:ty),*
|
$($name:ident: $ty:ty),*
|
||||||
$(,)*
|
$(,)?
|
||||||
) -> &mut Self
|
) -> &mut Self
|
||||||
) => {
|
) => {
|
||||||
$(#[$attrs])*
|
$(#[$attrs])*
|
||||||
|
|
|
@ -431,7 +431,7 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! dummy_meta_item_list {
|
macro_rules! dummy_meta_item_list {
|
||||||
($name:ident, [$($list:ident),* $(,)*]) => {
|
($name:ident, [$($list:ident),* $(,)?]) => {
|
||||||
MetaItem {
|
MetaItem {
|
||||||
ident: Path::from_ident(Ident::from_str(stringify!($name))),
|
ident: Path::from_ident(Ident::from_str(stringify!($name))),
|
||||||
node: MetaItemKind::List(vec![
|
node: MetaItemKind::List(vec![
|
||||||
|
@ -445,7 +445,7 @@ mod test {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
($name:ident, [$($list:expr),* $(,)*]) => {
|
($name:ident, [$($list:expr),* $(,)?]) => {
|
||||||
MetaItem {
|
MetaItem {
|
||||||
ident: Path::from_ident(Ident::from_str(stringify!($name))),
|
ident: Path::from_ident(Ident::from_str(stringify!($name))),
|
||||||
node: MetaItemKind::List(vec![
|
node: MetaItemKind::List(vec![
|
||||||
|
|
|
@ -69,7 +69,7 @@ impl FromInternal<(TreeAndJoint, &'_ ParseSess, &'_ mut Vec<Self>)>
|
||||||
};
|
};
|
||||||
|
|
||||||
macro_rules! tt {
|
macro_rules! tt {
|
||||||
($ty:ident { $($field:ident $(: $value:expr)*),+ $(,)* }) => (
|
($ty:ident { $($field:ident $(: $value:expr)*),+ $(,)? }) => (
|
||||||
TokenTree::$ty(self::$ty {
|
TokenTree::$ty(self::$ty {
|
||||||
$($field $(: $value)*,)*
|
$($field $(: $value)*,)*
|
||||||
span,
|
span,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue