Skip to content

Commit ffd8cb7

Browse files
committed
Auto merge of #21364 - cmr:fix-ttseq-ice, r=alexcrichton
Closes #21350
2 parents 3bf41da + 2d30f22 commit ffd8cb7

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

src/libsyntax/ext/tt/macro_rules.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -281,19 +281,22 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt,
281281
}
282282

283283
fn check_lhs_nt_follows(cx: &mut ExtCtxt, lhs: &NamedMatch, sp: Span) {
284-
// lhs is going to be like MatchedNonterminal(NtTT(TtDelimited(...))), where
285-
// the entire lhs is those tts.
286-
// if ever we get box/deref patterns, this could turn into an `if let
287-
// &MatchedNonterminal(NtTT(box TtDelimited(...))) = lhs`
288-
let matcher = match lhs {
284+
// lhs is going to be like MatchedNonterminal(NtTT(TtDelimited(...))), where the entire lhs is
285+
// those tts. Or, it can be a "bare sequence", not wrapped in parens.
286+
match lhs {
289287
&MatchedNonterminal(NtTT(ref inner)) => match &**inner {
290-
&TtDelimited(_, ref tts) => tts.tts.as_slice(),
291-
_ => cx.span_bug(sp, "wrong-structured lhs for follow check")
288+
&TtDelimited(_, ref tts) => {
289+
check_matcher(cx, tts.tts.iter(), &Eof);
290+
},
291+
tt @ &TtSequence(..) => {
292+
check_matcher(cx, Some(tt).into_iter(), &Eof);
293+
},
294+
_ => cx.span_bug(sp, "wrong-structured lhs for follow check (didn't find \
295+
a TtDelimited or TtSequence)")
292296
},
293-
_ => cx.span_bug(sp, "wrong-structured lhs for follow check")
297+
_ => cx.span_bug(sp, "wrong-structured lhs for follow check (didn't find a \
298+
MatchedNonterminal)")
294299
};
295-
296-
check_matcher(cx, matcher.iter(), &Eof);
297300
// we don't abort on errors on rejection, the driver will do that for us
298301
// after parsing/expansion. we can report every error in every macro this way.
299302
}

src/test/run-pass/issue-21350.rs

+17
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+
// Make sure that "bare sequences" don't ICE in follow checking
12+
13+
macro_rules! bare {
14+
$($id:expr),+ => ( $($id)+ )
15+
}
16+
17+
fn main() { }

0 commit comments

Comments
 (0)