Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 80b1044

Browse files
committedApr 17, 2024
Make lint messages translatable
1 parent 1fffcf3 commit 80b1044

File tree

2 files changed

+117
-85
lines changed

2 files changed

+117
-85
lines changed
 

‎compiler/rustc_lint/messages.ftl

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
lint_abs_path_with_module =
2+
absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
3+
4+
lint_ambiguous_glob_reexport = ambiguous glob re-exports
5+
16
lint_ambiguous_wide_pointer_comparisons = ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
27
.addr_metadata_suggestion = use explicit `std::ptr::eq` method to compare metadata and addresses
38
.addr_suggestion = use `std::ptr::addr_eq` or untyped pointers to only compare their addresses
@@ -26,10 +31,19 @@ lint_atomic_ordering_load = atomic loads cannot have `Release` or `AcqRel` order
2631
lint_atomic_ordering_store = atomic stores cannot have `Acquire` or `AcqRel` ordering
2732
.help = consider using ordering modes `Release`, `SeqCst` or `Relaxed`
2833
34+
lint_avoid_att_syntax =
35+
avoid using `.att_syntax`, prefer using `options(att_syntax)` instead
36+
37+
lint_avoid_intel_syntax =
38+
avoid using `.intel_syntax`, Intel syntax is the default
39+
2940
lint_bad_attribute_argument = bad attribute argument
3041
3142
lint_bad_opt_access = {$msg}
3243
44+
lint_break_with_label_and_loop =
45+
this labeled break expression is easy to confuse with an unlabeled break with a labeled value expression
46+
3347
lint_builtin_allow_internal_unsafe =
3448
`allow_internal_unsafe` allows defining macros using unsafe without triggering the `unsafe_code` lint at their call site
3549
@@ -184,6 +198,8 @@ lint_cstring_ptr = getting the inner pointer of a temporary `CString`
184198
.note = pointers do not have a lifetime; when calling `as_ptr` the `CString` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
185199
.help = for more information, see https://doc.rust-lang.org/reference/destructors.html
186200
201+
lint_custom_inner_attribute_unstable = custom inner attributes are unstable
202+
187203
lint_default_hash_types = prefer `{$preferred}` over `{$used}`, it has better performance
188204
.note = a `use rustc_data_structures::fx::{$preferred}` may be necessary
189205
@@ -214,6 +230,11 @@ lint_dropping_references = calls to `std::mem::drop` with a reference instead of
214230
.label = argument has type `{$arg_ty}`
215231
.note = use `let _ = ...` to ignore the expression or result
216232
233+
lint_duplicate_macro_attribute =
234+
duplicated attribute
235+
236+
lint_elided_lifetime_not_allowed = `'_` cannot be used here
237+
217238
lint_enum_intrinsics_mem_discriminant =
218239
the return value of `mem::discriminant` is unspecified when called with a non-enum type
219240
.note = the argument to `discriminant` should be a reference to an enum, but it was passed a reference to a `{$ty_param}`, which is not an enum.
@@ -226,6 +247,8 @@ lint_expectation = this lint expectation is unfulfilled
226247
.note = the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message
227248
.rationale = {$rationale}
228249
250+
lint_extern_crate_not_idiomatic = `extern crate` is not idiomatic in the new edition
251+
229252
lint_extern_without_abi = extern declarations without an explicit ABI are deprecated
230253
231254
lint_for_loops_over_fallibles =
@@ -242,6 +265,10 @@ lint_forgetting_references = calls to `std::mem::forget` with a reference instea
242265
.label = argument has type `{$arg_ty}`
243266
.note = use `let _ = ...` to ignore the expression or result
244267
268+
lint_hidden_glob_reexport = private item shadows public glob re-export
269+
270+
lint_hidden_lifetime_parameters = hidden lifetime parameters in types are deprecated
271+
245272
lint_hidden_unicode_codepoints = unicode codepoint changing visible direction of text present in {$label}
246273
.label = this {$label} contains {$count ->
247274
[one] an invisible
@@ -342,6 +369,13 @@ lint_improper_ctypes_union_layout_help = consider adding a `#[repr(C)]` or `#[re
342369
lint_improper_ctypes_union_layout_reason = this union has unspecified layout
343370
lint_improper_ctypes_union_non_exhaustive = this union is non-exhaustive
344371
372+
lint_incomplete_include =
373+
include macro expected single expression in source
374+
375+
lint_inner_macro_attribute_unstable = inner macro attributes are unstable
376+
377+
lint_invalid_crate_type_value = invalid `crate_type` value
378+
345379
# FIXME: we should ordinalize $valid_up_to when we add support for doing so
346380
lint_invalid_from_utf8_checked = calls to `{$method}` with a invalid literal always return an error
347381
.label = the literal was valid UTF-8 up to the {$valid_up_to} bytes
@@ -370,9 +404,18 @@ lint_invalid_reference_casting_note_book = for more information, visit <https://
370404
371405
lint_invalid_reference_casting_note_ty_has_interior_mutability = even for types with interior mutability, the only legal way to obtain a mutable pointer from a shared reference is through `UnsafeCell::get`
372406
407+
lint_legacy_derive_helpers =
408+
derive helper attribute is used before it is introduced
409+
373410
lint_lintpass_by_hand = implementing `LintPass` by hand
374411
.help = try using `declare_lint_pass!` or `impl_lint_pass!` instead
375412
413+
lint_macro_expanded_macro_exports_accessed_by_absolute_paths =
414+
macro-expanded `macro_export` macros from the current crate cannot be referred to by absolute paths
415+
416+
lint_macro_use_deprecated =
417+
deprecated `#[macro_use]` attribute used to import macros should be replaced at use sites with a `use` item to import the macro instead
418+
376419
lint_malformed_attribute = malformed lint attribute input
377420
378421
lint_map_unit_fn = `Iterator::map` call that discard the iterator's values
@@ -382,6 +425,8 @@ lint_map_unit_fn = `Iterator::map` call that discard the iterator's values
382425
.map_label = after this call to map, the resulting iterator is `impl Iterator<Item = ()>`, which means the only information carried by the iterator is the number of items
383426
.suggestion = you might have meant to use `Iterator::for_each`
384427
428+
lint_missing_fragment_specifier = missing fragment specifier
429+
385430
lint_mixed_script_confusables =
386431
the usage of Script Group `{$set}` in this crate consists solely of mixed script confusables
387432
.includes_note = the usage includes {$includes}
@@ -498,6 +543,9 @@ lint_opaque_hidden_inferred_bound = opaque type `{$ty}` does not satisfy its ass
498543
499544
lint_opaque_hidden_inferred_bound_sugg = add this bound
500545
546+
lint_or_patterns_back_compat =
547+
the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro
548+
501549
lint_overflowing_bin_hex = literal out of range for `{$ty}`
502550
.negative_note = the literal `{$lit}` (decimal `{$dec}`) does not fit into the type `{$ty}`
503551
.negative_becomes_note = and the value `-{$lit}` will become `{$actually}{$ty}`
@@ -533,6 +581,8 @@ lint_pattern_in_bodiless = patterns aren't allowed in functions without bodies
533581
lint_pattern_in_foreign = patterns aren't allowed in foreign function declarations
534582
.label = pattern not allowed in foreign function
535583
584+
lint_proc_macro_back_compat_rental = using an old version of `rental`
585+
536586
lint_ptr_null_checks_fn_ptr = function pointers are not nullable, so checking them for null will always return false
537587
.help = wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
538588
.label = expression has type `{$orig_ty}`
@@ -564,6 +614,8 @@ lint_redundant_semicolons =
564614
*[false] this semicolon
565615
}
566616
617+
lint_reference_without_lifetime_not_allowed = `&` without an explicit lifetime name cannot be used here
618+
567619
lint_removed_lint = lint `{$name}` has been removed: {$reason}
568620
569621
lint_renamed_lint = lint `{$name}` has been renamed to `{$replace}`
@@ -585,6 +637,9 @@ lint_suspicious_double_ref_clone =
585637
lint_suspicious_double_ref_deref =
586638
using `.deref()` on a double reference, which returns `{$ty}` instead of dereferencing the inner type
587639
640+
lint_trailing_semi_macro =
641+
trailing semicolon in macro used in expression position
642+
588643
lint_ty_qualified = usage of qualified `ty::{$ty}`
589644
.suggestion = try importing it and using it unqualified
590645
@@ -601,9 +656,14 @@ lint_undropped_manually_drops = calls to `std::mem::drop` with `std::mem::Manual
601656
lint_ungated_async_fn_track_caller = `#[track_caller]` on async functions is a no-op
602657
.label = this function will not propagate the caller location
603658
659+
lint_unicode_text_flow =
660+
unicode codepoint changing visible direction of text present in comment
661+
604662
lint_unit_bindings = binding has unit type `()`
605663
.label = this pattern is inferred to be the unit type `()`
606664
665+
lint_unknown_diagnostic_attribute = unknown diagnostic attribute
666+
607667
lint_unknown_gated_lint =
608668
unknown lint: `{$name}`
609669
.note = the `{$name}` lint is unstable
@@ -624,6 +684,8 @@ lint_unknown_tool_in_scoped_lint = unknown tool name `{$tool_name}` found in sco
624684
625685
lint_unnameable_test_items = cannot test inner items
626686
687+
lint_unnecessary_qualification = unnecessary qualification
688+
627689
lint_unsupported_group = `{$lint_group}` lint group is not supported with ´--force-warn´
628690
629691
lint_untranslatable_diag = diagnostics should be created using translatable messages
@@ -653,8 +715,14 @@ lint_unused_def = unused {$pre}`{$def}`{$post} that must be used
653715
lint_unused_delim = unnecessary {$delim} around {$item}
654716
.suggestion = remove these {$delim}
655717
718+
lint_unused_doc_comment = unused doc comment
719+
656720
lint_unused_import_braces = braces around {$node} is unnecessary
657721
722+
lint_unused_label = unused label
723+
724+
lint_unused_macro_use = unused `#[macro_use]` import
725+
658726
lint_unused_op = unused {$op} that must be used
659727
.label = the {$op} produces a value
660728
.suggestion = use `let _ = ...` to ignore the resulting value

‎compiler/rustc_lint/src/context/diagnostics.rs

Lines changed: 49 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ use rustc_span::BytePos;
1111

1212
use std::fmt::Write;
1313

14+
use crate::fluent_generated as fluent;
15+
1416
mod check_cfg;
1517

1618
#[cfg(test)]
@@ -384,23 +386,17 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiag, diag: &mut Di
384386

385387
pub(super) fn builtin_message(diagnostic: &BuiltinLintDiag) -> DiagMessage {
386388
match diagnostic {
387-
BuiltinLintDiag::AbsPathWithModule(_) => {
388-
"absolute paths must start with `self`, `super`, `crate`, or an \
389-
external crate name in the 2018 edition"
390-
.into()
391-
}
389+
BuiltinLintDiag::AbsPathWithModule(_) => fluent::lint_abs_path_with_module,
392390
BuiltinLintDiag::ProcMacroDeriveResolutionFallback { ns, ident, .. } => {
393391
format!("cannot find {} `{}` in this scope", ns.descr(), ident).into()
394392
}
395393
BuiltinLintDiag::MacroExpandedMacroExportsAccessedByAbsolutePaths(_) => {
396-
"macro-expanded `macro_export` macros from the current crate cannot \
397-
be referred to by absolute paths"
398-
.into()
394+
fluent::lint_macro_expanded_macro_exports_accessed_by_absolute_paths
399395
}
400396
BuiltinLintDiag::ElidedLifetimesInPaths(_, _, _, _) => {
401-
"hidden lifetime parameters in types are deprecated".into()
397+
fluent::lint_hidden_lifetime_parameters
402398
}
403-
BuiltinLintDiag::UnknownCrateTypes(_, _, _) => "invalid `crate_type` value".into(),
399+
BuiltinLintDiag::UnknownCrateTypes(_, _, _) => fluent::lint_invalid_crate_type_value,
404400
BuiltinLintDiag::UnusedImports { span_snippets, .. } => format!(
405401
"unused import{}{}",
406402
pluralize!(span_snippets.len()),
@@ -415,42 +411,28 @@ pub(super) fn builtin_message(diagnostic: &BuiltinLintDiag) -> DiagMessage {
415411
format!("the item `{source}` is imported redundantly").into()
416412
}
417413
BuiltinLintDiag::DeprecatedMacro { message, .. } => message.clone().into(),
418-
BuiltinLintDiag::MissingAbi(_, _) => crate::fluent_generated::lint_extern_without_abi,
419-
BuiltinLintDiag::UnusedDocComment(_) => "unused doc comment".into(),
414+
BuiltinLintDiag::MissingAbi(_, _) => fluent::lint_extern_without_abi,
415+
BuiltinLintDiag::UnusedDocComment(_) => fluent::lint_unused_doc_comment,
420416
BuiltinLintDiag::UnusedBuiltinAttribute { attr_name, .. } => {
421417
format!("unused attribute `{attr_name}`").into()
422418
}
423419
BuiltinLintDiag::PatternsInFnsWithoutBody { is_foreign, .. } => {
424420
if *is_foreign {
425-
crate::fluent_generated::lint_pattern_in_foreign
421+
fluent::lint_pattern_in_foreign
426422
} else {
427-
crate::fluent_generated::lint_pattern_in_bodiless
423+
fluent::lint_pattern_in_bodiless
428424
}
429425
}
430-
BuiltinLintDiag::LegacyDeriveHelpers(_) => {
431-
"derive helper attribute is used before it is introduced".into()
432-
}
433-
BuiltinLintDiag::ProcMacroBackCompat(_) => "using an old version of `rental`".into(),
434-
BuiltinLintDiag::OrPatternsBackCompat(_, _) => {
435-
"the meaning of the `pat` fragment specifier is changing in Rust 2021, \
436-
which may affect this macro"
437-
.into()
438-
}
426+
BuiltinLintDiag::LegacyDeriveHelpers(_) => fluent::lint_legacy_derive_helpers,
427+
BuiltinLintDiag::ProcMacroBackCompat(_) => fluent::lint_proc_macro_back_compat_rental,
428+
BuiltinLintDiag::OrPatternsBackCompat(_, _) => fluent::lint_or_patterns_back_compat,
439429
BuiltinLintDiag::ReservedPrefix(_, prefix) => {
440430
format!("prefix `{prefix}` is unknown").into()
441431
}
442-
BuiltinLintDiag::TrailingMacro(_, _) => {
443-
"trailing semicolon in macro used in expression position".into()
444-
}
445-
BuiltinLintDiag::BreakWithLabelAndLoop(_) => {
446-
"this labeled break expression is easy to confuse with an unlabeled break with a \
447-
labeled value expression"
448-
.into()
449-
}
450-
BuiltinLintDiag::NamedAsmLabel(_) => crate::fluent_generated::lint_builtin_asm_labels,
451-
BuiltinLintDiag::UnicodeTextFlow(_, _) => {
452-
"unicode codepoint changing visible direction of text present in comment".into()
453-
}
432+
BuiltinLintDiag::TrailingMacro(_, _) => fluent::lint_trailing_semi_macro,
433+
BuiltinLintDiag::BreakWithLabelAndLoop(_) => fluent::lint_break_with_label_and_loop,
434+
BuiltinLintDiag::NamedAsmLabel(_) => fluent::lint_builtin_asm_labels,
435+
BuiltinLintDiag::UnicodeTextFlow(_, _) => fluent::lint_unicode_text_flow,
454436
BuiltinLintDiag::UnexpectedCfgName((name, _), _) => {
455437
format!("unexpected `cfg` condition name: `{}`", name).into()
456438
}
@@ -461,7 +443,7 @@ pub(super) fn builtin_message(diagnostic: &BuiltinLintDiag) -> DiagMessage {
461443
}
462444
.into(),
463445
BuiltinLintDiag::DeprecatedWhereclauseLocation(_) => {
464-
crate::fluent_generated::lint_deprecated_where_clause_location
446+
fluent::lint_deprecated_where_clause_location
465447
}
466448
BuiltinLintDiag::SingleUseLifetime { use_span, ident, .. } => {
467449
if use_span.is_some() {
@@ -477,41 +459,34 @@ pub(super) fn builtin_message(diagnostic: &BuiltinLintDiag) -> DiagMessage {
477459
format!("{ty} slice in a packed struct that derives a built-in trait").into()
478460
}
479461
BuiltinLintDiag::UnusedExternCrate { .. } => "unused extern crate".into(),
480-
BuiltinLintDiag::ExternCrateNotIdiomatic { .. } => {
481-
"`extern crate` is not idiomatic in the new edition".into()
482-
}
462+
BuiltinLintDiag::ExternCrateNotIdiomatic { .. } => fluent::lint_extern_crate_not_idiomatic,
483463
BuiltinLintDiag::AmbiguousGlobImports { diag } => diag.msg.clone().into(),
484-
BuiltinLintDiag::AmbiguousGlobReexports { .. } => "ambiguous glob re-exports".into(),
485-
BuiltinLintDiag::HiddenGlobReexports { .. } => {
486-
"private item shadows public glob re-export".into()
487-
}
488-
BuiltinLintDiag::UnusedQualifications { .. } => "unnecessary qualification".into(),
489-
BuiltinLintDiag::AssociatedConstElidedLifetime { elided, .. } => if *elided {
490-
"`&` without an explicit lifetime name cannot be used here"
491-
} else {
492-
"`'_` cannot be used here"
464+
BuiltinLintDiag::AmbiguousGlobReexports { .. } => fluent::lint_ambiguous_glob_reexport,
465+
BuiltinLintDiag::HiddenGlobReexports { .. } => fluent::lint_hidden_glob_reexport,
466+
BuiltinLintDiag::UnusedQualifications { .. } => fluent::lint_unnecessary_qualification,
467+
BuiltinLintDiag::AssociatedConstElidedLifetime { elided, .. } => {
468+
if *elided {
469+
fluent::lint_reference_without_lifetime_not_allowed
470+
} else {
471+
fluent::lint_elided_lifetime_not_allowed
472+
}
493473
}
494-
.into(),
495474
BuiltinLintDiag::RedundantImportVisibility { import_vis, .. } => format!(
496475
"glob import doesn't reexport anything with visibility `{}` \
497476
because no imported item is public enough",
498477
import_vis
499478
)
500479
.into(),
501-
BuiltinLintDiag::InvalidCrateTypeValue => "invalid `crate_type` value".into(),
502-
BuiltinLintDiag::MacroUseDeprecated => "deprecated `#[macro_use]` attribute used to \
503-
import macros should be replaced at use sites \
504-
with a `use` item to import the macro \
505-
instead"
506-
.into(),
507-
BuiltinLintDiag::UnusedMacroUse => "unused `#[macro_use]` import".into(),
480+
BuiltinLintDiag::InvalidCrateTypeValue => fluent::lint_invalid_crate_type_value,
481+
BuiltinLintDiag::MacroUseDeprecated => fluent::lint_macro_use_deprecated,
482+
BuiltinLintDiag::UnusedMacroUse => fluent::lint_unused_macro_use,
508483
BuiltinLintDiag::PrivateExternCrateReexport(ident) => format!(
509484
"extern crate `{ident}` is private, and cannot be \
510485
re-exported (error E0365), consider declaring with \
511486
`pub`"
512487
)
513488
.into(),
514-
BuiltinLintDiag::UnusedLabel => "unused label".into(),
489+
BuiltinLintDiag::UnusedLabel => fluent::lint_unused_label,
515490
BuiltinLintDiag::MacroIsPrivate(ident) => format!("macro `{ident}` is private").into(),
516491
BuiltinLintDiag::UnusedMacroDefinition(name) => {
517492
format!("unused macro definition: `{}`", name).into()
@@ -520,27 +495,15 @@ pub(super) fn builtin_message(diagnostic: &BuiltinLintDiag) -> DiagMessage {
520495
format!("{} rule of macro `{}` is never used", ordinalize(n + 1), name).into()
521496
}
522497
BuiltinLintDiag::UnstableFeature(msg) => msg.clone().into(),
523-
BuiltinLintDiag::AvoidUsingIntelSyntax => {
524-
"avoid using `.intel_syntax`, Intel syntax is the default".into()
525-
}
526-
BuiltinLintDiag::AvoidUsingAttSyntax => {
527-
"avoid using `.att_syntax`, prefer using `options(att_syntax)` instead".into()
528-
}
529-
BuiltinLintDiag::IncompleteInclude => {
530-
"include macro expected single expression in source".into()
531-
}
532-
BuiltinLintDiag::UnnameableTestItems => crate::fluent_generated::lint_unnameable_test_items,
533-
BuiltinLintDiag::DuplicateMacroAttribute => "duplicated attribute".into(),
534-
BuiltinLintDiag::CfgAttrNoAttributes => {
535-
crate::fluent_generated::lint_cfg_attr_no_attributes
536-
}
537-
BuiltinLintDiag::CrateTypeInCfgAttr => {
538-
crate::fluent_generated::lint_crate_type_in_cfg_attr_deprecated
539-
}
540-
BuiltinLintDiag::CrateNameInCfgAttr => {
541-
crate::fluent_generated::lint_crate_name_in_cfg_attr_deprecated
542-
}
543-
BuiltinLintDiag::MissingFragmentSpecifier => "missing fragment specifier".into(),
498+
BuiltinLintDiag::AvoidUsingIntelSyntax => fluent::lint_avoid_intel_syntax,
499+
BuiltinLintDiag::AvoidUsingAttSyntax => fluent::lint_avoid_att_syntax,
500+
BuiltinLintDiag::IncompleteInclude => fluent::lint_incomplete_include,
501+
BuiltinLintDiag::UnnameableTestItems => fluent::lint_unnameable_test_items,
502+
BuiltinLintDiag::DuplicateMacroAttribute => fluent::lint_duplicate_macro_attribute,
503+
BuiltinLintDiag::CfgAttrNoAttributes => fluent::lint_cfg_attr_no_attributes,
504+
BuiltinLintDiag::CrateTypeInCfgAttr => fluent::lint_crate_type_in_cfg_attr_deprecated,
505+
BuiltinLintDiag::CrateNameInCfgAttr => fluent::lint_crate_name_in_cfg_attr_deprecated,
506+
BuiltinLintDiag::MissingFragmentSpecifier => fluent::lint_missing_fragment_specifier,
544507
BuiltinLintDiag::MetaVariableStillRepeating(name) => {
545508
format!("variable '{name}' is still repeating at this depth").into()
546509
}
@@ -556,7 +519,7 @@ pub(super) fn builtin_message(diagnostic: &BuiltinLintDiag) -> DiagMessage {
556519
extern_crate, local_crate, extern_crate
557520
)
558521
.into(),
559-
BuiltinLintDiag::WasmCAbi => crate::fluent_generated::lint_wasm_c_abi,
522+
BuiltinLintDiag::WasmCAbi => fluent::lint_wasm_c_abi,
560523
BuiltinLintDiag::IllFormedAttributeInput { suggestions } => suggestions
561524
.iter()
562525
.enumerate()
@@ -568,13 +531,14 @@ pub(super) fn builtin_message(diagnostic: &BuiltinLintDiag) -> DiagMessage {
568531
acc
569532
})
570533
.into(),
571-
BuiltinLintDiag::InnerAttributeUnstable { is_macro } => if *is_macro {
572-
"inner macro attributes are unstable"
573-
} else {
574-
"custom inner attributes are unstable"
534+
BuiltinLintDiag::InnerAttributeUnstable { is_macro } => {
535+
if *is_macro {
536+
fluent::lint_inner_macro_attribute_unstable
537+
} else {
538+
fluent::lint_custom_inner_attribute_unstable
539+
}
575540
}
576-
.into(),
577-
BuiltinLintDiag::UnknownDiagnosticAttribute => "unknown diagnostic attribute".into(),
541+
BuiltinLintDiag::UnknownDiagnosticAttribute => fluent::lint_unknown_diagnostic_attribute,
578542
}
579543
}
580544

0 commit comments

Comments
 (0)
Please sign in to comment.