Skip to content

Commit

Permalink
Don't ICE on bad syntax
Browse files Browse the repository at this point in the history
Closes #100
  • Loading branch information
sfackler committed Jan 2, 2017
1 parent 5dadfcd commit e87e95f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
11 changes: 8 additions & 3 deletions phf_macros/src/lib.rs
Expand Up @@ -33,6 +33,7 @@
#![doc(html_root_url="https://docs.rs/phf_macros/0.7.20")]
#![feature(plugin_registrar, quote, rustc_private)]

#[macro_use]
extern crate syntax;
extern crate rustc_plugin;
extern crate phf_shared;
Expand Down Expand Up @@ -66,6 +67,10 @@ use util::{create_map, create_set, create_ordered_map, create_ordered_set};
pub mod util;
mod macros;

mod errors {
pub use syntax::errors::*;
}

#[plugin_registrar]
#[doc(hidden)]
pub fn macro_registrar(reg: &mut Registry) {
Expand Down Expand Up @@ -162,7 +167,7 @@ fn parse_map(cx: &mut ExtCtxt, tts: &[TokenTree]) -> Option<Vec<Entry>> {

let mut bad = false;
while parser.token != Eof {
let key = cx.expander().fold_expr(parser.parse_expr().unwrap());
let key = cx.expander().fold_expr(panictry!(parser.parse_expr()));
let key_contents = parse_key(cx, &*key).unwrap_or_else(|| {
bad = true;
Key::Str(Symbol::intern("").as_str())
Expand All @@ -174,7 +179,7 @@ fn parse_map(cx: &mut ExtCtxt, tts: &[TokenTree]) -> Option<Vec<Entry>> {
return None;
}

let value = parser.parse_expr().unwrap();
let value = panictry!(parser.parse_expr());

entries.push(Entry {
key_contents: key_contents,
Expand Down Expand Up @@ -202,7 +207,7 @@ fn parse_set(cx: &mut ExtCtxt, tts: &[TokenTree]) -> Option<Vec<Entry>> {

let mut bad = false;
while parser.token != Eof {
let key = cx.expander().fold_expr(parser.parse_expr().unwrap());
let key = cx.expander().fold_expr(panictry!(parser.parse_expr()));
let key_contents = parse_key(cx, &*key).unwrap_or_else(|| {
bad = true;
Key::Str(Symbol::intern("").as_str())
Expand Down
8 changes: 8 additions & 0 deletions phf_macros/tests/compile-fail/bad-syntax.rs
@@ -0,0 +1,8 @@
#![feature(plugin)]
#![plugin(phf_macros)]

extern crate phf;

static MAP: phf::Map<u32, u32> = phf_map! {
Signature:: => () //~ ERROR expected identifier, found `=>`
};
5 changes: 5 additions & 0 deletions phf_macros/tests/compiletest.rs
Expand Up @@ -20,3 +20,8 @@ fn run_mode(directory: &'static str, mode: &'static str) {
fn compile_test_unicase() {
run_mode("compile-fail-unicase", "compile-fail");
}

#[test]
fn compile_fail() {
run_mode("compile-fail", "compile-fail");
}

0 comments on commit e87e95f

Please sign in to comment.