Improve error recovery for some built-in macros
This commit is contained in:
@@ -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)))
|
||||
|
||||
Reference in New Issue
Block a user