rust/src/test/run-make
Matthias Krüger 3aa5734a2c
Rollup merge of #100377 - est31:fluent_grepability, r=davidtwco
Replace - with _ in fluent slugs to improve developer workflows

This is a proposal to smoothen the compiler contribution experience in the face of the move to fluent.

## Context

The fluent project has introduced a layer of abstraction to compiler errors. Previously, people would write down error messages directly in the same file the code was located to emit them. Now, there is a slug that connects the code in the compiler to the error message in the ftl file.

You can look at 7ef610c003 to see an example of the changes:

Old:
```Rust
let msg = format!(
    "bounds on `{}` are most likely incorrect, consider instead \
        using `{}` to detect whether a type can be trivially dropped",
    predicate,
    cx.tcx.def_path_str(needs_drop)
);
lint.build(&msg).emit();
```
New (Rust side):
```Rust
lint.build(fluent::lint::drop_trait_constraints)
    .set_arg("predicate", predicate)
    .set_arg("needs_drop", cx.tcx.def_path_str(needs_drop))
    .emit();
```
New (Fluent side):
```fluent
lint-drop-trait-constraints =
    bounds on `{$predicate}` are most likely incorrect, consider instead using `{$needs_drop}` to detect whether a type can be trivially dropped
```

You will note that in the ftl file, the slug is slightly different from the slug in the Rust file: The ftl slug uses `-` (e.g. `lint-drop-trait-constraints`) while the rust slug uses `::` and `_` (e.g. `lint::drop_trait_constraints`). This choice was probably done due to:

* Rust not accepting `-` in identifiers (as it is an operator)
* fluent not supporting the `:` character in slug names (parse error upon attempts)
* all official fluent documentation using `-` instead of `_`

## The problem

The two different types of slugs, one with `-`, and one with `_`, cause difficulties for contributors. Imagine you don't have perfect knowledge of where stuff is in the compiler (i would say this is most people), and you encounter an error for which you think there is something you could improve that is not just a rewording.

So you want to find out where in the compiler's code that error is being emitted. The best way is via grepping.

1. you grep for the message in the compiler's source code. You discover the ftl file and find out the slug for that error.
2. That slug however contains `-` instead of `_`, so you have to manually translate the `-`'s into `_`s, and furthermore either remove the leading module name, or replace the first `-` with a `::`.
3. you do a second grep to get to the emitting location in the compiler's code.

This translation difficulty in step 2 appears also in the other direction when you want to figure out what some code in the compiler is doing and use error messages to help your understanding. Comments and variable names are way less exposed to users so [are more likely going to lie](cc3c5d2700) than error messages.

I think that at least the `-`→`_` translation which makes up most of step 2 can be removed at low cost.

## The solution

If you look closely, the practice of fluent to use `-` is only a stylistic choice and it is not enforced by fluent implementations, neither the playground nor the one the rust compiler uses, that slugs may not contain `_`. Thus, we can in fact migrate the ftl side to `_`. So now we'll have slugs like  `lint_drop_trait_constraints` on the ftl side. You only have to do one replacement now to get to the Rust slug: remove the first `_` and place a `::` in its stead. I would argue that this change is in fact useful as it allows you to control whether you want to look at the rust side of things or the ftl side of things via changing the query string only: with an increased number of translations checked into the repository, grepping for raw slugs will return the slug in many ftl files, so an explicit step to look for the source code is always useful. In the other direction (rust to fluent), you don't need a translation at all any more, as you can just take the final piece of the slug (e.g. `drop_trait_constraints`) and grep for that. The PR also adds enforcement to forbid usage of `_` in slug names. Internal slug names (those leading with a `-`) are exempt from that enforcement.

As another workflow that benefits from this change, people who add new errors don't have to do that `-` conversion either.

| Before/After | Fluent slug | Rust slug (no change) |
|--|--|--|
| Before | `lint-drop-trait-constraints` | `lint::drop_trait_constraints`|
| After | `lint_drop_trait_constraints` | `lint::drop_trait_constraints`|

Note that I've suggested this previously in the translation thread on zulip. I think it's important to think about non-translator contribution impact of fluent. I have certainly plans for more improvements, but this is a good first step.

``@rustbot`` label A-diagnostics
2022-08-15 20:11:34 +02:00
..
const_fn_mir tweak names and output and bless 2022-07-09 07:43:56 -04:00
coverage Diagnose missing make includes 2022-07-28 14:33:29 +02:00
coverage-llvmir Fix coverage-llvmir test on Windows 2022-08-09 12:39:59 +02:00
coverage-reports Diagnose missing make includes 2022-07-28 14:33:29 +02:00
dep-graph Add a test that -Zquery-dep-graph -Zdump-dep-graph works 2021-10-09 08:13:53 -04:00
emit-named-files Add test for --emit TYPE=path 2021-05-28 22:52:59 -07:00
emit-path-unhashed Add test showing different KIND parameters change hash 2021-06-21 17:22:35 -07:00
emit-shared-files Update run-make test front-files from .woff to .woff2 2022-04-21 13:07:21 +02:00
env-dep-info proc_macro: Add API for tracked access to environment variables 2020-07-26 13:37:37 +03:00
export-executable-symbols feat: impl export-executable-symbols 2022-07-25 05:20:23 +00:00
fmt-write-bloat Add test to check for fmt::write bloat. 2020-11-29 11:38:51 +01:00
incr-foreign-head-span Don't use guess_head_span in predicates_of for foreign span 2021-08-27 23:19:49 -05:00
incr-prev-body-beyond-eof test: run-make: skip tests on unsupported platforms 2021-03-28 16:50:56 +01:00
incremental-session-fail Fix incremental-session-fail to work when run as root. 2021-05-29 08:54:51 -07:00
invalid-so Improve error when an .rlib can't be parsed 2021-11-07 15:03:40 +00:00
issue-10971-temps-dir Changing cdylib to staticlib, as the former doesn't work with arm-none-eabi-gcc. 2021-11-10 08:25:35 +01:00
issue-36710 Add -Zunstable-options instead of feature 2021-10-28 23:38:21 +02:00
issue-47384 Add a test for issue 47384 2022-04-18 20:50:56 +01:00
issue-71519 gcc-lld mvp 2021-06-10 17:10:40 +10:00
issue-83112-incr-test-moved-file test: run-make: skip tests on unsupported platforms 2021-03-28 16:50:56 +01:00
issue-85019-moved-src-dir Add --target flag to issue-85019-moved-src-dir 2021-08-15 17:37:26 -05:00
issue-85401-static-mir Refuse to codegen an upstream static. 2022-08-10 18:30:12 +02:00
issue-85441 Run the #85441 regression test on MSVC only 2021-10-02 22:16:23 +03:00
issue-88756-default-output Rename debugging_opts to unstable_opts 2022-07-13 17:47:06 -05:00
issue-96498 Add @feat.00 symbol to symbols.o for COFF 2022-04-28 21:33:23 +01:00
libtest-thread-limit Move/rename lazy::Sync{OnceCell,Lazy} to sync::{Once,Lazy}Lock 2022-06-16 19:54:42 +04:00
llvm-outputs add test for issue #21335 2018-11-26 12:41:43 -05:00
native-link-modifier-bundle adapt native-link-modifier-bundle test to use llvm-nm 2022-07-04 12:33:23 +00:00
native-link-modifier-whole-archive Fix backwards-compatibility check for tests with +whole-archive 2022-08-02 15:47:18 -07:00
pass-linker-flags Lib kind -l link-arg: 2022-07-26 13:55:27 +03:00
pass-linker-flags-from-dep Lib kind -l link-arg: 2022-07-26 13:55:27 +03:00
raw-dylib-alt-calling-convention Fix vectorcall 2022-07-26 14:11:37 -07:00
raw-dylib-c Add test for raw-dylib with an external variable 2022-08-04 12:47:13 -07:00
raw-dylib-link-ordinal Add test for raw-dylib with an external variable 2022-08-04 12:47:13 -07:00
raw-dylib-stdcall-ordinal Enable raw-dylib for binaries 2022-07-22 09:55:14 -07:00
remap-path-prefix-dwarf Properly apply path prefix remapping paths emitted into debuginfo. 2022-05-18 12:19:01 +02:00
rustc-macro-dep-files expand: Stop using nonterminals for passing tokens to attribute and derive macros 2020-07-01 13:13:21 +03:00
rustdoc-scrape-examples-invalid-expr Fix rare ICE during typeck in rustdoc scrape_examples 2021-10-29 13:21:50 -07:00
rustdoc-scrape-examples-multiple Add --scrape-tests flags so rustdoc can scrape examples from tests 2022-02-11 21:48:59 -08:00
rustdoc-scrape-examples-ordering Improve alignment of additional scraped examples, add scrape examples help page 2022-03-27 18:11:50 -07:00
rustdoc-scrape-examples-remap Add test for ordering of examples, simplify with single scrape.mk file 2021-10-08 20:49:05 -07:00
rustdoc-scrape-examples-test Add --scrape-tests flags so rustdoc can scrape examples from tests 2022-02-11 21:48:59 -08:00
rustdoc-scrape-examples-whitespace Include all contents of first line of scraped item 2022-02-01 17:03:22 -08:00
rustdoc-with-out-dir-option Add --out-dir flag for rustdoc 2021-11-30 10:01:14 +08:00
rustdoc-with-output-option Add --out-dir flag for rustdoc 2021-11-30 10:01:14 +08:00
rustdoc-with-short-out-dir-option Add --out-dir flag for rustdoc 2021-11-30 10:01:14 +08:00
static-pie Check for -static-pie support before testing support 2021-11-01 18:38:11 +00:00
thumb-none-cortex-m Provide bootstrap tools with RUSTC in environment 2020-09-20 16:39:13 -04:00
thumb-none-qemu rfc3052: Remove authors field from Cargo manifests 2021-07-29 14:56:05 -07:00
track-path-dep-info add track_path::path fn for proc-macro usage 2021-07-02 07:13:19 +02:00
translation Fix tests 2022-08-12 22:26:08 +02:00
unstable-flag-required Update tests 2021-08-24 11:39:22 -04:00
wasm-abi rustc: Add a new wasm ABI 2021-04-08 08:03:18 -07:00
wasm-custom-section Upgrade Emscripten targets to use upstream LLVM backend 2019-10-16 17:06:48 -07:00
wasm-custom-sections-opt Upgrade Emscripten targets to use upstream LLVM backend 2019-10-16 17:06:48 -07:00
wasm-export-all-symbols Check for the entry kind 2020-01-08 10:05:44 +01:00
wasm-import-module Update tests for extern block linting 2021-01-13 07:49:16 -05:00
wasm-panic-small Use Cell::take in a couple places 2020-04-26 11:50:53 +02:00
wasm-spurious-import Add regression test for a spurious import 2021-08-30 12:54:54 +02:00
wasm-stringify-ints-small Change opt-level from 2 back to 3 2020-01-30 15:40:14 -05:00
wasm-symbols-different-module Fix handling of wasm import modules and names 2019-12-16 14:43:46 -08:00
wasm-symbols-not-exported Upgrade Emscripten targets to use upstream LLVM backend 2019-10-16 17:06:48 -07:00
wasm-symbols-not-imported Upgrade Emscripten targets to use upstream LLVM backend 2019-10-16 17:06:48 -07:00
x86_64-fortanix-unknown-sgx-lvi Stabilize asm! and global_asm! 2021-12-12 11:20:03 +00:00
git_clone_sha1.sh Remove licenses 2018-12-25 21:08:33 -07:00