about summary refs log tree commit diff
path: root/src/libsyntax/ext/tt
diff options
context:
space:
mode:
authorNick Cameron <ncameron@mozilla.com>2015-12-21 10:00:43 +1300
committerNick Cameron <ncameron@mozilla.com>2015-12-30 14:27:59 +1300
commit95dc7efad0df3640096a48a84c1d7a29044be750 (patch)
tree0d63c8598508c8892f7e8b84c7ecd242371b27b5 /src/libsyntax/ext/tt
parent253a1cefd8a9db926ca2d983dde5234504c86b4b (diff)
use structured errors
Diffstat (limited to 'src/libsyntax/ext/tt')
-rw-r--r--src/libsyntax/ext/tt/macro_parser.rs32
-rw-r--r--src/libsyntax/ext/tt/macro_rules.rs11
2 files changed, 28 insertions, 15 deletions
diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs
index fb09118035c..166d32a8cc6 100644
--- a/src/libsyntax/ext/tt/macro_parser.rs
+++ b/src/libsyntax/ext/tt/macro_parser.rs
@@ -82,6 +82,7 @@ use ast;
 use ast::{TokenTree, Name, Ident};
 use codemap::{BytePos, mk_sp, Span, Spanned};
 use codemap;
+use errors::FatalError;
 use parse::lexer::*; //resolve bug?
 use parse::ParseSess;
 use parse::parser::{LifetimeAndTypesWithoutColons, Parser};
@@ -499,11 +500,12 @@ pub fn parse(sess: &ParseSess,
     }
 }
 
-pub fn parse_nt(p: &mut Parser, sp: Span, name: &str) -> Nonterminal {
+pub fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal {
     match name {
         "tt" => {
             p.quote_depth += 1; //but in theory, non-quoted tts might be useful
-            let res = token::NtTT(P(panictry!(p.parse_token_tree())));
+            let res: ::parse::PResult<'a, _> = p.parse_token_tree();
+            let res = token::NtTT(P(panictry!(res)));
             p.quote_depth -= 1;
             return res;
         }
@@ -514,12 +516,18 @@ pub fn parse_nt(p: &mut Parser, sp: Span, name: &str) -> Nonterminal {
     match name {
         "item" => match panictry!(p.parse_item()) {
             Some(i) => token::NtItem(i),
-            None => panic!(p.fatal("expected an item keyword"))
+            None => {
+                p.fatal("expected an item keyword").emit();
+                panic!(FatalError);
+            }
         },
         "block" => token::NtBlock(panictry!(p.parse_block())),
         "stmt" => match panictry!(p.parse_stmt()) {
             Some(s) => token::NtStmt(s),
-            None => panic!(p.fatal("expected a statement"))
+            None => {
+                p.fatal("expected a statement").emit();
+                panic!(FatalError);
+            }
         },
         "pat" => token::NtPat(panictry!(p.parse_pat())),
         "expr" => token::NtExpr(panictry!(p.parse_expr())),
@@ -532,8 +540,9 @@ pub fn parse_nt(p: &mut Parser, sp: Span, name: &str) -> Nonterminal {
             }
             _ => {
                 let token_str = pprust::token_to_string(&p.token);
-                panic!(p.fatal(&format!("expected ident, found {}",
-                                 &token_str[..])))
+                p.fatal(&format!("expected ident, found {}",
+                                 &token_str[..])).emit();
+                panic!(FatalError)
             }
         },
         "path" => {
@@ -541,11 +550,12 @@ pub fn parse_nt(p: &mut Parser, sp: Span, name: &str) -> Nonterminal {
         },
         "meta" => token::NtMeta(panictry!(p.parse_meta_item())),
         _ => {
-            panic!(p.span_fatal_help(sp,
-                            &format!("invalid fragment specifier `{}`", name),
-                            "valid fragment specifiers are `ident`, `block`, \
-                             `stmt`, `expr`, `pat`, `ty`, `path`, `meta`, `tt` \
-                             and `item`"))
+            p.span_fatal_help(sp,
+                              &format!("invalid fragment specifier `{}`", name),
+                              "valid fragment specifiers are `ident`, `block`, \
+                               `stmt`, `expr`, `pat`, `ty`, `path`, `meta`, `tt` \
+                               and `item`").emit();
+            panic!(FatalError);
         }
     }
 }
diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs
index fae60d28032..fd0bbf7a072 100644
--- a/src/libsyntax/ext/tt/macro_rules.rs
+++ b/src/libsyntax/ext/tt/macro_rules.rs
@@ -55,12 +55,12 @@ impl<'a> ParserAnyMacro<'a> {
                                following",
                               token_str);
             let span = parser.span;
-            parser.span_err(span, &msg[..]);
-
+            let mut err = parser.diagnostic().struct_span_err(span, &msg[..]);
             let msg = format!("caused by the macro expansion here; the usage \
                                of `{}!` is likely invalid in {} context",
                                self.macro_ident, context);
-            parser.span_note(self.site_span, &msg[..]);
+            err.span_note(self.site_span, &msg[..])
+               .emit();
         }
     }
 }
@@ -111,7 +111,10 @@ impl<'a> MacResult for ParserAnyMacro<'a> {
                         Some(stmt) => ret.push(stmt),
                         None => (),
                     },
-                    Err(_) => break,
+                    Err(mut e) => {
+                        e.emit();
+                        break;
+                    }
                 }
             }
         }