Skip to content

Commit 5daa753

Browse files
committed
Auto merge of #30654 - nrc:panictry, r=brson
The motivation (other than removing boilerplate) is that this is a baby step towards a parser with error recovery. [breaking-change] if you use any of the changed functions, you'll need to remove a try! or panictry!
2 parents e8c337b + 9023c65 commit 5daa753

File tree

12 files changed

+318
-313
lines changed

12 files changed

+318
-313
lines changed

src/libsyntax/ext/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ pub fn get_exprs_from_tts(cx: &mut ExtCtxt,
826826
let mut es = Vec::new();
827827
while p.token != token::Eof {
828828
es.push(cx.expander().fold_expr(panictry!(p.parse_expr())));
829-
if panictry!(p.eat(&token::Comma)){
829+
if p.eat(&token::Comma) {
830830
continue;
831831
}
832832
if p.token != token::Eof {

src/libsyntax/ext/quote.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ fn parse_arguments_to_quote(cx: &ExtCtxt, tts: &[TokenTree])
801801
p.quote_depth += 1;
802802

803803
let cx_expr = panictry!(p.parse_expr());
804-
if !panictry!(p.eat(&token::Comma)) {
804+
if !p.eat(&token::Comma) {
805805
let _ = p.diagnostic().fatal("expected token `,`");
806806
}
807807

src/libsyntax/ext/tt/macro_parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ pub fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal {
512512
_ => {}
513513
}
514514
// check at the beginning and the parser checks after each bump
515-
panictry!(p.check_unknown_macro_variable());
515+
p.check_unknown_macro_variable();
516516
match name {
517517
"item" => match panictry!(p.parse_item()) {
518518
Some(i) => token::NtItem(i),
@@ -535,7 +535,7 @@ pub fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal {
535535
// this could be handled like a token, since it is one
536536
"ident" => match p.token {
537537
token::Ident(sn,b) => {
538-
panictry!(p.bump());
538+
p.bump();
539539
token::NtIdent(Box::new(Spanned::<Ident>{node: sn, span: p.span}),b)
540540
}
541541
_ => {

src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<'a> ParserAnyMacro<'a> {
4747
fn ensure_complete_parse(&self, allow_semi: bool, context: &str) {
4848
let mut parser = self.parser.borrow_mut();
4949
if allow_semi && parser.token == token::Semi {
50-
panictry!(parser.bump())
50+
parser.bump();
5151
}
5252
if parser.token != token::Eof {
5353
let token_str = parser.this_token_to_string();
@@ -194,7 +194,7 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt,
194194
imported_from,
195195
rhs);
196196
let mut p = Parser::new(cx.parse_sess(), cx.cfg(), Box::new(trncbr));
197-
panictry!(p.check_unknown_macro_variable());
197+
p.check_unknown_macro_variable();
198198
// Let the context choose how to interpret the result.
199199
// Weird, but useful for X-macros.
200200
return Box::new(ParserAnyMacro {

src/libsyntax/parse/attr.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl<'a> Parser<'a> {
3939
return Err(self.fatal("expected outer comment"));
4040
}
4141
attrs.push(attr);
42-
try!(self.bump());
42+
self.bump();
4343
}
4444
_ => break
4545
}
@@ -57,11 +57,11 @@ impl<'a> Parser<'a> {
5757
let (span, value, mut style) = match self.token {
5858
token::Pound => {
5959
let lo = self.span.lo;
60-
try!(self.bump());
60+
self.bump();
6161

6262
if permit_inner { self.expected_tokens.push(TokenType::Token(token::Not)); }
6363
let style = if self.token == token::Not {
64-
try!(self.bump());
64+
self.bump();
6565
if !permit_inner {
6666
let span = self.span;
6767
self.diagnostic().struct_span_err(span,
@@ -91,7 +91,7 @@ impl<'a> Parser<'a> {
9191
};
9292

9393
if permit_inner && self.token == token::Semi {
94-
try!(self.bump());
94+
self.bump();
9595
self.span_warn(span, "this inner attribute syntax is deprecated. \
9696
The new syntax is `#![foo]`, with a bang and no semicolon");
9797
style = ast::AttrStyle::Inner;
@@ -134,7 +134,7 @@ impl<'a> Parser<'a> {
134134
let attr = attr::mk_sugared_doc_attr(attr::mk_attr_id(), str, lo, hi);
135135
if attr.node.style == ast::AttrStyle::Inner {
136136
attrs.push(attr);
137-
try!(self.bump());
137+
self.bump();
138138
} else {
139139
break;
140140
}
@@ -158,7 +158,7 @@ impl<'a> Parser<'a> {
158158

159159
match nt_meta {
160160
Some(meta) => {
161-
try!(self.bump());
161+
self.bump();
162162
return Ok(meta);
163163
}
164164
None => {}
@@ -169,7 +169,7 @@ impl<'a> Parser<'a> {
169169
let name = self.id_to_interned_str(ident);
170170
match self.token {
171171
token::Eq => {
172-
try!(self.bump());
172+
self.bump();
173173
let lit = try!(self.parse_lit());
174174
// FIXME #623 Non-string meta items are not serialized correctly;
175175
// just forbid them for now

src/libsyntax/parse/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ pub fn tts_to_parser<'a>(sess: &'a ParseSess,
261261
cfg: ast::CrateConfig) -> Parser<'a> {
262262
let trdr = lexer::new_tt_reader(&sess.span_diagnostic, None, None, tts);
263263
let mut p = Parser::new(sess, cfg, Box::new(trdr));
264-
panictry!(p.check_unknown_macro_variable());
264+
p.check_unknown_macro_variable();
265265
p
266266
}
267267

0 commit comments

Comments
 (0)