From 06e1fc06d75e0bc67dcf90b1a12368775ede7ce0 Mon Sep 17 00:00:00 2001 From: kennytm Date: Thu, 6 Jul 2017 08:18:58 +0800 Subject: [PATCH] Disallow `$($v:vis)*`. Fix #42755. --- src/libsyntax/ext/tt/macro_rules.rs | 1 + src/test/compile-fail/issue-42755.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 src/test/compile-fail/issue-42755.rs diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index b732f47ce6a..a98a9dd2040 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -299,6 +299,7 @@ fn check_lhs_no_empty_seq(sess: &ParseSess, tts: &[quoted::TokenTree]) -> bool { TokenTree::Sequence(span, ref seq) => { if seq.separator.is_none() && seq.tts.iter().all(|seq_tt| { match *seq_tt { + TokenTree::MetaVarDecl(_, _, id) => id.name == "vis", TokenTree::Sequence(_, ref sub_seq) => sub_seq.op == quoted::KleeneOp::ZeroOrMore, _ => false, diff --git a/src/test/compile-fail/issue-42755.rs b/src/test/compile-fail/issue-42755.rs new file mode 100644 index 00000000000..7547c4a17be --- /dev/null +++ b/src/test/compile-fail/issue-42755.rs @@ -0,0 +1,17 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(macro_vis_matcher)] + +macro_rules! foo { + ($($p:vis)*) => {} //~ ERROR repetition matches empty token tree +} + +foo!(a);