1
Fork 0

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:
Julien Cretin 2019-05-29 20:05:43 +02:00
parent 305930cffe
commit b8106b59d2
16 changed files with 46 additions and 46 deletions

View file

@ -2070,19 +2070,19 @@ macro_rules! tuple {
() => ();
( $($name:ident,)+ ) => (
#[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)]
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
let mut builder = f.debug_tuple("");
let ($(ref $name,)*) = *self;
let ($(ref $name,)+) = *self;
$(
builder.field(&$name);
)*
)+
builder.finish()
}
}
peel! { $($name,)* }
peel! { $($name,)+ }
)
}

View file

@ -617,11 +617,11 @@ mod impls {
( $($name:ident)+) => (
#[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)]
fn hash<S: Hasher>(&self, state: &mut S) {
let ($(ref $name,)*) = *self;
$($name.hash(state);)*
let ($(ref $name,)+) = *self;
$($name.hash(state);)+
}
}
);

View file

@ -72,10 +72,10 @@ macro_rules! integer_sum_product {
($($a:ty)*) => (
integer_sum_product!(@impls 0, 1,
#[stable(feature = "iter_arith_traits", since = "1.12.0")],
$($a)+);
$($a)*);
integer_sum_product!(@impls Wrapping(0), Wrapping(1),
#[stable(feature = "wrapping_iter_arith", since = "1.14.0")],
$(Wrapping<$a>)+);
$(Wrapping<$a>)*);
);
}

View file

@ -15,7 +15,7 @@ macro_rules! panic {
$crate::panic!($msg)
);
($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!()))
});
}
@ -558,7 +558,7 @@ macro_rules! unreachable {
#[stable(feature = "rust1", since = "1.0.0")]
macro_rules! unimplemented {
() => (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.
@ -617,7 +617,7 @@ macro_rules! unimplemented {
#[unstable(feature = "todo_macro", issue = "59277")]
macro_rules! todo {
() => (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`].

View file

@ -2725,12 +2725,12 @@ macro_rules! fnptr_impls_safety_abi {
macro_rules! fnptr_impls_args {
($($Arg: ident),+) => {
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! { 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! { 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! { 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),+ }
};
() => {
// No variadic functions with 0 parameters

View file

@ -59,7 +59,7 @@ macro_rules! rpc_encode_decode {
}
};
(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) {
// HACK(eddyb): `Tag` enum duplicated between the
// 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>
for $name $(<$($T),+>)*
impl<S, $($($T: for<'s> DecodeMut<'a, 's, S>),+)?> DecodeMut<'a, '_, S>
for $name $(<$($T),+>)?
{
fn decode(r: &mut Reader<'a>, s: &mut S) -> Self {
// HACK(eddyb): `Tag` enum duplicated between the

View file

@ -147,7 +147,7 @@ impl<'tcx> TyCtxt<'tcx> {
let lang_items = self.lang_items();
let did = Some(item_def_id);
$(lang_items.$name() == did)||+
$(lang_items.$name() == did)||*
}
}

View file

@ -110,7 +110,7 @@ macro_rules! builder_methods_for_value_instructions {
unsafe {
llvm::$llvm_capi(self.llbuilder, $($arg,)* UNNAMED)
}
})*
})+
}
}

View file

@ -423,7 +423,7 @@ macro_rules! newtype_index {
(@derives [$($derives:ident,)*]
@attrs [$(#[$attrs:meta])*]
@type [$type:ident]
@max [$_max:expr]
@max [$max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]
$(#[doc = $doc:expr])*

View file

@ -219,7 +219,7 @@ fn get_type_suggestion(t: Ty<'_>, val: u128, negative: bool) -> Option<String> {
return Some(format!("{:?}", $itypes))
})*
None
},)*
},)+
_ => None
}
}

View file

@ -119,19 +119,19 @@ macro_rules! flavor_mappings {
($((($($flavor:tt)*), $string:expr),)*) => (
impl LinkerFlavor {
pub const fn one_of() -> &'static str {
concat!("one of: ", $($string, " ",)+)
concat!("one of: ", $($string, " ",)*)
}
pub fn from_str(s: &str) -> Option<Self> {
Some(match s {
$($string => $($flavor)*,)+
$($string => $($flavor)*,)*
_ => return None,
})
}
pub fn desc(&self) -> &str {
match *self {
$($($flavor)* => $string,)+
$($($flavor)* => $string,)*
}
}
}

View file

@ -739,33 +739,33 @@ macro_rules! count {
macro_rules! tuple {
() => ();
( $($name:ident,)+ ) => (
impl<$($name:Decodable),*> Decodable for ($($name,)*) {
impl<$($name:Decodable),+> Decodable for ($($name,)+) {
#[allow(non_snake_case)]
fn decode<D: Decoder>(d: &mut D) -> Result<($($name,)*), D::Error> {
let len: usize = count!($($name)*);
fn decode<D: Decoder>(d: &mut D) -> Result<($($name,)+), D::Error> {
let len: usize = count!($($name)+);
d.read_tuple(len, |d| {
let mut i = 0;
let ret = ($(d.read_tuple_arg({ i+=1; i-1 }, |d| -> Result<$name, D::Error> {
Decodable::decode(d)
})?,)*);
})?,)+);
Ok(ret)
})
}
}
impl<$($name:Encodable),*> Encodable for ($($name,)*) {
impl<$($name:Encodable),+> Encodable for ($($name,)+) {
#[allow(non_snake_case)]
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
let ($(ref $name,)*) = *self;
let ($(ref $name,)+) = *self;
let mut n = 0;
$(let $name = $name; n += 1;)*
$(let $name = $name; n += 1;)+
s.emit_tuple(n, |s| {
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(())
})
}
}
peel! { $($name,)* }
peel! { $($name,)+ }
)
}

View file

@ -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) =>
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 {
AstFragment::OptExpr(Some(ref expr)) => visitor.visit_expr(expr),
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[..] {
visitor.$visit_ast_elt(ast_elt);
})*)*
})?)*
}
}
}
@ -122,10 +122,10 @@ macro_rules! ast_fragments {
}
$($(fn $mut_visit_ast(&mut self, ast: &mut $AstTy) {
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 {
self.expand_fragment(AstFragment::$Kind(smallvec![ast_elt])).$make_ast()
})*)*
})?)*
}
impl<'a> MacResult for crate::ext::tt::macro_rules::ParserAnyMacro<'a> {

View file

@ -88,7 +88,7 @@ macro_rules! derive_traits {
)
}),
);
)*
)+
}
}
}

View file

@ -70,7 +70,7 @@ impl FromInternal<(TreeAndJoint, &'_ ParseSess, &'_ mut Vec<Self>)>
macro_rules! tt {
($ty:ident { $($field:ident $(: $value:expr)*),+ $(,)? }) => (
TokenTree::$ty(self::$ty {
$($field $(: $value)*,)*
$($field $(: $value)*,)+
span,
})
);

View file

@ -3,7 +3,7 @@ trait Test {}
macro_rules! test {
( $($name:ident)+) => (
impl<$($name: Test),*> Test for ($($name,)*) {
impl<$($name: Test),+> Test for ($($name,)+) {
}
)
}