diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2019-11-05 12:08:22 -0800 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2019-11-05 14:06:38 -0800 |
| commit | c271db284bea3882fe033afb1cd4c6f370c69dd5 (patch) | |
| tree | 5f36dcfc5f681ce43f530d77e2a22ada887a50ea /src/libsyntax_ext | |
| parent | 08b235b5bed1a53311da34fa12966cd42a2a5abe (diff) | |
| download | rust-c271db284bea3882fe033afb1cd4c6f370c69dd5.tar.gz rust-c271db284bea3882fe033afb1cd4c6f370c69dd5.zip | |
Provide structured suggestions for valid formatting descriptors
Diffstat (limited to 'src/libsyntax_ext')
| -rw-r--r-- | src/libsyntax_ext/format.rs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index b8d053a2162..b47038397b8 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -256,8 +256,9 @@ impl<'a, 'b> Context<'a, 'b> { "X" => "UpperHex", _ => { let fmtsp = self.fmtsp; + let sp = arg.format.ty_span.map(|sp| fmtsp.from_inner(sp)); let mut err = self.ecx.struct_span_err( - arg.format.ty_span.map(|sp| fmtsp.from_inner(sp)).unwrap_or(fmtsp), + sp.unwrap_or(fmtsp), &format!("unknown format trait `{}`", arg.format.ty), ); err.note("the only appropriate formatting traits are:\n\ @@ -270,6 +271,26 @@ impl<'a, 'b> Context<'a, 'b> { - `b`, which uses the `Binary` trait\n\ - `x`, which uses the `LowerHex` trait\n\ - `X`, which uses the `UpperHex` trait"); + if let Some(sp) = sp { + for (fmt, name) in &[ + ("", "Display"), + ("?", "Debug"), + ("e", "LowerExp"), + ("E", "UpperExp"), + ("o", "Octal"), + ("p", "Pointer"), + ("b", "Binary"), + ("x", "LowerHex"), + ("X", "UpperHex"), + ] { + err.tool_only_span_suggestion( + sp, + &format!("use the `{}` trait", name), + fmt.to_string(), + Applicability::MaybeIncorrect, + ); + } + } err.emit(); "<invalid>" } |
