Skip to content

Commit 11b8746

Browse files
committed
Disallow incorrect unseparated repetition
Macro pattern `($a:expr, $b:expr)` is invalid, for good reason. Correctly reject pattern `($($a:expr)*)`, as it is functionally the same.
1 parent 8ec22e7 commit 11b8746

22 files changed

+240
-131
lines changed

src/liballoc/collections/vec_deque.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2389,7 +2389,7 @@ __impl_slice_eq1! { VecDeque<A>, &'b [B] }
23892389
__impl_slice_eq1! { VecDeque<A>, &'b mut [B] }
23902390

23912391
macro_rules! array_impls {
2392-
($($N: expr)+) => {
2392+
($($N: expr),+) => {
23932393
$(
23942394
__impl_slice_eq1! { VecDeque<A>, [B; $N] }
23952395
__impl_slice_eq1! { VecDeque<A>, &'b [B; $N] }
@@ -2399,10 +2399,10 @@ macro_rules! array_impls {
23992399
}
24002400

24012401
array_impls! {
2402-
0 1 2 3 4 5 6 7 8 9
2403-
10 11 12 13 14 15 16 17 18 19
2404-
20 21 22 23 24 25 26 27 28 29
2405-
30 31 32
2402+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
2403+
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
2404+
20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
2405+
30, 31, 32
24062406
}
24072407

24082408
#[stable(feature = "rust1", since = "1.0.0")]

src/liballoc/vec.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2065,7 +2065,7 @@ __impl_slice_eq1! { Cow<'a, [A]>, &'b mut [B], Clone }
20652065
__impl_slice_eq1! { Cow<'a, [A]>, Vec<B>, Clone }
20662066

20672067
macro_rules! array_impls {
2068-
($($N: expr)+) => {
2068+
($($N: expr),+) => {
20692069
$(
20702070
// NOTE: some less important impls are omitted to reduce code bloat
20712071
__impl_slice_eq1! { Vec<A>, [B; $N] }
@@ -2079,10 +2079,10 @@ macro_rules! array_impls {
20792079
}
20802080

20812081
array_impls! {
2082-
0 1 2 3 4 5 6 7 8 9
2083-
10 11 12 13 14 15 16 17 18 19
2084-
20 21 22 23 24 25 26 27 28 29
2085-
30 31 32
2082+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
2083+
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
2084+
20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
2085+
30, 31, 32
20862086
}
20872087

20882088
/// Implements comparison of vectors, lexicographically.

src/libcore/array.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ macro_rules! __impl_slice_eq2 {
116116

117117
// macro for implementing n-element array functions and operations
118118
macro_rules! array_impls {
119-
($($N:expr)+) => {
119+
($($N:expr),+) => {
120120
$(
121121
#[stable(feature = "rust1", since = "1.0.0")]
122122
impl<T> AsRef<[T]> for [T; $N] {
@@ -257,10 +257,10 @@ macro_rules! array_impls {
257257
}
258258

259259
array_impls! {
260-
0 1 2 3 4 5 6 7 8 9
261-
10 11 12 13 14 15 16 17 18 19
262-
20 21 22 23 24 25 26 27 28 29
263-
30 31 32
260+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
261+
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
262+
20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
263+
30, 31, 32
264264
}
265265

266266
// The Default impls cannot be generated using the array_impls! macro because

src/libcore/clone.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ mod impls {
158158
use super::Clone;
159159

160160
macro_rules! impl_clone {
161-
($($t:ty)*) => {
161+
($($t:ty),*) => {
162162
$(
163163
#[stable(feature = "rust1", since = "1.0.0")]
164164
impl Clone for $t {
@@ -172,10 +172,10 @@ mod impls {
172172
}
173173

174174
impl_clone! {
175-
usize u8 u16 u32 u64 u128
176-
isize i8 i16 i32 i64 i128
177-
f32 f64
178-
bool char
175+
usize, u8, u16, u32, u64, u128,
176+
isize, i8, i16, i32, i64, i128,
177+
f32, f64,
178+
bool, char
179179
}
180180

181181
#[unstable(feature = "never_type", issue = "35121")]

src/libcore/cmp.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ mod impls {
863863
use cmp::Ordering::{self, Less, Greater, Equal};
864864

865865
macro_rules! partial_eq_impl {
866-
($($t:ty)*) => ($(
866+
($($t:ty),*) => ($(
867867
#[stable(feature = "rust1", since = "1.0.0")]
868868
impl PartialEq for $t {
869869
#[inline]
@@ -883,20 +883,20 @@ mod impls {
883883
}
884884

885885
partial_eq_impl! {
886-
bool char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64
886+
bool, char, usize, u8, u16, u32, u64, u128, isize, i8, i16, i32, i64, i128, f32, f64
887887
}
888888

889889
macro_rules! eq_impl {
890-
($($t:ty)*) => ($(
890+
($($t:ty),*) => ($(
891891
#[stable(feature = "rust1", since = "1.0.0")]
892892
impl Eq for $t {}
893893
)*)
894894
}
895895

896-
eq_impl! { () bool char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
896+
eq_impl! { (), bool, char, usize, u8, u16, u32, u64, u128, isize, i8, i16, i32, i64, i128 }
897897

898898
macro_rules! partial_ord_impl {
899-
($($t:ty)*) => ($(
899+
($($t:ty),*) => ($(
900900
#[stable(feature = "rust1", since = "1.0.0")]
901901
impl PartialOrd for $t {
902902
#[inline]
@@ -936,10 +936,10 @@ mod impls {
936936
}
937937
}
938938

939-
partial_ord_impl! { f32 f64 }
939+
partial_ord_impl! { f32, f64 }
940940

941941
macro_rules! ord_impl {
942-
($($t:ty)*) => ($(
942+
($($t:ty),*) => ($(
943943
#[stable(feature = "rust1", since = "1.0.0")]
944944
impl PartialOrd for $t {
945945
#[inline]
@@ -982,7 +982,7 @@ mod impls {
982982
}
983983
}
984984

985-
ord_impl! { char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
985+
ord_impl! { char, usize, u8, u16, u32, u64, u128, isize, i8, i16, i32, i64, i128 }
986986

987987
#[unstable(feature = "never_type", issue = "35121")]
988988
impl PartialEq for ! {

src/libcore/iter/range.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ macro_rules! step_identical_methods {
7272
}
7373

7474
macro_rules! step_impl_unsigned {
75-
($($t:ty)*) => ($(
75+
($($t:ty),*) => ($(
7676
#[unstable(feature = "step_trait",
7777
reason = "likely to be replaced by finer-grained traits",
7878
issue = "42168")]
@@ -145,7 +145,7 @@ macro_rules! step_impl_signed {
145145
}
146146

147147
macro_rules! step_impl_no_between {
148-
($($t:ty)*) => ($(
148+
($($t:ty),*) => ($(
149149
#[unstable(feature = "step_trait",
150150
reason = "likely to be replaced by finer-grained traits",
151151
issue = "42168")]
@@ -165,7 +165,7 @@ macro_rules! step_impl_no_between {
165165
)*)
166166
}
167167

168-
step_impl_unsigned!(usize u8 u16);
168+
step_impl_unsigned!(usize, u8, u16);
169169
#[cfg(not(target_pointer_witdth = "16"))]
170170
step_impl_unsigned!(u32);
171171
#[cfg(target_pointer_witdth = "16")]
@@ -182,32 +182,32 @@ step_impl_signed!([i64: u64]);
182182
// If the target pointer width is not 64-bits, we
183183
// assume here that it is less than 64-bits.
184184
#[cfg(not(target_pointer_width = "64"))]
185-
step_impl_no_between!(u64 i64);
186-
step_impl_no_between!(u128 i128);
185+
step_impl_no_between!(u64, i64);
186+
step_impl_no_between!(u128, i128);
187187

188188
macro_rules! range_exact_iter_impl {
189-
($($t:ty)*) => ($(
189+
($($t:ty),*) => ($(
190190
#[stable(feature = "rust1", since = "1.0.0")]
191191
impl ExactSizeIterator for ops::Range<$t> { }
192192
)*)
193193
}
194194

195195
macro_rules! range_incl_exact_iter_impl {
196-
($($t:ty)*) => ($(
196+
($($t:ty),*) => ($(
197197
#[stable(feature = "inclusive_range", since = "1.26.0")]
198198
impl ExactSizeIterator for ops::RangeInclusive<$t> { }
199199
)*)
200200
}
201201

202202
macro_rules! range_trusted_len_impl {
203-
($($t:ty)*) => ($(
203+
($($t:ty),*) => ($(
204204
#[unstable(feature = "trusted_len", issue = "37572")]
205205
unsafe impl TrustedLen for ops::Range<$t> { }
206206
)*)
207207
}
208208

209209
macro_rules! range_incl_trusted_len_impl {
210-
($($t:ty)*) => ($(
210+
($($t:ty),*) => ($(
211211
#[unstable(feature = "trusted_len", issue = "37572")]
212212
unsafe impl TrustedLen for ops::RangeInclusive<$t> { }
213213
)*)
@@ -276,15 +276,15 @@ impl<A: Step> Iterator for ops::Range<A> {
276276
// Range<{u,i}64> and RangeInclusive<{u,i}{32,64,size}> are excluded
277277
// because they cannot guarantee having a length <= usize::MAX, which is
278278
// required by ExactSizeIterator.
279-
range_exact_iter_impl!(usize u8 u16 u32 isize i8 i16 i32);
280-
range_incl_exact_iter_impl!(u8 u16 i8 i16);
279+
range_exact_iter_impl!(usize, u8, u16, u32, isize, i8, i16, i32);
280+
range_incl_exact_iter_impl!(u8, u16, i8, i16);
281281

282282
// These macros generate `TrustedLen` impls.
283283
//
284284
// They need to guarantee that .size_hint() is either exact, or that
285285
// the upper bound is None when it does not fit the type limits.
286-
range_trusted_len_impl!(usize isize u8 i8 u16 i16 u32 i32 i64 u64);
287-
range_incl_trusted_len_impl!(usize isize u8 i8 u16 i16 u32 i32 i64 u64);
286+
range_trusted_len_impl!(usize, isize, u8, i8, u16, i16, u32, i32, i64, u64);
287+
range_incl_trusted_len_impl!(usize, isize, u8, i8, u16, i16, u32, i32, i64, u64);
288288

289289
#[stable(feature = "rust1", since = "1.0.0")]
290290
impl<A: Step> DoubleEndedIterator for ops::Range<A> {

src/libcore/iter/traits.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ pub trait Product<A = Self>: Sized {
772772

773773
// NB: explicitly use Add and Mul here to inherit overflow checks
774774
macro_rules! integer_sum_product {
775-
(@impls $zero:expr, $one:expr, #[$attr:meta], $($a:ty)*) => ($(
775+
(@impls $zero:expr, $one:expr, #[$attr:meta], $($a:ty),*) => ($(
776776
#[$attr]
777777
impl Sum for $a {
778778
fn sum<I: Iterator<Item=$a>>(iter: I) -> $a {
@@ -801,13 +801,13 @@ macro_rules! integer_sum_product {
801801
}
802802
}
803803
)*);
804-
($($a:ty)*) => (
804+
($($a:ty),*) => (
805805
integer_sum_product!(@impls 0, 1,
806806
#[stable(feature = "iter_arith_traits", since = "1.12.0")],
807-
$($a)+);
807+
$($a),+);
808808
integer_sum_product!(@impls Wrapping(0), Wrapping(1),
809809
#[stable(feature = "wrapping_iter_arith", since = "1.14.0")],
810-
$(Wrapping<$a>)+);
810+
$(Wrapping<$a>),+);
811811
);
812812
}
813813

@@ -843,7 +843,7 @@ macro_rules! float_sum_product {
843843
)*)
844844
}
845845

846-
integer_sum_product! { i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usize }
846+
integer_sum_product! { i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, usize }
847847
float_sum_product! { f32 f64 }
848848

849849
/// An iterator adapter that produces output as long as the underlying

src/libcore/marker.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ mod copy_impls {
664664
use super::Copy;
665665

666666
macro_rules! impl_copy {
667-
($($t:ty)*) => {
667+
($($t:ty),*) => {
668668
$(
669669
#[stable(feature = "rust1", since = "1.0.0")]
670670
impl Copy for $t {}
@@ -673,10 +673,10 @@ mod copy_impls {
673673
}
674674

675675
impl_copy! {
676-
usize u8 u16 u32 u64 u128
677-
isize i8 i16 i32 i64 i128
678-
f32 f64
679-
bool char
676+
usize, u8, u16, u32, u64, u128,
677+
isize, i8, i16, i32, i64, i128,
678+
f32, f64,
679+
bool, char
680680
}
681681

682682
#[unstable(feature = "never_type", issue = "35121")]

src/libcore/num/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4421,7 +4421,7 @@ pub enum FpCategory {
44214421
}
44224422

44234423
macro_rules! from_str_radix_int_impl {
4424-
($($t:ty)*) => {$(
4424+
($($t:ty),*) => {$(
44254425
#[stable(feature = "rust1", since = "1.0.0")]
44264426
impl FromStr for $t {
44274427
type Err = ParseIntError;
@@ -4431,7 +4431,7 @@ macro_rules! from_str_radix_int_impl {
44314431
}
44324432
)*}
44334433
}
4434-
from_str_radix_int_impl! { isize i8 i16 i32 i64 i128 usize u8 u16 u32 u64 u128 }
4434+
from_str_radix_int_impl! { isize, i8, i16, i32, i64, i128, usize, u8, u16, u32, u64, u128 }
44354435

44364436
/// The error type returned when a checked integral type conversion fails.
44374437
#[unstable(feature = "try_from", issue = "33417")]
@@ -4662,7 +4662,7 @@ trait FromStrRadixHelper: PartialOrd + Copy {
46624662
}
46634663

46644664
macro_rules! doit {
4665-
($($t:ty)*) => ($(impl FromStrRadixHelper for $t {
4665+
($($t:ty),*) => ($(impl FromStrRadixHelper for $t {
46664666
#[inline]
46674667
fn min_value() -> Self { Self::min_value() }
46684668
#[inline]
@@ -4683,7 +4683,7 @@ macro_rules! doit {
46834683
}
46844684
})*)
46854685
}
4686-
doit! { i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usize }
4686+
doit! { i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, usize }
46874687

46884688
fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32) -> Result<T, ParseIntError> {
46894689
use self::IntErrorKind::*;

src/libcore/num/wrapping.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ sh_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize }
128128

129129
// FIXME(30524): impl Op<T> for Wrapping<T>, impl OpAssign<T> for Wrapping<T>
130130
macro_rules! wrapping_impl {
131-
($($t:ty)*) => ($(
131+
($($t:ty),*) => ($(
132132
#[stable(feature = "rust1", since = "1.0.0")]
133133
impl Add for Wrapping<$t> {
134134
type Output = Wrapping<$t>;
@@ -323,10 +323,10 @@ macro_rules! wrapping_impl {
323323
)*)
324324
}
325325

326-
wrapping_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
326+
wrapping_impl! { usize, u8, u16, u32, u64, u128, isize, i8, i16, i32, i64, i128 }
327327

328328
macro_rules! wrapping_int_impl {
329-
($($t:ty)*) => ($(
329+
($($t:ty),*) => ($(
330330
impl Wrapping<$t> {
331331
doc_comment! {
332332
concat!("Returns the smallest value that can be represented by this integer type.
@@ -685,10 +685,10 @@ assert_eq!(Wrapping(3i8).pow(6), Wrapping(-39));
685685
)*)
686686
}
687687

688-
wrapping_int_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
688+
wrapping_int_impl! { usize, u8, u16, u32, u64, u128, isize, i8, i16, i32, i64, i128 }
689689

690690
macro_rules! wrapping_int_impl_signed {
691-
($($t:ty)*) => ($(
691+
($($t:ty),*) => ($(
692692
impl Wrapping<$t> {
693693
doc_comment! {
694694
concat!("Returns the number of leading zeros in the binary representation of `self`.
@@ -814,10 +814,10 @@ assert!(!Wrapping(10", stringify!($t), ").is_negative());
814814
)*)
815815
}
816816

817-
wrapping_int_impl_signed! { isize i8 i16 i32 i64 i128 }
817+
wrapping_int_impl_signed! { isize, i8, i16, i32, i64, i128 }
818818

819819
macro_rules! wrapping_int_impl_unsigned {
820-
($($t:ty)*) => ($(
820+
($($t:ty),*) => ($(
821821
impl Wrapping<$t> {
822822
doc_comment! {
823823
concat!("Returns the number of leading zeros in the binary representation of `self`.
@@ -891,7 +891,7 @@ assert_eq!(Wrapping(200_u8).next_power_of_two(), Wrapping(0));
891891
)*)
892892
}
893893

894-
wrapping_int_impl_unsigned! { usize u8 u16 u32 u64 u128 }
894+
wrapping_int_impl_unsigned! { usize, u8, u16, u32, u64, u128 }
895895

896896
mod shift_max {
897897
#![allow(non_upper_case_globals)]

0 commit comments

Comments
 (0)