Skip to content

Commit 1dd87dc

Browse files
committed
Don't use panicking helpers in Parser.
1 parent f717249 commit 1dd87dc

File tree

9 files changed

+26
-25
lines changed

9 files changed

+26
-25
lines changed

src/libsyntax/ext/asm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
7979
cx.span_err(sp, "malformed inline assembly");
8080
return DummyResult::expr(sp);
8181
}
82-
let (s, style) = match expr_to_string(cx, p.parse_expr(),
82+
let (s, style) = match expr_to_string(cx, panictry!(p.parse_expr_nopanic()),
8383
"inline assembly must be a string literal") {
8484
Some((s, st)) => (s, st),
8585
// let compilation continue
@@ -102,7 +102,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
102102
let span = p.last_span;
103103

104104
panictry!(p.expect(&token::OpenDelim(token::Paren)));
105-
let out = p.parse_expr();
105+
let out = panictry!(p.parse_expr_nopanic());
106106
panictry!(p.expect(&token::CloseDelim(token::Paren)));
107107

108108
// Expands a read+write operand into two operands.
@@ -146,7 +146,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
146146
}
147147

148148
panictry!(p.expect(&token::OpenDelim(token::Paren)));
149-
let input = p.parse_expr();
149+
let input = panictry!(p.parse_expr_nopanic());
150150
panictry!(p.expect(&token::CloseDelim(token::Paren)));
151151

152152
inputs.push((constraint, input));

src/libsyntax/ext/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ pub fn get_single_str_from_tts(cx: &mut ExtCtxt,
809809
cx.span_err(sp, &format!("{} takes 1 argument", name));
810810
return None
811811
}
812-
let ret = cx.expander().fold_expr(p.parse_expr());
812+
let ret = cx.expander().fold_expr(panictry!(p.parse_expr_nopanic()));
813813
if p.token != token::Eof {
814814
cx.span_err(sp, &format!("{} takes 1 argument", name));
815815
}
@@ -826,7 +826,7 @@ pub fn get_exprs_from_tts(cx: &mut ExtCtxt,
826826
let mut p = cx.new_parser_from_tts(tts);
827827
let mut es = Vec::new();
828828
while p.token != token::Eof {
829-
es.push(cx.expander().fold_expr(p.parse_expr()));
829+
es.push(cx.expander().fold_expr(panictry!(p.parse_expr_nopanic())));
830830
if panictry!(p.eat(&token::Comma)){
831831
continue;
832832
}

src/libsyntax/ext/format.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fn parse_args(ecx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
9393
ecx.span_err(sp, "requires at least a format string argument");
9494
return None;
9595
}
96-
let fmtstr = p.parse_expr();
96+
let fmtstr = panictry!(p.parse_expr_nopanic());
9797
let mut named = false;
9898
while p.token != token::Eof {
9999
if !panictry!(p.eat(&token::Comma)) {
@@ -124,7 +124,7 @@ fn parse_args(ecx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
124124
let name: &str = &ident.name.as_str();
125125

126126
panictry!(p.expect(&token::Eq));
127-
let e = p.parse_expr();
127+
let e = panictry!(p.parse_expr_nopanic());
128128
match names.get(name) {
129129
None => {}
130130
Some(prev) => {
@@ -138,7 +138,7 @@ fn parse_args(ecx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
138138
order.push(name.to_string());
139139
names.insert(name.to_string(), e);
140140
} else {
141-
args.push(p.parse_expr());
141+
args.push(panictry!(p.parse_expr_nopanic()));
142142
}
143143
}
144144
Some((fmtstr, args, order, names))

src/libsyntax/ext/quote.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ fn parse_arguments_to_quote(cx: &ExtCtxt, tts: &[ast::TokenTree])
694694
let mut p = cx.new_parser_from_tts(tts);
695695
p.quote_depth += 1;
696696

697-
let cx_expr = p.parse_expr();
697+
let cx_expr = panictry!(p.parse_expr_nopanic());
698698
if !panictry!(p.eat(&token::Comma)) {
699699
panic!(p.fatal("expected token `,`"));
700700
}

src/libsyntax/ext/source_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree
109109
}
110110
impl<'a> base::MacResult for ExpandResult<'a> {
111111
fn make_expr(mut self: Box<ExpandResult<'a>>) -> Option<P<ast::Expr>> {
112-
Some(self.p.parse_expr())
112+
Some(panictry!(self.p.parse_expr_nopanic()))
113113
}
114114
fn make_items(mut self: Box<ExpandResult<'a>>)
115115
-> Option<SmallVector<P<ast::Item>>> {
116116
let mut ret = SmallVector::zero();
117117
while self.p.token != token::Eof {
118-
match self.p.parse_item() {
118+
match panictry!(self.p.parse_item_nopanic()) {
119119
Some(item) => ret.push(item),
120120
None => panic!(self.p.span_fatal(
121121
self.p.span,

src/libsyntax/ext/tt/macro_parser.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -503,18 +503,18 @@ pub fn parse_nt(p: &mut Parser, sp: Span, name: &str) -> Nonterminal {
503503
// check at the beginning and the parser checks after each bump
504504
panictry!(p.check_unknown_macro_variable());
505505
match name {
506-
"item" => match p.parse_item() {
506+
"item" => match panictry!(p.parse_item_nopanic()) {
507507
Some(i) => token::NtItem(i),
508508
None => panic!(p.fatal("expected an item keyword"))
509509
},
510510
"block" => token::NtBlock(panictry!(p.parse_block())),
511-
"stmt" => match p.parse_stmt() {
511+
"stmt" => match panictry!(p.parse_stmt_nopanic()) {
512512
Some(s) => token::NtStmt(s),
513513
None => panic!(p.fatal("expected a statement"))
514514
},
515-
"pat" => token::NtPat(p.parse_pat()),
516-
"expr" => token::NtExpr(p.parse_expr()),
517-
"ty" => token::NtTy(p.parse_ty()),
515+
"pat" => token::NtPat(panictry!(p.parse_pat_nopanic())),
516+
"expr" => token::NtExpr(panictry!(p.parse_expr_nopanic())),
517+
"ty" => token::NtTy(panictry!(p.parse_ty_nopanic())),
518518
// this could be handled like a token, since it is one
519519
"ident" => match p.token {
520520
token::Ident(sn,b) => { panictry!(p.bump()); token::NtIdent(Box::new(sn),b) }

src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,18 @@ impl<'a> ParserAnyMacro<'a> {
6666

6767
impl<'a> MacResult for ParserAnyMacro<'a> {
6868
fn make_expr(self: Box<ParserAnyMacro<'a>>) -> Option<P<ast::Expr>> {
69-
let ret = self.parser.borrow_mut().parse_expr();
69+
let ret = panictry!(self.parser.borrow_mut().parse_expr_nopanic());
7070
self.ensure_complete_parse(true);
7171
Some(ret)
7272
}
7373
fn make_pat(self: Box<ParserAnyMacro<'a>>) -> Option<P<ast::Pat>> {
74-
let ret = self.parser.borrow_mut().parse_pat();
74+
let ret = panictry!(self.parser.borrow_mut().parse_pat_nopanic());
7575
self.ensure_complete_parse(false);
7676
Some(ret)
7777
}
7878
fn make_items(self: Box<ParserAnyMacro<'a>>) -> Option<SmallVector<P<ast::Item>>> {
7979
let mut ret = SmallVector::zero();
80-
while let Some(item) = self.parser.borrow_mut().parse_item() {
80+
while let Some(item) = panictry!(self.parser.borrow_mut().parse_item_nopanic()) {
8181
ret.push(item);
8282
}
8383
self.ensure_complete_parse(false);
@@ -119,7 +119,7 @@ impl<'a> MacResult for ParserAnyMacro<'a> {
119119
}
120120

121121
fn make_ty(self: Box<ParserAnyMacro<'a>>) -> Option<P<ast::Ty>> {
122-
let ret = self.parser.borrow_mut().parse_ty();
122+
let ret = panictry!(self.parser.borrow_mut().parse_ty_nopanic());
123123
self.ensure_complete_parse(true);
124124
Some(ret)
125125
}

src/libsyntax/parse/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub fn parse_expr_from_source_str(name: String,
116116
sess: &ParseSess)
117117
-> P<ast::Expr> {
118118
let mut p = new_parser_from_source_str(sess, cfg, name, source);
119-
maybe_aborted(p.parse_expr(), p)
119+
maybe_aborted(panictry!(p.parse_expr_nopanic()), p)
120120
}
121121

122122
pub fn parse_item_from_source_str(name: String,
@@ -125,7 +125,7 @@ pub fn parse_item_from_source_str(name: String,
125125
sess: &ParseSess)
126126
-> Option<P<ast::Item>> {
127127
let mut p = new_parser_from_source_str(sess, cfg, name, source);
128-
maybe_aborted(p.parse_item(),p)
128+
maybe_aborted(panictry!(p.parse_item_nopanic()), p)
129129
}
130130

131131
pub fn parse_meta_from_source_str(name: String,
@@ -134,7 +134,7 @@ pub fn parse_meta_from_source_str(name: String,
134134
sess: &ParseSess)
135135
-> P<ast::MetaItem> {
136136
let mut p = new_parser_from_source_str(sess, cfg, name, source);
137-
maybe_aborted(p.parse_meta_item(),p)
137+
maybe_aborted(p.parse_meta_item(), p)
138138
}
139139

140140
pub fn parse_stmt_from_source_str(name: String,
@@ -148,7 +148,7 @@ pub fn parse_stmt_from_source_str(name: String,
148148
name,
149149
source
150150
);
151-
maybe_aborted(p.parse_stmt(), p)
151+
maybe_aborted(panictry!(p.parse_stmt_nopanic()), p)
152152
}
153153

154154
// Warning: This parses with quote_depth > 0, which is not the default.

src/libsyntax/parse/parser.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,8 @@ impl<'a> Parser<'a> {
359359
}
360360

361361
// Panicing fns (for now!)
362-
// This is so that the quote_*!() syntax extensions
362+
// These functions are used by the quote_*!() syntax extensions, but shouldn't
363+
// be used otherwise.
363364
pub fn parse_expr(&mut self) -> P<Expr> {
364365
panictry!(self.parse_expr_nopanic())
365366
}

0 commit comments

Comments
 (0)