Improve error recovery for some built-in macros

This commit is contained in:
Vadim Petrochenkov
2018-12-30 00:56:55 +03:00
parent 007115746c
commit df4690ddf4
13 changed files with 74 additions and 47 deletions

View File

@@ -18,6 +18,7 @@ pub fn expand_syntax_ext(
};
let mut accumulator = String::new();
let mut missing_literal = vec![];
let mut has_errors = false;
for e in es {
match e.node {
ast::ExprKind::Lit(ref lit) => match lit.node {
@@ -41,6 +42,9 @@ pub fn expand_syntax_ext(
cx.span_err(e.span, "cannot concatenate a byte string literal");
}
},
ast::ExprKind::Err => {
has_errors = true;
}
_ => {
missing_literal.push(e.span);
}
@@ -50,6 +54,9 @@ pub fn expand_syntax_ext(
let mut err = cx.struct_span_err(missing_literal, "expected a literal");
err.note("only literals (like `\"foo\"`, `42` and `3.14`) can be passed to `concat!()`");
err.emit();
return base::DummyResult::expr(sp);
} else if has_errors {
return base::DummyResult::expr(sp);
}
let sp = sp.apply_mark(cx.current_expansion.mark);
base::MacEager::expr(cx.expr_str(sp, Symbol::intern(&accumulator)))