Skip to content

Commit e7d3ae6

Browse files
committed
Make quote plugin use parsing functions which explicitly panic.
Rename parse_* to parse_*_panic, and add parse_attribute_panic.
1 parent 56ba8fe commit e7d3ae6

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

src/libsyntax/ext/quote.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -327,55 +327,55 @@ pub fn expand_quote_expr<'cx>(cx: &'cx mut ExtCtxt,
327327
sp: Span,
328328
tts: &[ast::TokenTree])
329329
-> Box<base::MacResult+'cx> {
330-
let expanded = expand_parse_call(cx, sp, "parse_expr", vec!(), tts);
330+
let expanded = expand_parse_call(cx, sp, "parse_expr_panic", vec!(), tts);
331331
base::MacEager::expr(expanded)
332332
}
333333

334334
pub fn expand_quote_item<'cx>(cx: &mut ExtCtxt,
335335
sp: Span,
336336
tts: &[ast::TokenTree])
337337
-> Box<base::MacResult+'cx> {
338-
let expanded = expand_parse_call(cx, sp, "parse_item", vec!(), tts);
338+
let expanded = expand_parse_call(cx, sp, "parse_item_panic", vec!(), tts);
339339
base::MacEager::expr(expanded)
340340
}
341341

342342
pub fn expand_quote_pat<'cx>(cx: &'cx mut ExtCtxt,
343343
sp: Span,
344344
tts: &[ast::TokenTree])
345345
-> Box<base::MacResult+'cx> {
346-
let expanded = expand_parse_call(cx, sp, "parse_pat", vec!(), tts);
346+
let expanded = expand_parse_call(cx, sp, "parse_pat_panic", vec!(), tts);
347347
base::MacEager::expr(expanded)
348348
}
349349

350350
pub fn expand_quote_arm(cx: &mut ExtCtxt,
351351
sp: Span,
352352
tts: &[ast::TokenTree])
353353
-> Box<base::MacResult+'static> {
354-
let expanded = expand_parse_call(cx, sp, "parse_arm", vec!(), tts);
354+
let expanded = expand_parse_call(cx, sp, "parse_arm_panic", vec!(), tts);
355355
base::MacEager::expr(expanded)
356356
}
357357

358358
pub fn expand_quote_ty(cx: &mut ExtCtxt,
359359
sp: Span,
360360
tts: &[ast::TokenTree])
361361
-> Box<base::MacResult+'static> {
362-
let expanded = expand_parse_call(cx, sp, "parse_ty", vec!(), tts);
362+
let expanded = expand_parse_call(cx, sp, "parse_ty_panic", vec!(), tts);
363363
base::MacEager::expr(expanded)
364364
}
365365

366366
pub fn expand_quote_stmt(cx: &mut ExtCtxt,
367367
sp: Span,
368368
tts: &[ast::TokenTree])
369369
-> Box<base::MacResult+'static> {
370-
let expanded = expand_parse_call(cx, sp, "parse_stmt", vec!(), tts);
370+
let expanded = expand_parse_call(cx, sp, "parse_stmt_panic", vec!(), tts);
371371
base::MacEager::expr(expanded)
372372
}
373373

374374
pub fn expand_quote_attr(cx: &mut ExtCtxt,
375375
sp: Span,
376376
tts: &[ast::TokenTree])
377377
-> Box<base::MacResult+'static> {
378-
let expanded = expand_parse_call(cx, sp, "parse_attribute",
378+
let expanded = expand_parse_call(cx, sp, "parse_attribute_panic",
379379
vec!(cx.expr_bool(sp, true)), tts);
380380

381381
base::MacEager::expr(expanded)

src/libsyntax/parse/attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<'a> Parser<'a> {
5151
///
5252
/// If permit_inner is true, then a leading `!` indicates an inner
5353
/// attribute
54-
fn parse_attribute(&mut self, permit_inner: bool) -> PResult<ast::Attribute> {
54+
pub fn parse_attribute(&mut self, permit_inner: bool) -> PResult<ast::Attribute> {
5555
debug!("parse_attributes: permit_inner={:?} self.token={:?}",
5656
permit_inner, self.token);
5757
let (span, value, mut style) = match self.token {

src/libsyntax/parse/parser.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -360,30 +360,34 @@ impl<'a> Parser<'a> {
360360
// Panicing fns (for now!)
361361
// These functions are used by the quote_*!() syntax extensions, but shouldn't
362362
// be used otherwise.
363-
pub fn parse_expr(&mut self) -> P<Expr> {
363+
pub fn parse_expr_panic(&mut self) -> P<Expr> {
364364
panictry!(self.parse_expr_nopanic())
365365
}
366366

367-
pub fn parse_item(&mut self) -> Option<P<Item>> {
367+
pub fn parse_item_panic(&mut self) -> Option<P<Item>> {
368368
panictry!(self.parse_item_nopanic())
369369
}
370370

371-
pub fn parse_pat(&mut self) -> P<Pat> {
371+
pub fn parse_pat_panic(&mut self) -> P<Pat> {
372372
panictry!(self.parse_pat_nopanic())
373373
}
374374

375-
pub fn parse_arm(&mut self) -> Arm {
375+
pub fn parse_arm_panic(&mut self) -> Arm {
376376
panictry!(self.parse_arm_nopanic())
377377
}
378378

379-
pub fn parse_ty(&mut self) -> P<Ty> {
379+
pub fn parse_ty_panic(&mut self) -> P<Ty> {
380380
panictry!(self.parse_ty_nopanic())
381381
}
382382

383-
pub fn parse_stmt(&mut self) -> Option<P<Stmt>> {
383+
pub fn parse_stmt_panic(&mut self) -> Option<P<Stmt>> {
384384
panictry!(self.parse_stmt_nopanic())
385385
}
386386

387+
pub fn parse_attribute_panic(&mut self, permit_inner: bool) -> ast::Attribute {
388+
panictry!(self.parse_attribute(permit_inner))
389+
}
390+
387391
/// Convert a token to a string using self's reader
388392
pub fn token_to_string(token: &token::Token) -> String {
389393
pprust::token_to_string(token)

src/test/auxiliary/macro_crate_test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn expand_identity(cx: &mut ExtCtxt, _span: Span, tts: &[TokenTree])
5454
// Parse an expression and emit it unchanged.
5555
let mut parser = parse::new_parser_from_tts(cx.parse_sess(),
5656
cx.cfg(), tts.to_vec());
57-
let expr = parser.parse_expr();
57+
let expr = parser.parse_expr_panic();
5858
MacEager::expr(quote_expr!(&mut *cx, $expr))
5959
}
6060

0 commit comments

Comments
 (0)