Skip to content

Commit 5b82c5f

Browse files
committed
Fix ICE on failure to parse token tree
1 parent 2c93720 commit 5b82c5f

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 5 additions & 2 deletions
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) => {
@@ -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 {

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

Lines changed: 18 additions & 0 deletions
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)