Skip to content

Commit 74380b3

Browse files
authored
Rollup merge of #62068 - ia0:fix_meta_var, r=petrochenkov
Fix meta-variable binding errors in macros The errors are either: - The meta-variable used in the right-hand side is not bound (or defined) in the left-hand side. - The meta-variable used in the right-hand side does not repeat with the same kleene operator as its binder in the left-hand side. Either it does not repeat enough, or it uses a different operator somewhere. This change should have no semantic impact. Found by #62008
2 parents 07c82e1 + b8106b5 commit 74380b3

File tree

16 files changed

+46
-46
lines changed

16 files changed

+46
-46
lines changed

src/libcore/fmt/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2070,19 +2070,19 @@ macro_rules! tuple {
20702070
() => ();
20712071
( $($name:ident,)+ ) => (
20722072
#[stable(feature = "rust1", since = "1.0.0")]
2073-
impl<$($name:Debug),*> Debug for ($($name,)*) where last_type!($($name,)+): ?Sized {
2073+
impl<$($name:Debug),+> Debug for ($($name,)+) where last_type!($($name,)+): ?Sized {
20742074
#[allow(non_snake_case, unused_assignments)]
20752075
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
20762076
let mut builder = f.debug_tuple("");
2077-
let ($(ref $name,)*) = *self;
2077+
let ($(ref $name,)+) = *self;
20782078
$(
20792079
builder.field(&$name);
2080-
)*
2080+
)+
20812081

20822082
builder.finish()
20832083
}
20842084
}
2085-
peel! { $($name,)* }
2085+
peel! { $($name,)+ }
20862086
)
20872087
}
20882088

src/libcore/hash/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -617,11 +617,11 @@ mod impls {
617617

618618
( $($name:ident)+) => (
619619
#[stable(feature = "rust1", since = "1.0.0")]
620-
impl<$($name: Hash),*> Hash for ($($name,)*) where last_type!($($name,)+): ?Sized {
620+
impl<$($name: Hash),+> Hash for ($($name,)+) where last_type!($($name,)+): ?Sized {
621621
#[allow(non_snake_case)]
622622
fn hash<S: Hasher>(&self, state: &mut S) {
623-
let ($(ref $name,)*) = *self;
624-
$($name.hash(state);)*
623+
let ($(ref $name,)+) = *self;
624+
$($name.hash(state);)+
625625
}
626626
}
627627
);

src/libcore/iter/traits/accum.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ macro_rules! integer_sum_product {
7272
($($a:ty)*) => (
7373
integer_sum_product!(@impls 0, 1,
7474
#[stable(feature = "iter_arith_traits", since = "1.12.0")],
75-
$($a)+);
75+
$($a)*);
7676
integer_sum_product!(@impls Wrapping(0), Wrapping(1),
7777
#[stable(feature = "wrapping_iter_arith", since = "1.14.0")],
78-
$(Wrapping<$a>)+);
78+
$(Wrapping<$a>)*);
7979
);
8080
}
8181

src/libcore/macros.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ macro_rules! panic {
1515
$crate::panic!($msg)
1616
);
1717
($fmt:expr, $($arg:tt)+) => ({
18-
$crate::panicking::panic_fmt(format_args!($fmt, $($arg)*),
18+
$crate::panicking::panic_fmt(format_args!($fmt, $($arg)+),
1919
&(file!(), line!(), __rust_unstable_column!()))
2020
});
2121
}
@@ -558,7 +558,7 @@ macro_rules! unreachable {
558558
#[stable(feature = "rust1", since = "1.0.0")]
559559
macro_rules! unimplemented {
560560
() => (panic!("not yet implemented"));
561-
($($arg:tt)+) => (panic!("not yet implemented: {}", format_args!($($arg)*)));
561+
($($arg:tt)+) => (panic!("not yet implemented: {}", format_args!($($arg)+)));
562562
}
563563

564564
/// Indicates unfinished code.
@@ -617,7 +617,7 @@ macro_rules! unimplemented {
617617
#[unstable(feature = "todo_macro", issue = "59277")]
618618
macro_rules! todo {
619619
() => (panic!("not yet implemented"));
620-
($($arg:tt)+) => (panic!("not yet implemented: {}", format_args!($($arg)*)));
620+
($($arg:tt)+) => (panic!("not yet implemented: {}", format_args!($($arg)+)));
621621
}
622622

623623
/// Creates an array of [`MaybeUninit`].

src/libcore/ptr/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2725,12 +2725,12 @@ macro_rules! fnptr_impls_safety_abi {
27252725

27262726
macro_rules! fnptr_impls_args {
27272727
($($Arg: ident),+) => {
2728-
fnptr_impls_safety_abi! { extern "Rust" fn($($Arg),*) -> Ret, $($Arg),* }
2729-
fnptr_impls_safety_abi! { extern "C" fn($($Arg),*) -> Ret, $($Arg),* }
2730-
fnptr_impls_safety_abi! { extern "C" fn($($Arg),* , ...) -> Ret, $($Arg),* }
2731-
fnptr_impls_safety_abi! { unsafe extern "Rust" fn($($Arg),*) -> Ret, $($Arg),* }
2732-
fnptr_impls_safety_abi! { unsafe extern "C" fn($($Arg),*) -> Ret, $($Arg),* }
2733-
fnptr_impls_safety_abi! { unsafe extern "C" fn($($Arg),* , ...) -> Ret, $($Arg),* }
2728+
fnptr_impls_safety_abi! { extern "Rust" fn($($Arg),+) -> Ret, $($Arg),+ }
2729+
fnptr_impls_safety_abi! { extern "C" fn($($Arg),+) -> Ret, $($Arg),+ }
2730+
fnptr_impls_safety_abi! { extern "C" fn($($Arg),+ , ...) -> Ret, $($Arg),+ }
2731+
fnptr_impls_safety_abi! { unsafe extern "Rust" fn($($Arg),+) -> Ret, $($Arg),+ }
2732+
fnptr_impls_safety_abi! { unsafe extern "C" fn($($Arg),+) -> Ret, $($Arg),+ }
2733+
fnptr_impls_safety_abi! { unsafe extern "C" fn($($Arg),+ , ...) -> Ret, $($Arg),+ }
27342734
};
27352735
() => {
27362736
// No variadic functions with 0 parameters

src/libproc_macro/bridge/rpc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ macro_rules! rpc_encode_decode {
5959
}
6060
};
6161
(enum $name:ident $(<$($T:ident),+>)? { $($variant:ident $(($field:ident))*),* $(,)? }) => {
62-
impl<S, $($($T: Encode<S>),+)?> Encode<S> for $name $(<$($T),+>)* {
62+
impl<S, $($($T: Encode<S>),+)?> Encode<S> for $name $(<$($T),+>)? {
6363
fn encode(self, w: &mut Writer, s: &mut S) {
6464
// HACK(eddyb): `Tag` enum duplicated between the
6565
// two impls as there's no other place to stash it.
@@ -79,8 +79,8 @@ macro_rules! rpc_encode_decode {
7979
}
8080
}
8181

82-
impl<S, $($($T: for<'s> DecodeMut<'a, 's, S>),+)*> DecodeMut<'a, '_, S>
83-
for $name $(<$($T),+>)*
82+
impl<S, $($($T: for<'s> DecodeMut<'a, 's, S>),+)?> DecodeMut<'a, '_, S>
83+
for $name $(<$($T),+>)?
8484
{
8585
fn decode(r: &mut Reader<'a>, s: &mut S) -> Self {
8686
// HACK(eddyb): `Tag` enum duplicated between the

src/librustc/middle/weak_lang_items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl<'tcx> TyCtxt<'tcx> {
147147
let lang_items = self.lang_items();
148148
let did = Some(item_def_id);
149149

150-
$(lang_items.$name() == did)||+
150+
$(lang_items.$name() == did)||*
151151
}
152152
}
153153

src/librustc_codegen_llvm/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ macro_rules! builder_methods_for_value_instructions {
110110
unsafe {
111111
llvm::$llvm_capi(self.llbuilder, $($arg,)* UNNAMED)
112112
}
113-
})*
113+
})+
114114
}
115115
}
116116

src/librustc_data_structures/indexed_vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ macro_rules! newtype_index {
423423
(@derives [$($derives:ident,)*]
424424
@attrs [$(#[$attrs:meta])*]
425425
@type [$type:ident]
426-
@max [$_max:expr]
426+
@max [$max:expr]
427427
@vis [$v:vis]
428428
@debug_format [$debug_format:tt]
429429
$(#[doc = $doc:expr])*

src/librustc_lint/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ fn get_type_suggestion(t: Ty<'_>, val: u128, negative: bool) -> Option<String> {
219219
return Some(format!("{:?}", $itypes))
220220
})*
221221
None
222-
},)*
222+
},)+
223223
_ => None
224224
}
225225
}

src/librustc_target/spec/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,19 @@ macro_rules! flavor_mappings {
119119
($((($($flavor:tt)*), $string:expr),)*) => (
120120
impl LinkerFlavor {
121121
pub const fn one_of() -> &'static str {
122-
concat!("one of: ", $($string, " ",)+)
122+
concat!("one of: ", $($string, " ",)*)
123123
}
124124

125125
pub fn from_str(s: &str) -> Option<Self> {
126126
Some(match s {
127-
$($string => $($flavor)*,)+
127+
$($string => $($flavor)*,)*
128128
_ => return None,
129129
})
130130
}
131131

132132
pub fn desc(&self) -> &str {
133133
match *self {
134-
$($($flavor)* => $string,)+
134+
$($($flavor)* => $string,)*
135135
}
136136
}
137137
}

src/libserialize/serialize.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -739,33 +739,33 @@ macro_rules! count {
739739
macro_rules! tuple {
740740
() => ();
741741
( $($name:ident,)+ ) => (
742-
impl<$($name:Decodable),*> Decodable for ($($name,)*) {
742+
impl<$($name:Decodable),+> Decodable for ($($name,)+) {
743743
#[allow(non_snake_case)]
744-
fn decode<D: Decoder>(d: &mut D) -> Result<($($name,)*), D::Error> {
745-
let len: usize = count!($($name)*);
744+
fn decode<D: Decoder>(d: &mut D) -> Result<($($name,)+), D::Error> {
745+
let len: usize = count!($($name)+);
746746
d.read_tuple(len, |d| {
747747
let mut i = 0;
748748
let ret = ($(d.read_tuple_arg({ i+=1; i-1 }, |d| -> Result<$name, D::Error> {
749749
Decodable::decode(d)
750-
})?,)*);
750+
})?,)+);
751751
Ok(ret)
752752
})
753753
}
754754
}
755-
impl<$($name:Encodable),*> Encodable for ($($name,)*) {
755+
impl<$($name:Encodable),+> Encodable for ($($name,)+) {
756756
#[allow(non_snake_case)]
757757
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
758-
let ($(ref $name,)*) = *self;
758+
let ($(ref $name,)+) = *self;
759759
let mut n = 0;
760-
$(let $name = $name; n += 1;)*
760+
$(let $name = $name; n += 1;)+
761761
s.emit_tuple(n, |s| {
762762
let mut i = 0;
763-
$(s.emit_tuple_arg({ i+=1; i-1 }, |s| $name.encode(s))?;)*
763+
$(s.emit_tuple_arg({ i+=1; i-1 }, |s| $name.encode(s))?;)+
764764
Ok(())
765765
})
766766
}
767767
}
768-
peel! { $($name,)* }
768+
peel! { $($name,)+ }
769769
)
770770
}
771771

src/libsyntax/ext/expand.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,20 @@ macro_rules! ast_fragments {
9898
}
9999
});
100100
}
101-
$($(AstFragment::$Kind(ast) => vis.$mut_visit_ast(ast),)*)*
101+
$($(AstFragment::$Kind(ast) => vis.$mut_visit_ast(ast),)?)*
102102
$($(AstFragment::$Kind(ast) =>
103-
ast.flat_map_in_place(|ast| vis.$flat_map_ast_elt(ast)),)*)*
103+
ast.flat_map_in_place(|ast| vis.$flat_map_ast_elt(ast)),)?)*
104104
}
105105
}
106106

107107
pub fn visit_with<'a, V: Visitor<'a>>(&'a self, visitor: &mut V) {
108108
match *self {
109109
AstFragment::OptExpr(Some(ref expr)) => visitor.visit_expr(expr),
110110
AstFragment::OptExpr(None) => {}
111-
$($(AstFragment::$Kind(ref ast) => visitor.$visit_ast(ast),)*)*
111+
$($(AstFragment::$Kind(ref ast) => visitor.$visit_ast(ast),)?)*
112112
$($(AstFragment::$Kind(ref ast) => for ast_elt in &ast[..] {
113113
visitor.$visit_ast_elt(ast_elt);
114-
})*)*
114+
})?)*
115115
}
116116
}
117117
}
@@ -122,10 +122,10 @@ macro_rules! ast_fragments {
122122
}
123123
$($(fn $mut_visit_ast(&mut self, ast: &mut $AstTy) {
124124
visit_clobber(ast, |ast| self.expand_fragment(AstFragment::$Kind(ast)).$make_ast());
125-
})*)*
125+
})?)*
126126
$($(fn $flat_map_ast_elt(&mut self, ast_elt: <$AstTy as IntoIterator>::Item) -> $AstTy {
127127
self.expand_fragment(AstFragment::$Kind(smallvec![ast_elt])).$make_ast()
128-
})*)*
128+
})?)*
129129
}
130130

131131
impl<'a> MacResult for crate::ext::tt::macro_rules::ParserAnyMacro<'a> {

src/libsyntax_ext/deriving/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ macro_rules! derive_traits {
8888
)
8989
}),
9090
);
91-
)*
91+
)+
9292
}
9393
}
9494
}

src/libsyntax_ext/proc_macro_server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl FromInternal<(TreeAndJoint, &'_ ParseSess, &'_ mut Vec<Self>)>
7070
macro_rules! tt {
7171
($ty:ident { $($field:ident $(: $value:expr)*),+ $(,)? }) => (
7272
TokenTree::$ty(self::$ty {
73-
$($field $(: $value)*,)*
73+
$($field $(: $value)*,)+
7474
span,
7575
})
7676
);

src/test/ui/issues/issue-22814.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ trait Test {}
33

44
macro_rules! test {
55
( $($name:ident)+) => (
6-
impl<$($name: Test),*> Test for ($($name,)*) {
6+
impl<$($name: Test),+> Test for ($($name,)+) {
77
}
88
)
99
}

0 commit comments

Comments
 (0)