Return original snippet when macro contains invalid syntax

This commit is contained in:
topecongiro 2017-05-24 01:18:15 +09:00
parent 7c8432f05b
commit e3eec44690
3 changed files with 12 additions and 2 deletions

View file

@ -113,14 +113,14 @@ pub fn rewrite_macro(mac: &ast::Mac,
Ok(expr) => { Ok(expr) => {
// Recovered errors. // Recovered errors.
if context.parse_session.span_diagnostic.has_errors() { if context.parse_session.span_diagnostic.has_errors() {
return None; return Some(context.snippet(mac.span));
} }
expr expr
} }
Err(mut e) => { Err(mut e) => {
e.cancel(); e.cancel();
return None; return Some(context.snippet(mac.span));
} }
}; };

View file

@ -78,6 +78,11 @@ fn main() {
// comment // comment
not function like not function like
); );
// #1577
let json = json!({
"foo": "bar",
});
} }
impl X { impl X {

View file

@ -83,6 +83,11 @@ fn main() {
// comment // comment
not function like not function like
); );
// #1577
let json = json!({
"foo": "bar",
});
} }
impl X { impl X {