Skip to content

Commit 3aa5734

Browse files
authored
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 7ef610c 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](cc3c5d2) 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
2 parents 13ff45d + ca16a8d commit 3aa5734

File tree

20 files changed

+443
-384
lines changed

20 files changed

+443
-384
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
borrowck-move-unsized =
1+
borrowck_move_unsized =
22
cannot move a value of type `{$ty}`
33
.label = the size of `{$ty}` cannot be statically determined
44
5-
borrowck-higher-ranked-lifetime-error =
5+
borrowck_higher_ranked_lifetime_error =
66
higher-ranked lifetime error
77
8-
borrowck-could-not-prove =
8+
borrowck_could_not_prove =
99
could not prove `{$predicate}`
1010
11-
borrowck-could-not-normalize =
11+
borrowck_could_not_normalize =
1212
could not normalize `{$value}`
1313
14-
borrowck-higher-ranked-subtype-error =
14+
borrowck_higher_ranked_subtype_error =
1515
higher-ranked subtype error
1616
17-
generic-does-not-live-long-enough =
17+
generic_does_not_live_long_enough =
1818
`{$kind}` does not live long enough
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
builtin-macros-requires-cfg-pattern =
1+
builtin_macros_requires_cfg_pattern =
22
macro requires a cfg-pattern as an argument
33
.label = cfg-pattern required
44
5-
builtin-macros-expected-one-cfg-pattern = expected 1 cfg-pattern
5+
builtin_macros_expected_one_cfg_pattern = expected 1 cfg-pattern
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
const-eval-unstable-in-stable =
1+
const_eval_unstable_in_stable =
22
const-stable function cannot use `#[feature({$gate})]`
3-
.unstable-sugg = if it is not part of the public API, make this function unstably const
4-
.bypass-sugg = otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks
3+
.unstable_sugg = if it is not part of the public API, make this function unstably const
4+
.bypass_sugg = otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks
55
6-
const-eval-thread-local-access =
6+
const_eval_thread_local_access =
77
thread-local statics cannot be accessed at compile-time
88
9-
const-eval-static-access =
9+
const_eval_static_access =
1010
{$kind}s cannot refer to statics
1111
.help = consider extracting the value of the `static` to a `const`, and referring to that
12-
.teach-note = `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable.
13-
.teach-help = To fix this, the value can be extracted to a `const` and then used.
12+
.teach_note = `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable.
13+
.teach_help = To fix this, the value can be extracted to a `const` and then used.
1414
15-
const-eval-raw-ptr-to-int =
15+
const_eval_raw_ptr_to_int =
1616
pointers cannot be cast to integers during const eval
1717
.note = at compile-time, pointers do not have an integer value
1818
.note2 = avoiding this restriction via `transmute`, `union`, or raw pointers leads to compile-time undefined behavior
1919
20-
const-eval-raw-ptr-comparison =
20+
const_eval_raw_ptr_comparison =
2121
pointers cannot be reliably compared during const eval
2222
.note = see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information
2323
24-
const-eval-panic-non-str = argument to `panic!()` in a const context must have type `&str`
24+
const_eval_panic_non_str = argument to `panic!()` in a const context must have type `&str`
2525
26-
const-eval-mut-deref =
26+
const_eval_mut_deref =
2727
mutation through a reference is not allowed in {$kind}s
2828
29-
const-eval-transient-mut-borrow = mutable references are not allowed in {$kind}s
29+
const_eval_transient_mut_borrow = mutable references are not allowed in {$kind}s
3030
31-
const-eval-transient-mut-borrow-raw = raw mutable references are not allowed in {$kind}s
31+
const_eval_transient_mut_borrow_raw = raw mutable references are not allowed in {$kind}s
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
expand-explain-doc-comment-outer =
1+
expand_explain_doc_comment_outer =
22
outer doc comments expand to `#[doc = "..."]`, which is what this macro attempted to match
33
4-
expand-explain-doc-comment-inner =
4+
expand_explain_doc_comment_inner =
55
inner doc comments expand to `#![doc = "..."]`, which is what this macro attempted to match

compiler/rustc_error_messages/locales/en-US/lint.ftl

+163-163
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
parser-struct-literal-body-without-path =
1+
parser_struct_literal_body_without_path =
22
struct literal body without path
33
.suggestion = you might have forgotten to add the struct literal inside the block
44
5-
parser-maybe-report-ambiguous-plus =
5+
parser_maybe_report_ambiguous_plus =
66
ambiguous `+` in a type
77
.suggestion = use parentheses to disambiguate
88
9-
parser-maybe-recover-from-bad-type-plus =
9+
parser_maybe_recover_from_bad_type_plus =
1010
expected a path on the left-hand side of `+`, not `{$ty}`
1111
12-
parser-add-paren = try adding parentheses
12+
parser_add_paren = try adding parentheses
1313
14-
parser-forgot-paren = perhaps you forgot parentheses?
14+
parser_forgot_paren = perhaps you forgot parentheses?
1515
16-
parser-expect-path = expected a path
16+
parser_expect_path = expected a path
1717
18-
parser-maybe-recover-from-bad-qpath-stage-2 =
18+
parser_maybe_recover_from_bad_qpath_stage_2 =
1919
missing angle brackets in associated item path
2020
.suggestion = try: `{$ty}`
2121
22-
parser-incorrect-semicolon =
22+
parser_incorrect_semicolon =
2323
expected item, found `;`
2424
.suggestion = remove this semicolon
2525
.help = {$name} declarations are not followed by a semicolon
2626
27-
parser-incorrect-use-of-await =
27+
parser_incorrect_use_of_await =
2828
incorrect use of `await`
29-
.parentheses-suggestion = `await` is not a method call, remove the parentheses
30-
.postfix-suggestion = `await` is a postfix operation
29+
.parentheses_suggestion = `await` is not a method call, remove the parentheses
30+
.postfix_suggestion = `await` is a postfix operation
3131
32-
parser-in-in-typo =
32+
parser_in_in_typo =
3333
expected iterable, found keyword `in`
3434
.suggestion = remove the duplicated `in`

0 commit comments

Comments
 (0)