Skip to content

Commit 65ea911

Browse files
author
Keegan McAllister
committed
Always error on invalid macro fragment specifiers
Fixes #21370. unused-macro-with-follow-violation.rs was already handled correctly. That test is just for good measure. :)
1 parent 880fb89 commit 65ea911

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

src/libsyntax/ext/tt/macro_rules.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,10 @@ fn check_matcher<'a, I>(cx: &mut ExtCtxt, matcher: I, follow: &Token)
334334
let tok = if let TtToken(_, ref tok) = *token { tok } else { unreachable!() };
335335
// If T' is in the set FOLLOW(NT), continue. Else, reject.
336336
match (&next_token, is_in_follow(cx, &next_token, frag_spec.as_str())) {
337+
(_, Err(msg)) => {
338+
cx.span_err(sp, &msg);
339+
continue
340+
}
337341
(&Eof, _) => return Some((sp, tok.clone())),
338342
(_, Ok(true)) => continue,
339343
(next, Ok(false)) => {
@@ -343,10 +347,6 @@ fn check_matcher<'a, I>(cx: &mut ExtCtxt, matcher: I, follow: &Token)
343347
token_to_string(next)));
344348
continue
345349
},
346-
(_, Err(msg)) => {
347-
cx.span_err(sp, &msg);
348-
continue
349-
}
350350
}
351351
},
352352
TtSequence(sp, ref seq) => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2015 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+
// Issue #21370
12+
13+
macro_rules! test {
14+
($wrong:t_ty) => () //~ ERROR invalid fragment specifier `t_ty`
15+
}
16+
17+
fn main() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2015 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+
macro_rules! test {
12+
($e:expr +) => () //~ ERROR not allowed for `expr` fragments
13+
}
14+
15+
fn main() { }

0 commit comments

Comments
 (0)