Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix meta-variable binding errors in macros #62068

Merged
merged 1 commit into from
Jun 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,)+ }
)
}

Expand Down
6 changes: 3 additions & 3 deletions src/libcore/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);)+
}
}
);
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/iter/traits/accum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>)*);
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/libcore/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!()))
});
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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`].
Expand Down
12 changes: 6 additions & 6 deletions src/libcore/ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/libproc_macro/bridge/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/weak_lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)||*
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ macro_rules! builder_methods_for_value_instructions {
unsafe {
llvm::$llvm_capi(self.llbuilder, $($arg,)* UNNAMED)
}
})*
})+
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_data_structures/indexed_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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])*
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ fn get_type_suggestion(t: Ty<'_>, val: u128, negative: bool) -> Option<String> {
return Some(format!("{:?}", $itypes))
})*
None
},)*
},)+
_ => None
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_target/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,)*
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/libserialize/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,)+ }
)
}

Expand Down
12 changes: 6 additions & 6 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,20 @@ 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)),)?)*
}
}

pub fn visit_with<'a, V: Visitor<'a>>(&'a self, visitor: &mut V) {
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);
})*)*
})?)*
}
}
}
Expand All @@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax_ext/deriving/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ macro_rules! derive_traits {
)
}),
);
)*
)+
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax_ext/proc_macro_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
);
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-22814.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ trait Test {}

macro_rules! test {
( $($name:ident)+) => (
impl<$($name: Test),*> Test for ($($name,)*) {
impl<$($name: Test),+> Test for ($($name,)+) {
}
)
}
Expand Down