Skip to content

Commit c04e838

Browse files
Rollup merge of rust-lang#33870 - jseyfried:ice-issue-33569, r=pnkfelix
Fix ICE on parsing a bad metavariable in a macro definition Fixes rust-lang#33569, fixes rust-lang#33728. r? @pnkfelix
2 parents 43b430e + 5b82c5f commit c04e838

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

src/libsyntax/parse/parser.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -2702,7 +2702,10 @@ impl<'a> Parser<'a> {
27022702
return Ok(TokenTree::Token(sp, SpecialVarNt(SpecialMacroVar::CrateMacroVar)));
27032703
} else {
27042704
sp = mk_sp(sp.lo, self.span.hi);
2705-
self.parse_ident()?
2705+
self.parse_ident().unwrap_or_else(|mut e| {
2706+
e.emit();
2707+
keywords::Invalid.ident()
2708+
})
27062709
}
27072710
}
27082711
token::SubstNt(name) => {
@@ -2807,14 +2810,14 @@ impl<'a> Parser<'a> {
28072810
let span = Span { hi: close_span.hi, ..pre_span };
28082811

28092812
match self.token {
2810-
// Correct delmiter.
2813+
// Correct delimiter.
28112814
token::CloseDelim(d) if d == delim => {
28122815
self.open_braces.pop().unwrap();
28132816

28142817
// Parse the close delimiter.
28152818
self.bump();
28162819
}
2817-
// Incorect delimiter.
2820+
// Incorrect delimiter.
28182821
token::CloseDelim(other) => {
28192822
let token_str = self.this_token_to_string();
28202823
let mut err = self.diagnostic().struct_span_err(self.span,
@@ -2829,9 +2832,9 @@ impl<'a> Parser<'a> {
28292832

28302833
self.open_braces.pop().unwrap();
28312834

2832-
// If the incorrect delimter matches an earlier opening
2835+
// If the incorrect delimiter matches an earlier opening
28332836
// delimiter, then don't consume it (it can be used to
2834-
// close the earlier one)Otherwise, consume it.
2837+
// close the earlier one). Otherwise, consume it.
28352838
// E.g., we try to recover from:
28362839
// fn foo() {
28372840
// bar(baz(
@@ -2845,7 +2848,7 @@ impl<'a> Parser<'a> {
28452848
// and an error emitted then. Thus we don't pop from
28462849
// self.open_braces here.
28472850
},
2848-
_ => unreachable!(),
2851+
_ => {}
28492852
}
28502853

28512854
Ok(TokenTree::Delimited(span, Rc::new(Delimited {
@@ -2859,7 +2862,7 @@ impl<'a> Parser<'a> {
28592862
// invariants: the current token is not a left-delimiter,
28602863
// not an EOF, and not the desired right-delimiter (if
28612864
// it were, parse_seq_to_before_end would have prevented
2862-
// reaching this point.
2865+
// reaching this point).
28632866
maybe_whole!(deref self, NtTT);
28642867
match self.token {
28652868
token::CloseDelim(_) => {

src/test/parse-fail/issue-33569.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 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+
// compile-flags: -Z no-analysis
12+
13+
macro_rules! foo {
14+
{ $+ } => { //~ ERROR expected identifier, found `+`
15+
$(x)(y) //~ ERROR expected `*` or `+`
16+
//~^ ERROR no rules expected the token `y`
17+
}
18+
}

0 commit comments

Comments
 (0)