Skip to content

Commit 72bd4c0

Browse files
committed
Auto merge of #55373 - estebank:macro-rep, r=<try>
Warn on 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. Fix #44975, fix #48220.
2 parents c08840d + 7755f36 commit 72bd4c0

37 files changed

+502
-242
lines changed

src/liballoc/collections/vec_deque.rs

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

24312431
macro_rules! array_impls {
2432-
($($N: expr)+) => {
2432+
($($N: expr),+) => {
24332433
$(
24342434
__impl_slice_eq1! { VecDeque<A>, [B; $N] }
24352435
__impl_slice_eq1! { VecDeque<A>, &'b [B; $N] }
@@ -2439,10 +2439,10 @@ macro_rules! array_impls {
24392439
}
24402440

24412441
array_impls! {
2442-
0 1 2 3 4 5 6 7 8 9
2443-
10 11 12 13 14 15 16 17 18 19
2444-
20 21 22 23 24 25 26 27 28 29
2445-
30 31 32
2442+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
2443+
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
2444+
20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
2445+
30, 31, 32
24462446
}
24472447

24482448
#[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
@@ -665,7 +665,7 @@ mod copy_impls {
665665
use super::Copy;
666666

667667
macro_rules! impl_copy {
668-
($($t:ty)*) => {
668+
($($t:ty),*) => {
669669
$(
670670
#[stable(feature = "rust1", since = "1.0.0")]
671671
impl Copy for $t {}
@@ -674,10 +674,10 @@ mod copy_impls {
674674
}
675675

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

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

src/libcore/num/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4433,7 +4433,7 @@ pub enum FpCategory {
44334433
}
44344434

44354435
macro_rules! from_str_radix_int_impl {
4436-
($($t:ty)*) => {$(
4436+
($($t:ty),*) => {$(
44374437
#[stable(feature = "rust1", since = "1.0.0")]
44384438
impl FromStr for $t {
44394439
type Err = ParseIntError;
@@ -4443,7 +4443,7 @@ macro_rules! from_str_radix_int_impl {
44434443
}
44444444
)*}
44454445
}
4446-
from_str_radix_int_impl! { isize i8 i16 i32 i64 i128 usize u8 u16 u32 u64 u128 }
4446+
from_str_radix_int_impl! { isize, i8, i16, i32, i64, i128, usize, u8, u16, u32, u64, u128 }
44474447

44484448
/// The error type returned when a checked integral type conversion fails.
44494449
#[unstable(feature = "try_from", issue = "33417")]
@@ -4674,7 +4674,7 @@ trait FromStrRadixHelper: PartialOrd + Copy {
46744674
}
46754675

46764676
macro_rules! doit {
4677-
($($t:ty)*) => ($(impl FromStrRadixHelper for $t {
4677+
($($t:ty),*) => ($(impl FromStrRadixHelper for $t {
46784678
#[inline]
46794679
fn min_value() -> Self { Self::min_value() }
46804680
#[inline]
@@ -4695,7 +4695,7 @@ macro_rules! doit {
46954695
}
46964696
})*)
46974697
}
4698-
doit! { i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usize }
4698+
doit! { i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, usize }
46994699

47004700
fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32) -> Result<T, ParseIntError> {
47014701
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)