rust/compiler
Manish Goregaokar d388428aaa
Rollup merge of #89340 - FabianWolff:issue-89173, r=petrochenkov
Improve error message for `printf`-style format strings

Fixes #89173. The following is actually supported today:
```rust
fn main() {
    let num = 5;
    let width = 20;
    print!("%*2$x", num, width);
}
```
```
error: multiple unused formatting arguments
 --> src/main.rs:4:21
  |
4 |     print!("%*2$x", num, width);
  |            -------  ^^^  ^^^^^ argument never used
  |            ||       |
  |            ||       argument never used
  |            |help: format specifiers use curly braces: `{:1$x}`
  |            multiple missing formatting specifiers
  |
  = note: printf formatting not supported; see the documentation for `std::fmt`
```
However, as noted in #89173, something like
```rust
    print!("%0*x", width, num);
```
does not give a helpful suggestion. I think this is partly intended, because there actually _is_ no Rust equivalent to this; you always have to use a positional or named argument to specify the width (instead of just using the "next" argument, as `printf` or even `.*` as a precision specifier in Rust would). Therefore, I have added a note:
```
[...]
note: format specifiers use curly braces, and you have to use a positional or named parameter for the width
 --> t2.rs:4:13
  |
4 |     print!("%0*x", width, num);
  |             ^^^^
  = note: printf formatting not supported; see the documentation for `std::fmt`
```
This is not perfect, but it should at least point the user in the right direction, instead of issuing no explanation at all.

cc ```@lcnr```
2021-10-01 09:18:19 -07:00
..
rustc Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_apfloat Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_arena Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_ast Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_ast_lowering Rollup merge of #89344 - jackh726:maybe-bound-eror, r=cjgillot 2021-09-30 23:41:09 -07:00
rustc_ast_passes Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_ast_pretty Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_attr Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_borrowck Rollup merge of #89327 - oli-obk:nll_diag_infer_vars, r=wesleywiser 2021-09-30 23:41:08 -07:00
rustc_builtin_macros Improve error message for printf-style format strings 2021-09-29 02:02:45 +02:00
rustc_codegen_cranelift Update compiler/rustc_codegen_cranelift/scripts/filter_profile.rs 2021-09-30 19:41:32 +02:00
rustc_codegen_gcc Rebase fallout. 2021-09-30 20:22:42 +02:00
rustc_codegen_llvm Rollup merge of #88820 - hlopko:add_pie_relocation_model, r=petrochenkov 2021-10-01 09:18:16 -07:00
rustc_codegen_ssa Rollup merge of #88820 - hlopko:add_pie_relocation_model, r=petrochenkov 2021-10-01 09:18:16 -07:00
rustc_const_eval CTFE: extra assertions for Aggregate rvalues; remove unnecessarily eager special case 2021-09-29 13:47:41 -04:00
rustc_data_structures More tracing instrumentation 2021-09-28 12:28:22 +00:00
rustc_driver Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_error_codes Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_errors Rollup merge of #89046 - oli-obk:fix_oflo, r=estebank 2021-09-22 19:03:22 +02:00
rustc_expand Improve help for recursion limit errors 2021-09-28 22:17:13 +02:00
rustc_feature Stabilize feature(macro_attributes_in_derive_output) 2021-09-24 21:48:30 +03:00
rustc_fs_util Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_graphviz Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_hir Rollup merge of #89029 - notriddle:notriddle/issue-89013, r=estebank 2021-10-01 09:18:17 -07:00
rustc_hir_pretty Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_incremental Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_index rustc_index: Add some map-like APIs to IndexVec 2021-09-22 03:11:29 +03:00
rustc_infer More tracing instrumentation 2021-09-28 12:28:22 +00:00
rustc_interface Move EncodedMetadata to rustc_metadata. 2021-09-30 19:41:32 +02:00
rustc_lexer Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_lint rustc_session: Remove lint store from Session 2021-09-28 11:56:15 +03:00
rustc_lint_defs Auto merge of #88865 - guswynn:must_not_suspend, r=oli-obk 2021-09-22 06:43:33 +00:00
rustc_llvm PassWrapper: handle function rename from upstream D36850 2021-09-27 18:11:21 -04:00
rustc_macros Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_metadata Move EncodedMetadata to rustc_metadata. 2021-09-30 19:41:32 +02:00
rustc_middle Rollup merge of #87868 - Kixiron:packing-on-the-pounds, r=eddyb 2021-10-01 09:18:16 -07:00
rustc_mir_build Rollup merge of #89314 - notriddle:notriddle/lint-fix-enum-variant-match, r=davidtwco 2021-09-30 18:05:25 -07:00
rustc_mir_dataflow More tracing instrumentation 2021-09-28 12:28:22 +00:00
rustc_mir_transform Rebase resume argument projections during state transform 2021-09-28 14:39:18 +02:00
rustc_monomorphize Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_parse Rollup merge of #89029 - notriddle:notriddle/issue-89013, r=estebank 2021-10-01 09:18:17 -07:00
rustc_parse_format Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_passes Auto merge of #88865 - guswynn:must_not_suspend, r=oli-obk 2021-09-22 06:43:33 +00:00
rustc_plugin_impl Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_privacy Auto merge of #89103 - Mark-Simulacrum:migrate-2021, r=estebank 2021-09-21 19:25:49 +00:00
rustc_query_impl Auto merge of #89120 - In-line:remove_unneded_visible_parents_map, r=estebank 2021-09-24 05:29:49 +00:00
rustc_query_system Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_resolve Auto merge of #89417 - Manishearth:rollup-j2gdu95, r=Manishearth 2021-10-01 09:00:42 +00:00
rustc_save_analysis Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_serialize Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_session Rollup merge of #89322 - tmiasko:rm-optimization-fuel, r=michaelwoerister 2021-10-01 09:18:18 -07:00
rustc_span Rollup merge of #89072 - bjorn3:less_symbol_as_str, r=michaelwoerister 2021-09-24 11:40:12 -07:00
rustc_symbol_mangling Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_target Rollup merge of #88820 - hlopko:add_pie_relocation_model, r=petrochenkov 2021-10-01 09:18:16 -07:00
rustc_trait_selection Improve help for recursion limit errors 2021-09-28 22:17:13 +02:00
rustc_traits Improve cause information for NLL higher-ranked errors 2021-09-27 10:23:45 -05:00
rustc_ty_utils Auto merge of #89144 - sexxi-goose:insig_stdlib, r=nikomatsakis 2021-09-26 19:36:00 +00:00
rustc_type_ir Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_typeck Rollup merge of #89029 - notriddle:notriddle/issue-89013, r=estebank 2021-10-01 09:18:17 -07:00