mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 23:34:48 +00:00
Bail out on recovered errors. (#965)
Closes #915 Closes #930 Closes #931
This commit is contained in:
parent
b0755581ca
commit
9188ec0f7f
19
src/lib.rs
19
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<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());
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -55,3 +55,8 @@ fn main() {
|
||||
impl X {
|
||||
empty_invoc!{}
|
||||
}
|
||||
|
||||
gfx_pipeline!(pipe {
|
||||
vbuf: gfx::VertexBuffer<Vertex> = (),
|
||||
out: gfx::RenderTarget<ColorFormat> = "Target0",
|
||||
});
|
||||
|
@ -58,3 +58,8 @@ fn main() {
|
||||
impl X {
|
||||
empty_invoc!{}
|
||||
}
|
||||
|
||||
gfx_pipeline!(pipe {
|
||||
vbuf: gfx::VertexBuffer<Vertex> = (),
|
||||
out: gfx::RenderTarget<ColorFormat> = "Target0",
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user