rust/src
bors d6734be398 Auto merge of #100996 - m-ou-se:format-args-2, r=estebank
Rewrite and refactor format_args!() builtin macro.

This is a near complete rewrite of `compiler/rustc_builtin_macros/src/format.rs`.

This gets rid of the massive unmaintanable [`Context` struct](76531befc4/compiler/rustc_builtin_macros/src/format.rs (L176-L263)), and splits the macro expansion into three parts:

1. First, `parse_args` will parse the `(literal, arg, arg, name=arg, name=arg)` syntax, but doesn't parse the template (the literal) itself.
2. Second, `make_format_args` will parse the template, the format options, resolve argument references, produce diagnostics, and turn the whole thing into a `FormatArgs` structure.
3. Finally, `expand_parsed_format_args` will turn that `FormatArgs` structure into the expression that the macro expands to.

In other words, the `format_args` builtin macro used to be a hard-to-maintain 'single pass compiler', which I've split into a three phase compiler with a parser/tokenizer (step 1), semantic analysis (step 2), and backend (step 3). (It's compilers all the way down. ^^)

This can serve as a great starting point for https://github.com/rust-lang/rust/issues/99012, which will only need to change the implementation of 3, while leaving step 1 and 2 unchanged.

It also makes https://github.com/rust-lang/compiler-team/issues/541 easier, which could then upgrade the new `FormatArgs` struct to an `ast` node and remove step 3, moving that step to later in the compilation process.

It also fixes a few diagnostics bugs.

This also [significantly reduces](https://gist.github.com/m-ou-se/b67b2d54172c4837a5ab1b26fa3e5284) the amount of generated code for cases with arguments in non-default order without formatting options, like `"{1} {0}"` or `"{a} {}"`, etc.
2022-09-28 01:36:28 +00:00
..
bootstrap fix check_cfg 2022-09-26 10:14:48 +02:00
ci Auto merge of #98483 - dvtkrlbs:bootstrap-dist, r=jyn514 2022-09-24 20:00:51 +00:00
doc Rollup merge of #101997 - cuviper:drop-legacy-pm, r=nikic 2022-09-25 22:06:38 +08:00
etc
librustdoc Rollup merge of #102369 - GuillaumeGomez:results-colors, r=notriddle 2022-09-27 21:42:25 +02:00
llvm-project@670e5f673a
rustdoc-json-types Rustdoc-Json: List impls for primitives 2022-09-26 18:06:48 +01:00
test Auto merge of #100996 - m-ou-se:format-args-2, r=estebank 2022-09-28 01:36:28 +00:00
tools Update cargo 2022-09-27 17:46:42 +01:00
README.md
stage0.json bump stage0 2022-09-26 10:13:46 +02:00
version

This directory contains the source code of the rust project, including:

  • The test suite
  • The bootstrapping build system
  • Various submodules for tools, like cargo, etc.

For more information on how various parts of the compiler work, see the rustc dev guide.