Bail out on recovered errors. (#965)

Closes #915
Closes #930
Closes #931
This commit is contained in:
Nick Cameron 2016-04-28 07:08:44 +12:00 committed by Marcus Klaas de Vries
parent b0755581ca
commit 9188ec0f7f
4 changed files with 37 additions and 7 deletions

View File

@ -378,13 +378,22 @@ fn format_lines(file_map: &mut FileMap, config: &Config) -> FormatReport {
report
}
fn parse_input(input: Input, parse_session: &ParseSess) -> Result<ast::Crate, DiagnosticBuilder> {
match input {
fn parse_input(input: Input,
parse_session: &ParseSess)
-> Result<ast::Crate, Option<DiagnosticBuilder>> {
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());
}

View File

@ -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,

View File

@ -55,3 +55,8 @@ fn main() {
impl X {
empty_invoc!{}
}
gfx_pipeline!(pipe {
vbuf: gfx::VertexBuffer<Vertex> = (),
out: gfx::RenderTarget<ColorFormat> = "Target0",
});

View File

@ -58,3 +58,8 @@ fn main() {
impl X {
empty_invoc!{}
}
gfx_pipeline!(pipe {
vbuf: gfx::VertexBuffer<Vertex> = (),
out: gfx::RenderTarget<ColorFormat> = "Target0",
});