Skip to content

Commit c029e40

Browse files
authored
Rollup merge of rust-lang#58313 - matthewjasper:use-question-in-macros, r=oli-obk
Use `?` in librustc macros
2 parents 14bd021 + 0a16b87 commit c029e40

File tree

2 files changed

+246
-260
lines changed

2 files changed

+246
-260
lines changed

src/librustc/macros.rs

+26-30
Original file line numberDiff line numberDiff line change
@@ -62,38 +62,36 @@ macro_rules! __impl_stable_hash_field {
6262
#[macro_export]
6363
macro_rules! impl_stable_hash_for {
6464
// Enums
65-
// FIXME(mark-i-m): Some of these should be `?` rather than `*`. See the git blame and change
66-
// them back when `?` is supported again.
6765
(enum $enum_name:path {
6866
$( $variant:ident
6967
// this incorrectly allows specifying both tuple-like and struct-like fields, as in `Variant(a,b){c,d}`,
7068
// when it should be only one or the other
71-
$( ( $($field:ident $(-> $delegate:tt)*),* ) )*
72-
$( { $($named_field:ident $(-> $named_delegate:tt)*),* } )*
73-
),* $(,)*
69+
$( ( $($field:ident $(-> $delegate:tt)?),* ) )?
70+
$( { $($named_field:ident $(-> $named_delegate:tt)?),* } )?
71+
),* $(,)?
7472
}) => {
7573
impl_stable_hash_for!(
7674
impl<> for enum $enum_name [ $enum_name ] { $( $variant
77-
$( ( $($field $(-> $delegate)*),* ) )*
78-
$( { $($named_field $(-> $named_delegate)*),* } )*
75+
$( ( $($field $(-> $delegate)?),* ) )?
76+
$( { $($named_field $(-> $named_delegate)?),* } )?
7977
),* }
8078
);
8179
};
8280
// We want to use the enum name both in the `impl ... for $enum_name` as well as for
8381
// importing all the variants. Unfortunately it seems we have to take the name
8482
// twice for this purpose
85-
(impl<$($lt:lifetime $(: $lt_bound:lifetime)* ),* $(,)* $($T:ident),* $(,)*>
83+
(impl<$($lt:lifetime $(: $lt_bound:lifetime)? ),* $(,)? $($T:ident),* $(,)?>
8684
for enum $enum_name:path
8785
[ $enum_path:path ]
8886
{
8987
$( $variant:ident
9088
// this incorrectly allows specifying both tuple-like and struct-like fields, as in `Variant(a,b){c,d}`,
9189
// when it should be only one or the other
92-
$( ( $($field:ident $(-> $delegate:tt)*),* ) )*
93-
$( { $($named_field:ident $(-> $named_delegate:tt)*),* } )*
94-
),* $(,)*
90+
$( ( $($field:ident $(-> $delegate:tt)?),* ) )?
91+
$( { $($named_field:ident $(-> $named_delegate:tt)?),* } )?
92+
),* $(,)?
9593
}) => {
96-
impl<'a, $($lt $(: $lt_bound)*,)* $($T,)*>
94+
impl<'a, $($lt $(: $lt_bound)?,)* $($T,)*>
9795
::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>>
9896
for $enum_name
9997
where $($T: ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>>),*
@@ -107,26 +105,25 @@ macro_rules! impl_stable_hash_for {
107105

108106
match *self {
109107
$(
110-
$variant $( ( $(ref $field),* ) )* $( { $(ref $named_field),* } )* => {
111-
$($( __impl_stable_hash_field!($field, __ctx, __hasher $(, $delegate)*) );*)*
112-
$($( __impl_stable_hash_field!($named_field, __ctx, __hasher $(, $named_delegate)*) );*)*
108+
$variant $( ( $(ref $field),* ) )? $( { $(ref $named_field),* } )? => {
109+
$($( __impl_stable_hash_field!($field, __ctx, __hasher $(, $delegate)?) );*)?
110+
$($( __impl_stable_hash_field!($named_field, __ctx, __hasher $(, $named_delegate)?) );*)?
113111
}
114112
)*
115113
}
116114
}
117115
}
118116
};
119117
// Structs
120-
// FIXME(mark-i-m): same here.
121-
(struct $struct_name:path { $($field:ident $(-> $delegate:tt)*),* $(,)* }) => {
118+
(struct $struct_name:path { $($field:ident $(-> $delegate:tt)?),* $(,)? }) => {
122119
impl_stable_hash_for!(
123-
impl<'tcx> for struct $struct_name { $($field $(-> $delegate)*),* }
120+
impl<'tcx> for struct $struct_name { $($field $(-> $delegate)?),* }
124121
);
125122
};
126-
(impl<$($lt:lifetime $(: $lt_bound:lifetime)* ),* $(,)* $($T:ident),* $(,)*> for struct $struct_name:path {
127-
$($field:ident $(-> $delegate:tt)*),* $(,)*
123+
(impl<$($lt:lifetime $(: $lt_bound:lifetime)? ),* $(,)? $($T:ident),* $(,)?> for struct $struct_name:path {
124+
$($field:ident $(-> $delegate:tt)?),* $(,)?
128125
}) => {
129-
impl<'a, $($lt $(: $lt_bound)*,)* $($T,)*>
126+
impl<'a, $($lt $(: $lt_bound)?,)* $($T,)*>
130127
::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>> for $struct_name
131128
where $($T: ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>>),*
132129
{
@@ -138,21 +135,20 @@ macro_rules! impl_stable_hash_for {
138135
$(ref $field),*
139136
} = *self;
140137

141-
$( __impl_stable_hash_field!($field, __ctx, __hasher $(, $delegate)*) );*
138+
$( __impl_stable_hash_field!($field, __ctx, __hasher $(, $delegate)?) );*
142139
}
143140
}
144141
};
145142
// Tuple structs
146-
// We cannot use normale parentheses here, the parser won't allow it
147-
// FIXME(mark-i-m): same here.
148-
(tuple_struct $struct_name:path { $($field:ident $(-> $delegate:tt)*),* $(,)* }) => {
143+
// We cannot use normal parentheses here, the parser won't allow it
144+
(tuple_struct $struct_name:path { $($field:ident $(-> $delegate:tt)?),* $(,)? }) => {
149145
impl_stable_hash_for!(
150-
impl<'tcx> for tuple_struct $struct_name { $($field $(-> $delegate)*),* }
146+
impl<'tcx> for tuple_struct $struct_name { $($field $(-> $delegate)?),* }
151147
);
152148
};
153-
(impl<$($lt:lifetime $(: $lt_bound:lifetime)* ),* $(,)* $($T:ident),* $(,)*>
154-
for tuple_struct $struct_name:path { $($field:ident $(-> $delegate:tt)*),* $(,)* }) => {
155-
impl<'a, $($lt $(: $lt_bound)*,)* $($T,)*>
149+
(impl<$($lt:lifetime $(: $lt_bound:lifetime)? ),* $(,)? $($T:ident),* $(,)?>
150+
for tuple_struct $struct_name:path { $($field:ident $(-> $delegate:tt)?),* $(,)? }) => {
151+
impl<'a, $($lt $(: $lt_bound)?,)* $($T,)*>
156152
::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>> for $struct_name
157153
where $($T: ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>>),*
158154
{
@@ -164,7 +160,7 @@ macro_rules! impl_stable_hash_for {
164160
$(ref $field),*
165161
) = *self;
166162

167-
$( __impl_stable_hash_field!($field, __ctx, __hasher $(, $delegate)*) );*
163+
$( __impl_stable_hash_field!($field, __ctx, __hasher $(, $delegate)?) );*
168164
}
169165
}
170166
};

0 commit comments

Comments
 (0)