rust/src/librustdoc
Dylan DPC dc9f6f3243
Rollup merge of #102623 - davidtwco:translation-eager, r=compiler-errors
translation: eager translation

Part of #100717. See [Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.23100717.20lists!/near/295010720) for additional context.

- **Store diagnostic arguments in a `HashMap`**: Eager translation will enable subdiagnostics to be translated multiple times with different arguments - this requires the ability to replace the value of one argument with a new value, which is better suited to a `HashMap` than the previous storage, a `Vec`.
- **Add `AddToDiagnostic::add_to_diagnostic_with`**: `AddToDiagnostic::add_to_diagnostic_with` is similar to the previous `AddToDiagnostic::add_to_diagnostic` but takes a function that can be used by the caller to modify diagnostic messages originating from the subdiagnostic (such as performing translation eagerly). `add_to_diagnostic` now just calls `add_to_diagnostic_with` with an empty closure.
- **Add `DiagnosticMessage::Eager`**: Add variant of `DiagnosticMessage` for eagerly translated messages
(messages in the target language which don't need translated by the emitter during emission). Also adds `eager_subdiagnostic` function which is intended to be invoked by the diagnostic derive for subdiagnostic fields which are marked as needing eager translation.
- **Support `#[subdiagnostic(eager)]`**: Add support for `eager` argument to the `subdiagnostic` attribute which generates a call to `eager_subdiagnostic`.
- **Finish migrating `rustc_query_system`**: Using eager translation, migrate the remaining repeated cycle stack diagnostic.
- **Split formatting initialization and use in diagnostic derives**: Diagnostic derives have previously had to take special care when ordering the generated code so that fields were not used after a move.

  This is unlikely for most fields because a field is either annotated with a subdiagnostic attribute and is thus likely a `Span` and copiable, or is a argument, in which case it is only used once by `set_arg`
anyway.

  However, format strings for code in suggestions can result in fields being used after being moved if not ordered carefully. As a result, the derive currently puts `set_arg` calls last (just before emission), such as:

      let diag = { /* create diagnostic */ };

      diag.span_suggestion_with_style(
          span,
          fluent::crate::slug,
          format!("{}", __binding_0),
          Applicability::Unknown,
          SuggestionStyle::ShowAlways
      );
      /* + other subdiagnostic additions */

      diag.set_arg("foo", __binding_0);
      /* + other `set_arg` calls */

      diag.emit();

  For eager translation, this doesn't work, as the message being translated eagerly can assume that all arguments are available - so arguments _must_ be set first.

  Format strings for suggestion code are now separated into two parts - an initialization line that performs the formatting into a variable, and a usage in the subdiagnostic addition.

  By separating these parts, the initialization can happen before arguments are set, preserving the desired order so that code compiles, while still enabling arguments to be set before subdiagnostics are added.

      let diag = { /* create diagnostic */ };

      let __code_0 = format!("{}", __binding_0);
      /* + other formatting */

      diag.set_arg("foo", __binding_0);
      /* + other `set_arg` calls */

      diag.span_suggestion_with_style(
          span,
          fluent::crate::slug,
          __code_0,
          Applicability::Unknown,
          SuggestionStyle::ShowAlways
      );
      /* + other subdiagnostic additions */

      diag.emit();

- **Remove field ordering logic in diagnostic derive:** Following the approach taken in earlier commits to separate formatting initialization from use in the subdiagnostic derive, simplify the diagnostic derive by removing the field-ordering logic that previously solved this problem.

r? ```@compiler-errors```
2022-10-12 22:13:23 +05:30
..
clean Rollup merge of #102834 - compiler-errors:unnecessary-lift, r=jyn514 2022-10-10 00:09:43 +09:00
doctest Rename TestOptions to GlobalTestOptions 2021-12-12 17:46:19 -08:00
formats Remove -Ztime option. 2022-10-06 15:49:44 +11:00
html rustdoc: remove unneeded .content selector from link colors 2022-10-11 09:22:40 -07:00
json rustdoc: render more cross-crate hrtbs properly 2022-10-05 23:14:15 +02:00
passes Rollup merge of #102623 - davidtwco:translation-eager, r=compiler-errors 2022-10-12 22:13:23 +05:30
theme Correctly handle parens 2022-09-15 13:53:20 +02:00
askama.toml Move back templates into html folder 2022-01-19 11:13:24 +01:00
Cargo.toml Replace rustc_data_structures::thin_vec::ThinVec with thin_vec::ThinVec. 2022-08-29 15:42:13 +10:00
config.rs Simplify CSS parser to check themes 2022-09-14 19:36:03 +02:00
core.rs rustdoc: adopt to the new lint API 2022-10-01 10:03:06 +00:00
docfs.rs Remove crate visibility modifier in libs, tests 2022-05-21 00:32:47 -04:00
doctest.rs Do not panic when a test function returns Result::Err. 2022-09-16 14:36:00 +00:00
error.rs Remove crate visibility modifier in libs, tests 2022-05-21 00:32:47 -04:00
externalfiles.rs Remove crate visibility modifier in libs, tests 2022-05-21 00:32:47 -04:00
fold.rs rustdoc: remove clean::TraitWithExtraInfo 2022-09-27 12:27:04 -07:00
lib.rs rustc_typeck to rustc_hir_analysis 2022-09-27 10:37:23 +02:00
lint.rs Change default lint level of INVALID_HTML_TAGS to warning 2022-10-10 18:28:29 +02:00
markdown.rs Remove crate visibility modifier in libs, tests 2022-05-21 00:32:47 -04:00
README.md rust-lang.github.io/rustc-dev-guide -> rustc-dev-guide.rust-lang.org 2020-03-10 17:08:18 -03:00
scrape_examples.rs separate definitions and HIR owners 2022-09-24 23:21:19 +09:00
theme.rs Correctly handle parens 2022-09-15 13:53:20 +02:00
visit.rs rustdoc: remove clean::TraitWithExtraInfo 2022-09-27 12:27:04 -07:00
visit_ast.rs change AccessLevels representation 2022-09-14 18:11:00 +03:00
visit_lib.rs change AccessLevels representation 2022-09-14 18:11:00 +03:00

For more information about how librustdoc works, see the rustc dev guide.