diff options
| author | Mark Simulacrum <mark.simulacrum@gmail.com> | 2018-05-17 13:51:21 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-05-17 13:51:21 -0600 |
| commit | b3734bd78f566dc9c6ddf977fb290c847cccdc9c (patch) | |
| tree | da37d9467374f84dcf56d0b214f1befd21a1f110 /src/libsyntax_ext | |
| parent | 0c0bb18a5b0675f2d7c64efb334ff564104174f4 (diff) | |
| parent | 3f6b3bbace466f4be1311192f335c4c7792a83d2 (diff) | |
| download | rust-b3734bd78f566dc9c6ddf977fb290c847cccdc9c.tar.gz rust-b3734bd78f566dc9c6ddf977fb290c847cccdc9c.zip | |
Rollup merge of #50610 - estebank:fmt-str, r=Kimundi
Improve format string errors
Point at format string position inside the formatting string:
```
error: invalid format string: unmatched `}` found
--> $DIR/format-string-error.rs:21:22
|
LL | let _ = format!("}");
| ^ unmatched `}` in format string
```
Explain that argument names can't start with an underscore:
```
error: invalid format string: invalid argument name `_foo`
--> $DIR/format-string-error.rs:15:23
|
LL | let _ = format!("{_foo}", _foo = 6usize);
| ^^^^ invalid argument name in format string
|
= note: argument names cannot start with an underscore
```
Fix #23476.
The more accurate spans will only be seen when using `format!` directly, when using `println!` the diagnostics machinery makes the span be the entire statement.
Diffstat (limited to 'src/libsyntax_ext')
| -rw-r--r-- | src/libsyntax_ext/format.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index f29cc75664d..b22098408a3 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -767,9 +767,12 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, } if !parser.errors.is_empty() { - 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 { + let err = parser.errors.remove(0); + let sp = cx.fmtsp.from_inner_byte_pos(err.start, err.end); + let mut e = cx.ecx.struct_span_err(sp, &format!("invalid format string: {}", + err.description)); + e.span_label(sp, err.label + " in format string"); + if let Some(note) = err.note { e.note(¬e); } e.emit(); |
