Skip to content

Commit b5cf4ea

Browse files
authored
Rollup merge of rust-lang#58697 - taiki-e:question-in-macros, r=Centril
Use ? in some macros
2 parents ed73ec0 + 871910a commit b5cf4ea

File tree

10 files changed

+29
-29
lines changed

10 files changed

+29
-29
lines changed

src/bootstrap/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ pub enum Kind {
326326
impl<'a> Builder<'a> {
327327
fn get_step_descriptions(kind: Kind) -> Vec<StepDescription> {
328328
macro_rules! describe {
329-
($($rule:ty),+ $(,)*) => {{
329+
($($rule:ty),+ $(,)?) => {{
330330
vec![$(StepDescription::from::<$rule>()),+]
331331
}};
332332
}

src/libproc_macro/bridge/client.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ impl fmt::Debug for Span {
222222

223223
macro_rules! define_client_side {
224224
($($name:ident {
225-
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)*) $(-> $ret_ty:ty)*;)*
226-
}),* $(,)*) => {
225+
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)*;)*
226+
}),* $(,)?) => {
227227
$(impl $name {
228228
$(pub(crate) fn $method($($arg: $arg_ty),*) $(-> $ret_ty)* {
229229
Bridge::with(|bridge| {

src/libproc_macro/bridge/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ mod api_tags {
225225

226226
macro_rules! declare_tags {
227227
($($name:ident {
228-
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)*) $(-> $ret_ty:ty)*;)*
229-
}),* $(,)*) => {
228+
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)*;)*
229+
}),* $(,)?) => {
230230
$(
231231
pub(super) enum $name {
232232
$($method),*
@@ -307,7 +307,7 @@ impl<T: Unmark> Unmark for Option<T> {
307307
}
308308

309309
macro_rules! mark_noop {
310-
($($ty:ty),* $(,)*) => {
310+
($($ty:ty),* $(,)?) => {
311311
$(
312312
impl Mark for $ty {
313313
type Unmarked = Self;

src/libproc_macro/bridge/rpc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ macro_rules! rpc_encode_decode {
5353
}
5454
}
5555
};
56-
(struct $name:ident { $($field:ident),* $(,)* }) => {
56+
(struct $name:ident { $($field:ident),* $(,)? }) => {
5757
impl<S> Encode<S> for $name {
5858
fn encode(self, w: &mut Writer, s: &mut S) {
5959
$(self.$field.encode(w, s);)*
@@ -68,8 +68,8 @@ macro_rules! rpc_encode_decode {
6868
}
6969
}
7070
};
71-
(enum $name:ident $(<$($T:ident),+>)* { $($variant:ident $(($field:ident))*),* $(,)* }) => {
72-
impl<S, $($($T: Encode<S>),+)*> Encode<S> for $name $(<$($T),+>)* {
71+
(enum $name:ident $(<$($T:ident),+>)? { $($variant:ident $(($field:ident))*),* $(,)? }) => {
72+
impl<S, $($($T: Encode<S>),+)?> Encode<S> for $name $(<$($T),+>)* {
7373
fn encode(self, w: &mut Writer, s: &mut S) {
7474
// HACK(eddyb): `Tag` enum duplicated between the
7575
// two impls as there's no other place to stash it.

src/libproc_macro/bridge/server.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ macro_rules! associated_item {
3939

4040
macro_rules! declare_server_traits {
4141
($($name:ident {
42-
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)*) $(-> $ret_ty:ty)*;)*
43-
}),* $(,)*) => {
42+
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)?;)*
43+
}),* $(,)?) => {
4444
pub trait Types {
4545
$(associated_item!(type $name);)*
4646
}
4747

4848
$(pub trait $name: Types {
49-
$(associated_item!(fn $method(&mut self, $($arg: $arg_ty),*) $(-> $ret_ty)*);)*
49+
$(associated_item!(fn $method(&mut self, $($arg: $arg_ty),*) $(-> $ret_ty)?);)*
5050
})*
5151

5252
pub trait Server: Types $(+ $name)* {}
@@ -59,14 +59,14 @@ pub(super) struct MarkedTypes<S: Types>(S);
5959

6060
macro_rules! define_mark_types_impls {
6161
($($name:ident {
62-
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)*) $(-> $ret_ty:ty)*;)*
63-
}),* $(,)*) => {
62+
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)?;)*
63+
}),* $(,)?) => {
6464
impl<S: Types> Types for MarkedTypes<S> {
6565
$(type $name = Marked<S::$name, client::$name>;)*
6666
}
6767

6868
$(impl<S: $name> $name for MarkedTypes<S> {
69-
$(fn $method(&mut self, $($arg: $arg_ty),*) $(-> $ret_ty)* {
69+
$(fn $method(&mut self, $($arg: $arg_ty),*) $(-> $ret_ty)? {
7070
<_>::mark($name::$method(&mut self.0, $($arg.unmark()),*))
7171
})*
7272
})*
@@ -81,8 +81,8 @@ struct Dispatcher<S: Types> {
8181

8282
macro_rules! define_dispatcher_impl {
8383
($($name:ident {
84-
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)*) $(-> $ret_ty:ty)*;)*
85-
}),* $(,)*) => {
84+
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)?;)*
85+
}),* $(,)?) => {
8686
// FIXME(eddyb) `pub` only for `ExecutionStrategy` below.
8787
pub trait DispatcherTrait {
8888
// HACK(eddyb) these are here to allow `Self::$name` to work below.

src/librustc/dep_graph/dep_node.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ macro_rules! define_dep_nodes {
111111
(<$tcx:tt>
112112
$(
113113
[$($attr:ident),* ]
114-
$variant:ident $(( $tuple_arg_ty:ty $(,)* ))*
114+
$variant:ident $(( $tuple_arg_ty:ty $(,)? ))*
115115
$({ $($struct_arg_name:ident : $struct_arg_ty:ty),* })*
116116
,)*
117117
) => (

src/librustc/macros.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ macro_rules! CloneTypeFoldableAndLiftImpls {
257257
macro_rules! BraceStructLiftImpl {
258258
(impl<$($p:tt),*> Lift<$tcx:tt> for $s:path {
259259
type Lifted = $lifted:ty;
260-
$($field:ident),* $(,)*
260+
$($field:ident),* $(,)?
261261
} $(where $($wc:tt)*)*) => {
262262
impl<$($p),*> $crate::ty::Lift<$tcx> for $s
263263
$(where $($wc)*)*
@@ -327,7 +327,7 @@ macro_rules! EnumLiftImpl {
327327
#[macro_export]
328328
macro_rules! BraceStructTypeFoldableImpl {
329329
(impl<$($p:tt),*> TypeFoldable<$tcx:tt> for $s:path {
330-
$($field:ident),* $(,)*
330+
$($field:ident),* $(,)?
331331
} $(where $($wc:tt)*)*) => {
332332
impl<$($p),*> $crate::ty::fold::TypeFoldable<$tcx> for $s
333333
$(where $($wc)*)*
@@ -354,7 +354,7 @@ macro_rules! BraceStructTypeFoldableImpl {
354354
#[macro_export]
355355
macro_rules! TupleStructTypeFoldableImpl {
356356
(impl<$($p:tt),*> TypeFoldable<$tcx:tt> for $s:path {
357-
$($field:ident),* $(,)*
357+
$($field:ident),* $(,)?
358358
} $(where $($wc:tt)*)*) => {
359359
impl<$($p),*> $crate::ty::fold::TypeFoldable<$tcx> for $s
360360
$(where $($wc)*)*
@@ -426,7 +426,7 @@ macro_rules! EnumTypeFoldableImpl {
426426
};
427427

428428
(@FoldVariants($this:expr, $folder:expr)
429-
input( ($variant:path) { $($variant_arg:ident),* $(,)* } , $($input:tt)*)
429+
input( ($variant:path) { $($variant_arg:ident),* $(,)? } , $($input:tt)*)
430430
output( $($output:tt)*) ) => {
431431
EnumTypeFoldableImpl!(
432432
@FoldVariants($this, $folder)
@@ -480,7 +480,7 @@ macro_rules! EnumTypeFoldableImpl {
480480
};
481481

482482
(@VisitVariants($this:expr, $visitor:expr)
483-
input( ($variant:path) { $($variant_arg:ident),* $(,)* } , $($input:tt)*)
483+
input( ($variant:path) { $($variant_arg:ident),* $(,)? } , $($input:tt)*)
484484
output( $($output:tt)*) ) => {
485485
EnumTypeFoldableImpl!(
486486
@VisitVariants($this, $visitor)

src/librustc_errors/diagnostic_builder.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ macro_rules! forward {
3636
// Forward pattern for &self -> &Self
3737
(
3838
$(#[$attrs:meta])*
39-
pub fn $n:ident(&self, $($name:ident: $ty:ty),* $(,)*) -> &Self
39+
pub fn $n:ident(&self, $($name:ident: $ty:ty),* $(,)?) -> &Self
4040
) => {
4141
$(#[$attrs])*
4242
pub fn $n(&self, $($name: $ty),*) -> &Self {
@@ -48,7 +48,7 @@ macro_rules! forward {
4848
// Forward pattern for &mut self -> &mut Self
4949
(
5050
$(#[$attrs:meta])*
51-
pub fn $n:ident(&mut self, $($name:ident: $ty:ty),* $(,)*) -> &mut Self
51+
pub fn $n:ident(&mut self, $($name:ident: $ty:ty),* $(,)?) -> &mut Self
5252
) => {
5353
$(#[$attrs])*
5454
pub fn $n(&mut self, $($name: $ty),*) -> &mut Self {
@@ -64,7 +64,7 @@ macro_rules! forward {
6464
pub fn $n:ident<S: Into<MultiSpan>>(
6565
&mut self,
6666
$($name:ident: $ty:ty),*
67-
$(,)*
67+
$(,)?
6868
) -> &mut Self
6969
) => {
7070
$(#[$attrs])*

src/librustdoc/clean/cfg.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ mod test {
431431
}
432432

433433
macro_rules! dummy_meta_item_list {
434-
($name:ident, [$($list:ident),* $(,)*]) => {
434+
($name:ident, [$($list:ident),* $(,)?]) => {
435435
MetaItem {
436436
ident: Path::from_ident(Ident::from_str(stringify!($name))),
437437
node: MetaItemKind::List(vec![
@@ -445,7 +445,7 @@ mod test {
445445
}
446446
};
447447

448-
($name:ident, [$($list:expr),* $(,)*]) => {
448+
($name:ident, [$($list:expr),* $(,)?]) => {
449449
MetaItem {
450450
ident: Path::from_ident(Ident::from_str(stringify!($name))),
451451
node: MetaItemKind::List(vec![

src/libsyntax_ext/proc_macro_server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl FromInternal<(TreeAndJoint, &'_ ParseSess, &'_ mut Vec<Self>)>
6969
};
7070

7171
macro_rules! tt {
72-
($ty:ident { $($field:ident $(: $value:expr)*),+ $(,)* }) => (
72+
($ty:ident { $($field:ident $(: $value:expr)*),+ $(,)? }) => (
7373
TokenTree::$ty(self::$ty {
7474
$($field $(: $value)*,)*
7575
span,

0 commit comments

Comments
 (0)