diff options
| author | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2016-11-12 10:38:42 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-11-12 10:38:42 +0200 |
| commit | 048daa62246abc5dd441c34ffd2834cb6e173060 (patch) | |
| tree | a38e3b75c73b28708201e08b37268499879998a8 /src/libsyntax_ext | |
| parent | 5439cb5bdc7557f20a9dbedb57a636da68445440 (diff) | |
| parent | 3c17abc4d955080baa410e9b697bf5be37b0d079 (diff) | |
| download | rust-048daa62246abc5dd441c34ffd2834cb6e173060.tar.gz rust-048daa62246abc5dd441c34ffd2834cb6e173060.zip | |
Rollup merge of #37695 - estebank:unescaped-curly, r=alexcrichton
On fmt string with unescaped `{` note how to escape
On cases of malformed format strings where a `{` hasn't been properly escaped, like `println!("{");`, present a NOTE explaining how to escape the `{` char.
Fix #34300.
Diffstat (limited to 'src/libsyntax_ext')
| -rw-r--r-- | src/libsyntax_ext/format.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index 117bb39f8e7..6eba8baf5b8 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -756,8 +756,12 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, } if !parser.errors.is_empty() { - cx.ecx.span_err(cx.fmtsp, - &format!("invalid format string: {}", parser.errors.remove(0))); + let (err, note) = parser.errors.remove(0); + let mut e = cx.ecx.struct_span_err(cx.fmtsp, &format!("invalid format string: {}", err)); + if let Some(note) = note { + e.note(¬e); + } + e.emit(); return DummyResult::raw_expr(sp); } if !cx.literal.is_empty() { |
