Skip to content

Commit d729039

Browse files
committed
steven_blocks: Use the ? operator instead of * in macro
Previously, only the * and + operators were available, for 0 or more and 1 or more, respectively, so steven_blocks used * for optional tokens even though only one would be expected in most cases. Rust version 1.32.0 added a new operator, ?, for zero or one: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1320-2019-01-17 > You can now use the ? operator in macro definitions. The ? operator allows > you to specify zero or one repetitions similar to the * and + operators. rust-lang/rust#56245 Change to use ? instead of * for these optional repetitions. Found this while investigating #174.
1 parent 19948ff commit d729039

File tree

1 file changed

+41
-41
lines changed

1 file changed

+41
-41
lines changed

blocks/src/lib.rs

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,21 @@ macro_rules! define_blocks {
5252
(
5353
$(
5454
$name:ident {
55-
$(modid $modid:expr,)*
55+
$(modid $modid:expr,)?
5656
props {
5757
$(
5858
$fname:ident : $ftype:ty = [$($val:expr),+],
5959
)*
6060
},
61-
$(data $datafunc:expr,)*
62-
$(offset $offsetfunc:expr,)*
63-
$(material $mat:expr,)*
61+
$(data $datafunc:expr,)?
62+
$(offset $offsetfunc:expr,)?
63+
$(material $mat:expr,)?
6464
model $model:expr,
65-
$(variant $variant:expr,)*
66-
$(tint $tint:expr,)*
67-
$(collision $collision:expr,)*
68-
$(update_state ($world:ident, $pos:ident) => $update_state:expr,)*
69-
$(multipart ($mkey:ident, $mval:ident) => $multipart:expr,)*
65+
$(variant $variant:expr,)?
66+
$(tint $tint:expr,)?
67+
$(collision $collision:expr,)?
68+
$(update_state ($world:ident, $pos:ident) => $update_state:expr,)?
69+
$(multipart ($mkey:ident, $mval:ident) => $multipart:expr,)?
7070
}
7171
)+
7272
) => (
@@ -76,7 +76,7 @@ macro_rules! define_blocks {
7676
$name {
7777
$(
7878
$fname : $ftype,
79-
)*
79+
)?
8080
},
8181
)+
8282
}
@@ -90,7 +90,7 @@ macro_rules! define_blocks {
9090
match *self {
9191
$(
9292
Block::$name {
93-
$($fname,)*
93+
$($fname,)?
9494
} => {
9595
internal_ids::$name
9696
}
@@ -103,12 +103,12 @@ macro_rules! define_blocks {
103103
match *self {
104104
$(
105105
Block::$name {
106-
$($fname,)*
106+
$($fname,)?
107107
} => {
108108
$(
109109
let data: Option<usize> = ($datafunc).map(|v| v);
110110
return data;
111-
)*
111+
)?
112112
Some(0)
113113
}
114114
)+
@@ -120,16 +120,16 @@ macro_rules! define_blocks {
120120
match *self {
121121
$(
122122
Block::$name {
123-
$($fname,)*
123+
$($fname,)?
124124
} => {
125125
$(
126126
let offset: Option<usize> = ($offsetfunc).map(|v| v);
127127
return offset;
128-
)*
128+
)?
129129
$(
130130
let data: Option<usize> = ($datafunc).map(|v| v);
131131
return data;
132-
)*
132+
)?
133133
Some(0)
134134
}
135135
)+
@@ -141,11 +141,11 @@ macro_rules! define_blocks {
141141
match *self {
142142
$(
143143
Block::$name {
144-
$($fname,)*
144+
$($fname,)?
145145
} => {
146146
$(
147147
return Some($modid);
148-
)*
148+
)?
149149
None
150150
}
151151
)+
@@ -181,9 +181,9 @@ macro_rules! define_blocks {
181181
match *self {
182182
$(
183183
Block::$name {
184-
$($fname,)*
184+
$($fname,)?
185185
} => {
186-
$(return $mat;)*
186+
$(return $mat;)?
187187
material::SOLID
188188
}
189189
)+
@@ -195,7 +195,7 @@ macro_rules! define_blocks {
195195
match *self {
196196
$(
197197
Block::$name {
198-
$($fname,)*
198+
$($fname,)?
199199
} => {
200200
let parts = $model;
201201
(String::from(parts.0), String::from(parts.1))
@@ -209,9 +209,9 @@ macro_rules! define_blocks {
209209
match *self {
210210
$(
211211
Block::$name {
212-
$($fname,)*
212+
$($fname,)?
213213
} => {
214-
$(return String::from($variant);)*
214+
$(return String::from($variant);)?
215215
"normal".to_owned()
216216
}
217217
)+
@@ -223,9 +223,9 @@ macro_rules! define_blocks {
223223
match *self {
224224
$(
225225
Block::$name {
226-
$($fname,)*
226+
$($fname,)?
227227
} => {
228-
$(return $tint;)*
228+
$(return $tint;)?
229229
TintType::Default
230230
}
231231
)+
@@ -237,9 +237,9 @@ macro_rules! define_blocks {
237237
match *self {
238238
$(
239239
Block::$name {
240-
$($fname,)*
240+
$($fname,)?
241241
} => {
242-
$(return $collision;)*
242+
$(return $collision;)?
243243
vec![Aabb3::new(
244244
Point3::new(0.0, 0.0, 0.0),
245245
Point3::new(1.0, 1.0, 1.0)
@@ -254,15 +254,15 @@ macro_rules! define_blocks {
254254
match *self {
255255
$(
256256
Block::$name {
257-
$($fname,)*
257+
$($fname,)?
258258
} => {
259259
$(
260260
let $world = world;
261261
let $pos = pos;
262262
return $update_state;
263-
)*
263+
)?
264264
Block::$name {
265-
$($fname: $fname,)*
265+
$($fname: $fname,)?
266266
}
267267
}
268268
)+
@@ -274,13 +274,13 @@ macro_rules! define_blocks {
274274
match *self {
275275
$(
276276
Block::$name {
277-
$($fname,)*
277+
$($fname,)?
278278
} => {
279279
$(
280280
let $mkey = key;
281281
let $mval = val;
282282
return $multipart;
283-
)*
283+
)?
284284
false
285285
}
286286
)+
@@ -307,15 +307,15 @@ macro_rules! define_blocks {
307307
}
308308
#[allow(non_camel_case_types)]
309309
struct CombinationIterState<$($fname),*> {
310-
$($fname: $fname,)*
310+
$($fname: $fname,)?
311311
}
312312
#[allow(non_camel_case_types)]
313313
struct CombinationIterOrig<$($fname),*> {
314-
$($fname: $fname,)*
314+
$($fname: $fname,)?
315315
}
316316
#[allow(non_camel_case_types)]
317317
struct CombinationIterCurrent {
318-
$($fname: $ftype,)*
318+
$($fname: $ftype,)?
319319
}
320320

321321
#[allow(non_camel_case_types)]
@@ -332,7 +332,7 @@ macro_rules! define_blocks {
332332
return Some(Block::$name {
333333
$(
334334
$fname: self.current.$fname,
335-
)*
335+
)?
336336
});
337337
}
338338
let mut has_value = false;
@@ -345,15 +345,15 @@ macro_rules! define_blocks {
345345
}
346346
self.state.$fname = self.orig.$fname.clone();
347347
self.current.$fname = self.state.$fname.next().unwrap();
348-
)*
348+
)?
349349
self.finished = true;
350350
return None;
351351
}
352352
if has_value {
353353
Some(Block::$name {
354354
$(
355355
$fname: self.current.$fname,
356-
)*
356+
)?
357357
})
358358
} else {
359359
None
@@ -368,13 +368,13 @@ macro_rules! define_blocks {
368368
finished: false,
369369
first: true,
370370
orig: CombinationIterOrig {
371-
$($fname: $fname.clone(),)*
371+
$($fname: $fname.clone(),)?
372372
},
373373
current: CombinationIterCurrent {
374-
$($fname: $fname.next().unwrap(),)*
374+
$($fname: $fname.next().unwrap(),)?
375375
},
376376
state: CombinationIterState {
377-
$($fname: $fname,)*
377+
$($fname: $fname,)?
378378
}
379379
}
380380
}

0 commit comments

Comments
 (0)