Skip to content

Commit ccf401f

Browse files
committed
Auto merge of #43078 - kennytm:fix-42755-vis-can-be-empty, r=petrochenkov
Disallow `$($v:vis)*`. Fix #42755. #42755
2 parents afb853a + 06e1fc0 commit ccf401f

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/libsyntax/ext/tt/macro_rules.rs

+1
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ fn check_lhs_no_empty_seq(sess: &ParseSess, tts: &[quoted::TokenTree]) -> bool {
299299
TokenTree::Sequence(span, ref seq) => {
300300
if seq.separator.is_none() && seq.tts.iter().all(|seq_tt| {
301301
match *seq_tt {
302+
TokenTree::MetaVarDecl(_, _, id) => id.name == "vis",
302303
TokenTree::Sequence(_, ref sub_seq) =>
303304
sub_seq.op == quoted::KleeneOp::ZeroOrMore,
304305
_ => false,

src/test/compile-fail/issue-42755.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(macro_vis_matcher)]
12+
13+
macro_rules! foo {
14+
($($p:vis)*) => {} //~ ERROR repetition matches empty token tree
15+
}
16+
17+
foo!(a);

0 commit comments

Comments
 (0)