diff --git a/src/lib.rs b/src/lib.rs index f63b2caaa94..0a222428fe1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -378,13 +378,22 @@ fn format_lines(file_map: &mut FileMap, config: &Config) -> FormatReport { report } -fn parse_input(input: Input, parse_session: &ParseSess) -> Result { - match input { +fn parse_input(input: Input, + parse_session: &ParseSess) + -> Result> { + let result = match input { Input::File(file) => parse::parse_crate_from_file(&file, Vec::new(), &parse_session), Input::Text(text) => { parse::parse_crate_from_source_str("stdin".to_owned(), text, Vec::new(), &parse_session) } + }; + + // Bail out if the parser recovered from an error. + if parse_session.span_diagnostic.has_errors() { + return Err(None); } + + result.map_err(|e| Some(e)) } pub fn format_input(input: Input, config: &Config) -> (Summary, FileMap, FormatReport) { @@ -405,8 +414,10 @@ pub fn format_input(input: Input, config: &Config) -> (Summary, FileMap, FormatR let krate = match parse_input(input, &parse_session) { Ok(krate) => krate, - Err(mut diagnostic) => { - diagnostic.emit(); + Err(diagnostic) => { + if let Some(mut diagnostic) = diagnostic { + diagnostic.emit(); + } summary.add_parsing_error(); return (summary, FileMap::new(), FormatReport::new()); } diff --git a/src/macros.rs b/src/macros.rs index 2be271e140b..bd054474608 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -81,13 +81,22 @@ pub fn rewrite_macro(mac: &ast::Mac, if MacroStyle::Braces != style { loop { - expr_vec.push(match parser.parse_expr() { - Ok(expr) => expr, + let expr = match parser.parse_expr() { + Ok(expr) => { + // Recovered errors. + if context.parse_session.span_diagnostic.has_errors() { + return None; + } + + expr + } Err(mut e) => { e.cancel(); return None; } - }); + }; + + expr_vec.push(expr); match parser.token { Token::Eof => break, diff --git a/tests/source/macros.rs b/tests/source/macros.rs index aa0ba0b234e..d04c204186c 100644 --- a/tests/source/macros.rs +++ b/tests/source/macros.rs @@ -55,3 +55,8 @@ fn main() { impl X { empty_invoc!{} } + +gfx_pipeline!(pipe { + vbuf: gfx::VertexBuffer = (), + out: gfx::RenderTarget = "Target0", +}); diff --git a/tests/target/macros.rs b/tests/target/macros.rs index 7099f714144..902dd2e4d9a 100644 --- a/tests/target/macros.rs +++ b/tests/target/macros.rs @@ -58,3 +58,8 @@ fn main() { impl X { empty_invoc!{} } + +gfx_pipeline!(pipe { + vbuf: gfx::VertexBuffer = (), + out: gfx::RenderTarget = "Target0", +});