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.
This commit is contained in:
parent
305930cffe
commit
b8106b59d2
16 changed files with 46 additions and 46 deletions
|
@ -2070,19 +2070,19 @@ macro_rules! tuple {
|
||||||
() => ();
|
() => ();
|
||||||
( $($name:ident,)+ ) => (
|
( $($name:ident,)+ ) => (
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<$($name:Debug),*> Debug for ($($name,)*) where last_type!($($name,)+): ?Sized {
|
impl<$($name:Debug),+> Debug for ($($name,)+) where last_type!($($name,)+): ?Sized {
|
||||||
#[allow(non_snake_case, unused_assignments)]
|
#[allow(non_snake_case, unused_assignments)]
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
||||||
let mut builder = f.debug_tuple("");
|
let mut builder = f.debug_tuple("");
|
||||||
let ($(ref $name,)*) = *self;
|
let ($(ref $name,)+) = *self;
|
||||||
$(
|
$(
|
||||||
builder.field(&$name);
|
builder.field(&$name);
|
||||||
)*
|
)+
|
||||||
|
|
||||||
builder.finish()
|
builder.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
peel! { $($name,)* }
|
peel! { $($name,)+ }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -617,11 +617,11 @@ mod impls {
|
||||||
|
|
||||||
( $($name:ident)+) => (
|
( $($name:ident)+) => (
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<$($name: Hash),*> Hash for ($($name,)*) where last_type!($($name,)+): ?Sized {
|
impl<$($name: Hash),+> Hash for ($($name,)+) where last_type!($($name,)+): ?Sized {
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
fn hash<S: Hasher>(&self, state: &mut S) {
|
fn hash<S: Hasher>(&self, state: &mut S) {
|
||||||
let ($(ref $name,)*) = *self;
|
let ($(ref $name,)+) = *self;
|
||||||
$($name.hash(state);)*
|
$($name.hash(state);)+
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -72,10 +72,10 @@ macro_rules! integer_sum_product {
|
||||||
($($a:ty)*) => (
|
($($a:ty)*) => (
|
||||||
integer_sum_product!(@impls 0, 1,
|
integer_sum_product!(@impls 0, 1,
|
||||||
#[stable(feature = "iter_arith_traits", since = "1.12.0")],
|
#[stable(feature = "iter_arith_traits", since = "1.12.0")],
|
||||||
$($a)+);
|
$($a)*);
|
||||||
integer_sum_product!(@impls Wrapping(0), Wrapping(1),
|
integer_sum_product!(@impls Wrapping(0), Wrapping(1),
|
||||||
#[stable(feature = "wrapping_iter_arith", since = "1.14.0")],
|
#[stable(feature = "wrapping_iter_arith", since = "1.14.0")],
|
||||||
$(Wrapping<$a>)+);
|
$(Wrapping<$a>)*);
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ macro_rules! panic {
|
||||||
$crate::panic!($msg)
|
$crate::panic!($msg)
|
||||||
);
|
);
|
||||||
($fmt:expr, $($arg:tt)+) => ({
|
($fmt:expr, $($arg:tt)+) => ({
|
||||||
$crate::panicking::panic_fmt(format_args!($fmt, $($arg)*),
|
$crate::panicking::panic_fmt(format_args!($fmt, $($arg)+),
|
||||||
&(file!(), line!(), __rust_unstable_column!()))
|
&(file!(), line!(), __rust_unstable_column!()))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -558,7 +558,7 @@ macro_rules! unreachable {
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
macro_rules! unimplemented {
|
macro_rules! unimplemented {
|
||||||
() => (panic!("not yet implemented"));
|
() => (panic!("not yet implemented"));
|
||||||
($($arg:tt)+) => (panic!("not yet implemented: {}", format_args!($($arg)*)));
|
($($arg:tt)+) => (panic!("not yet implemented: {}", format_args!($($arg)+)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Indicates unfinished code.
|
/// Indicates unfinished code.
|
||||||
|
@ -617,7 +617,7 @@ macro_rules! unimplemented {
|
||||||
#[unstable(feature = "todo_macro", issue = "59277")]
|
#[unstable(feature = "todo_macro", issue = "59277")]
|
||||||
macro_rules! todo {
|
macro_rules! todo {
|
||||||
() => (panic!("not yet implemented"));
|
() => (panic!("not yet implemented"));
|
||||||
($($arg:tt)+) => (panic!("not yet implemented: {}", format_args!($($arg)*)));
|
($($arg:tt)+) => (panic!("not yet implemented: {}", format_args!($($arg)+)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates an array of [`MaybeUninit`].
|
/// Creates an array of [`MaybeUninit`].
|
||||||
|
|
|
@ -2725,12 +2725,12 @@ macro_rules! fnptr_impls_safety_abi {
|
||||||
|
|
||||||
macro_rules! fnptr_impls_args {
|
macro_rules! fnptr_impls_args {
|
||||||
($($Arg: ident),+) => {
|
($($Arg: ident),+) => {
|
||||||
fnptr_impls_safety_abi! { extern "Rust" fn($($Arg),*) -> Ret, $($Arg),* }
|
fnptr_impls_safety_abi! { extern "Rust" fn($($Arg),+) -> Ret, $($Arg),+ }
|
||||||
fnptr_impls_safety_abi! { extern "C" fn($($Arg),*) -> Ret, $($Arg),* }
|
fnptr_impls_safety_abi! { extern "C" fn($($Arg),+) -> Ret, $($Arg),+ }
|
||||||
fnptr_impls_safety_abi! { extern "C" fn($($Arg),* , ...) -> Ret, $($Arg),* }
|
fnptr_impls_safety_abi! { extern "C" fn($($Arg),+ , ...) -> Ret, $($Arg),+ }
|
||||||
fnptr_impls_safety_abi! { unsafe extern "Rust" fn($($Arg),*) -> Ret, $($Arg),* }
|
fnptr_impls_safety_abi! { unsafe extern "Rust" fn($($Arg),+) -> Ret, $($Arg),+ }
|
||||||
fnptr_impls_safety_abi! { unsafe extern "C" fn($($Arg),*) -> Ret, $($Arg),* }
|
fnptr_impls_safety_abi! { unsafe extern "C" fn($($Arg),+) -> Ret, $($Arg),+ }
|
||||||
fnptr_impls_safety_abi! { unsafe extern "C" fn($($Arg),* , ...) -> Ret, $($Arg),* }
|
fnptr_impls_safety_abi! { unsafe extern "C" fn($($Arg),+ , ...) -> Ret, $($Arg),+ }
|
||||||
};
|
};
|
||||||
() => {
|
() => {
|
||||||
// No variadic functions with 0 parameters
|
// No variadic functions with 0 parameters
|
||||||
|
|
|
@ -59,7 +59,7 @@ macro_rules! rpc_encode_decode {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
(enum $name:ident $(<$($T:ident),+>)? { $($variant:ident $(($field:ident))*),* $(,)? }) => {
|
(enum $name:ident $(<$($T:ident),+>)? { $($variant:ident $(($field:ident))*),* $(,)? }) => {
|
||||||
impl<S, $($($T: Encode<S>),+)?> Encode<S> for $name $(<$($T),+>)* {
|
impl<S, $($($T: Encode<S>),+)?> Encode<S> for $name $(<$($T),+>)? {
|
||||||
fn encode(self, w: &mut Writer, s: &mut S) {
|
fn encode(self, w: &mut Writer, s: &mut S) {
|
||||||
// HACK(eddyb): `Tag` enum duplicated between the
|
// HACK(eddyb): `Tag` enum duplicated between the
|
||||||
// two impls as there's no other place to stash it.
|
// two impls as there's no other place to stash it.
|
||||||
|
@ -79,8 +79,8 @@ macro_rules! rpc_encode_decode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, $($($T: for<'s> DecodeMut<'a, 's, S>),+)*> DecodeMut<'a, '_, S>
|
impl<S, $($($T: for<'s> DecodeMut<'a, 's, S>),+)?> DecodeMut<'a, '_, S>
|
||||||
for $name $(<$($T),+>)*
|
for $name $(<$($T),+>)?
|
||||||
{
|
{
|
||||||
fn decode(r: &mut Reader<'a>, s: &mut S) -> Self {
|
fn decode(r: &mut Reader<'a>, s: &mut S) -> Self {
|
||||||
// HACK(eddyb): `Tag` enum duplicated between the
|
// HACK(eddyb): `Tag` enum duplicated between the
|
||||||
|
|
|
@ -147,7 +147,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
let lang_items = self.lang_items();
|
let lang_items = self.lang_items();
|
||||||
let did = Some(item_def_id);
|
let did = Some(item_def_id);
|
||||||
|
|
||||||
$(lang_items.$name() == did)||+
|
$(lang_items.$name() == did)||*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,7 @@ macro_rules! builder_methods_for_value_instructions {
|
||||||
unsafe {
|
unsafe {
|
||||||
llvm::$llvm_capi(self.llbuilder, $($arg,)* UNNAMED)
|
llvm::$llvm_capi(self.llbuilder, $($arg,)* UNNAMED)
|
||||||
}
|
}
|
||||||
})*
|
})+
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -423,7 +423,7 @@ macro_rules! newtype_index {
|
||||||
(@derives [$($derives:ident,)*]
|
(@derives [$($derives:ident,)*]
|
||||||
@attrs [$(#[$attrs:meta])*]
|
@attrs [$(#[$attrs:meta])*]
|
||||||
@type [$type:ident]
|
@type [$type:ident]
|
||||||
@max [$_max:expr]
|
@max [$max:expr]
|
||||||
@vis [$v:vis]
|
@vis [$v:vis]
|
||||||
@debug_format [$debug_format:tt]
|
@debug_format [$debug_format:tt]
|
||||||
$(#[doc = $doc:expr])*
|
$(#[doc = $doc:expr])*
|
||||||
|
|
|
@ -219,7 +219,7 @@ fn get_type_suggestion(t: Ty<'_>, val: u128, negative: bool) -> Option<String> {
|
||||||
return Some(format!("{:?}", $itypes))
|
return Some(format!("{:?}", $itypes))
|
||||||
})*
|
})*
|
||||||
None
|
None
|
||||||
},)*
|
},)+
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,19 +119,19 @@ macro_rules! flavor_mappings {
|
||||||
($((($($flavor:tt)*), $string:expr),)*) => (
|
($((($($flavor:tt)*), $string:expr),)*) => (
|
||||||
impl LinkerFlavor {
|
impl LinkerFlavor {
|
||||||
pub const fn one_of() -> &'static str {
|
pub const fn one_of() -> &'static str {
|
||||||
concat!("one of: ", $($string, " ",)+)
|
concat!("one of: ", $($string, " ",)*)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_str(s: &str) -> Option<Self> {
|
pub fn from_str(s: &str) -> Option<Self> {
|
||||||
Some(match s {
|
Some(match s {
|
||||||
$($string => $($flavor)*,)+
|
$($string => $($flavor)*,)*
|
||||||
_ => return None,
|
_ => return None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn desc(&self) -> &str {
|
pub fn desc(&self) -> &str {
|
||||||
match *self {
|
match *self {
|
||||||
$($($flavor)* => $string,)+
|
$($($flavor)* => $string,)*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -739,33 +739,33 @@ macro_rules! count {
|
||||||
macro_rules! tuple {
|
macro_rules! tuple {
|
||||||
() => ();
|
() => ();
|
||||||
( $($name:ident,)+ ) => (
|
( $($name:ident,)+ ) => (
|
||||||
impl<$($name:Decodable),*> Decodable for ($($name,)*) {
|
impl<$($name:Decodable),+> Decodable for ($($name,)+) {
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
fn decode<D: Decoder>(d: &mut D) -> Result<($($name,)*), D::Error> {
|
fn decode<D: Decoder>(d: &mut D) -> Result<($($name,)+), D::Error> {
|
||||||
let len: usize = count!($($name)*);
|
let len: usize = count!($($name)+);
|
||||||
d.read_tuple(len, |d| {
|
d.read_tuple(len, |d| {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
let ret = ($(d.read_tuple_arg({ i+=1; i-1 }, |d| -> Result<$name, D::Error> {
|
let ret = ($(d.read_tuple_arg({ i+=1; i-1 }, |d| -> Result<$name, D::Error> {
|
||||||
Decodable::decode(d)
|
Decodable::decode(d)
|
||||||
})?,)*);
|
})?,)+);
|
||||||
Ok(ret)
|
Ok(ret)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<$($name:Encodable),*> Encodable for ($($name,)*) {
|
impl<$($name:Encodable),+> Encodable for ($($name,)+) {
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
|
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
|
||||||
let ($(ref $name,)*) = *self;
|
let ($(ref $name,)+) = *self;
|
||||||
let mut n = 0;
|
let mut n = 0;
|
||||||
$(let $name = $name; n += 1;)*
|
$(let $name = $name; n += 1;)+
|
||||||
s.emit_tuple(n, |s| {
|
s.emit_tuple(n, |s| {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
$(s.emit_tuple_arg({ i+=1; i-1 }, |s| $name.encode(s))?;)*
|
$(s.emit_tuple_arg({ i+=1; i-1 }, |s| $name.encode(s))?;)+
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
peel! { $($name,)* }
|
peel! { $($name,)+ }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,9 +98,9 @@ macro_rules! ast_fragments {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
$($(AstFragment::$Kind(ast) => vis.$mut_visit_ast(ast),)*)*
|
$($(AstFragment::$Kind(ast) => vis.$mut_visit_ast(ast),)?)*
|
||||||
$($(AstFragment::$Kind(ast) =>
|
$($(AstFragment::$Kind(ast) =>
|
||||||
ast.flat_map_in_place(|ast| vis.$flat_map_ast_elt(ast)),)*)*
|
ast.flat_map_in_place(|ast| vis.$flat_map_ast_elt(ast)),)?)*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,10 +108,10 @@ macro_rules! ast_fragments {
|
||||||
match *self {
|
match *self {
|
||||||
AstFragment::OptExpr(Some(ref expr)) => visitor.visit_expr(expr),
|
AstFragment::OptExpr(Some(ref expr)) => visitor.visit_expr(expr),
|
||||||
AstFragment::OptExpr(None) => {}
|
AstFragment::OptExpr(None) => {}
|
||||||
$($(AstFragment::$Kind(ref ast) => visitor.$visit_ast(ast),)*)*
|
$($(AstFragment::$Kind(ref ast) => visitor.$visit_ast(ast),)?)*
|
||||||
$($(AstFragment::$Kind(ref ast) => for ast_elt in &ast[..] {
|
$($(AstFragment::$Kind(ref ast) => for ast_elt in &ast[..] {
|
||||||
visitor.$visit_ast_elt(ast_elt);
|
visitor.$visit_ast_elt(ast_elt);
|
||||||
})*)*
|
})?)*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,10 +122,10 @@ macro_rules! ast_fragments {
|
||||||
}
|
}
|
||||||
$($(fn $mut_visit_ast(&mut self, ast: &mut $AstTy) {
|
$($(fn $mut_visit_ast(&mut self, ast: &mut $AstTy) {
|
||||||
visit_clobber(ast, |ast| self.expand_fragment(AstFragment::$Kind(ast)).$make_ast());
|
visit_clobber(ast, |ast| self.expand_fragment(AstFragment::$Kind(ast)).$make_ast());
|
||||||
})*)*
|
})?)*
|
||||||
$($(fn $flat_map_ast_elt(&mut self, ast_elt: <$AstTy as IntoIterator>::Item) -> $AstTy {
|
$($(fn $flat_map_ast_elt(&mut self, ast_elt: <$AstTy as IntoIterator>::Item) -> $AstTy {
|
||||||
self.expand_fragment(AstFragment::$Kind(smallvec![ast_elt])).$make_ast()
|
self.expand_fragment(AstFragment::$Kind(smallvec![ast_elt])).$make_ast()
|
||||||
})*)*
|
})?)*
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> MacResult for crate::ext::tt::macro_rules::ParserAnyMacro<'a> {
|
impl<'a> MacResult for crate::ext::tt::macro_rules::ParserAnyMacro<'a> {
|
||||||
|
|
|
@ -88,7 +88,7 @@ macro_rules! derive_traits {
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
)*
|
)+
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ impl FromInternal<(TreeAndJoint, &'_ ParseSess, &'_ mut Vec<Self>)>
|
||||||
macro_rules! tt {
|
macro_rules! tt {
|
||||||
($ty:ident { $($field:ident $(: $value:expr)*),+ $(,)? }) => (
|
($ty:ident { $($field:ident $(: $value:expr)*),+ $(,)? }) => (
|
||||||
TokenTree::$ty(self::$ty {
|
TokenTree::$ty(self::$ty {
|
||||||
$($field $(: $value)*,)*
|
$($field $(: $value)*,)+
|
||||||
span,
|
span,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
|
@ -3,7 +3,7 @@ trait Test {}
|
||||||
|
|
||||||
macro_rules! test {
|
macro_rules! test {
|
||||||
( $($name:ident)+) => (
|
( $($name:ident)+) => (
|
||||||
impl<$($name: Test),*> Test for ($($name,)*) {
|
impl<$($name: Test),+> Test for ($($name,)+) {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue