Skip to content

Commit 04badd6

Browse files
committed
Auto merge of #27253 - bossmc:unbalanced-delimiters-cause-ice, r=nikomatsakis
This introduces a test for #23389 and improves the error behaviour to treat the malformed LHS as an error, not a compiler bug. The parse phase that precedes the call to `check_lhs_nt_follows` could possibly be enhanced to police the format itself (which the old code suggests was the original intention), but I'm not sure that's any nicer than just parsing the matcher as generic rust code and then policing the specific requirements for being a macro matcher afterwards (as this does). Fixes #23389
2 parents f0b7ede + 93dd75a commit 04badd6

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/libsyntax/ext/tt/macro_rules.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ fn check_lhs_nt_follows(cx: &mut ExtCtxt, lhs: &NamedMatch, sp: Span) {
302302
tt @ &TtSequence(..) => {
303303
check_matcher(cx, Some(tt).into_iter(), &Eof);
304304
},
305-
_ => cx.span_bug(sp, "wrong-structured lhs for follow check (didn't find \
306-
a TtDelimited or TtSequence)")
305+
_ => cx.span_err(sp, "Invalid macro matcher; matchers must be contained \
306+
in balanced delimiters or a repetition indicator")
307307
},
308308
_ => cx.span_bug(sp, "wrong-structured lhs for follow check (didn't find a \
309309
MatchedNonterminal)")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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! invalid {
12+
_ => (); //~^ ERROR Invalid macro matcher
13+
}
14+
15+
fn main() {
16+
}

0 commit comments

Comments
 (0)