diff options
| author | bors <bors@rust-lang.org> | 2018-08-07 22:15:25 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-08-07 22:15:25 +0000 |
| commit | 3f4f18f098183bf60820e4304433c4c4d9cceaaa (patch) | |
| tree | 55ebf9dfc309669e521980d80bf32d2a7675b7f2 /src/libsyntax/ext | |
| parent | e90dc6f80d76c94a5b1b13d464d1de7e18a05d05 (diff) | |
| parent | daa5bd35a8746126a4af014d135ddb8bc442b9e6 (diff) | |
| download | rust-3f4f18f098183bf60820e4304433c4c4d9cceaaa.tar.gz rust-3f4f18f098183bf60820e4304433c4c4d9cceaaa.zip | |
Auto merge of #52397 - estebank:println-comma, r=oli-obk
Suggest comma when writing `println!("{}" a);`
Fix #49370.
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/tt/macro_rules.rs | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index c9ec2c7d1e8..e7e94614ac8 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -174,7 +174,32 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt, } let best_fail_msg = parse_failure_msg(best_fail_tok.expect("ran no matchers")); - cx.span_err(best_fail_spot.substitute_dummy(sp), &best_fail_msg); + let mut err = cx.struct_span_err(best_fail_spot.substitute_dummy(sp), &best_fail_msg); + + // Check whether there's a missing comma in this macro call, like `println!("{}" a);` + if let Some((arg, comma_span)) = arg.add_comma() { + for lhs in lhses { // try each arm's matchers + let lhs_tt = match *lhs { + quoted::TokenTree::Delimited(_, ref delim) => &delim.tts[..], + _ => cx.span_bug(sp, "malformed macro lhs") + }; + match TokenTree::parse(cx, lhs_tt, arg.clone()) { + Success(_) => { + if comma_span == DUMMY_SP { + err.note("you might be missing a comma"); + } else { + err.span_suggestion_short( + comma_span, + "missing comma here", + ",".to_string(), + ); + } + } + _ => {} + } + } + } + err.emit(); cx.trace_macros_diag(); DummyResult::any(sp) } |
