Skip to content

Commit 55c8590

Browse files
committed
Convert early lints to diag structs
1 parent ea1ca70 commit 55c8590

23 files changed

+909
-480
lines changed

compiler/rustc_expand/src/base.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1555,14 +1555,14 @@ fn pretty_printing_compatibility_hack(item: &Item, sess: &Session) -> bool {
15551555
// FIXME: make this translatable
15561556
#[allow(rustc::untranslatable_diagnostic)]
15571557
sess.psess.buffer_lint_with_diagnostic(
1558-
PROC_MACRO_BACK_COMPAT,
1559-
item.ident.span,
1560-
ast::CRATE_NODE_ID,
1561-
BuiltinLintDiag::ProcMacroBackCompat(
1562-
"older versions of the `rental` crate will stop compiling in future versions of Rust; \
1563-
please update to `rental` v0.5.6, or switch to one of the `rental` alternatives".to_string()
1564-
)
1565-
);
1558+
PROC_MACRO_BACK_COMPAT,
1559+
item.ident.span,
1560+
ast::CRATE_NODE_ID,
1561+
BuiltinLintDiag::ProcMacroBackCompat {
1562+
crate_name: "rental".to_string(),
1563+
fixed_version: "0.5.6".to_string(),
1564+
},
1565+
);
15661566
return true;
15671567
}
15681568
}

compiler/rustc_lint/messages.ftl

+88-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
lint_abs_path_with_module =
2-
absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
1+
lint_abs_path_with_module = absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
2+
.suggestion = use `crate`
33
44
lint_ambiguous_glob_reexport = ambiguous glob re-exports
55
@@ -41,8 +41,8 @@ lint_bad_attribute_argument = bad attribute argument
4141
4242
lint_bad_opt_access = {$msg}
4343
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
44+
lint_break_with_label_and_loop = this labeled break expression is easy to confuse with an unlabeled break with a labeled value expression
45+
.suggestion = wrap this expression in parentheses
4646
4747
lint_builtin_allow_internal_unsafe =
4848
`allow_internal_unsafe` allows defining macros using unsafe without triggering the `unsafe_code` lint at their call site
@@ -235,6 +235,8 @@ lint_dropping_references = calls to `std::mem::drop` with a reference instead of
235235
lint_duplicate_macro_attribute =
236236
duplicated attribute
237237
238+
lint_duplicate_matcher_binding = duplicate matcher binding
239+
238240
lint_elided_lifetime_not_allowed = `'_` cannot be used here
239241
240242
lint_enum_intrinsics_mem_discriminant =
@@ -252,6 +254,8 @@ lint_expectation = this lint expectation is unfulfilled
252254
lint_extern_crate_not_idiomatic = `extern crate` is not idiomatic in the new edition
253255
254256
lint_extern_without_abi = extern declarations without an explicit ABI are deprecated
257+
.label = ABI should be specified here
258+
.help = the default ABI is {$default_abi}
255259
256260
lint_for_loops_over_fallibles =
257261
for loop over {$article} `{$ty}`. This is more readably written as an `if let` statement
@@ -312,6 +316,11 @@ lint_identifier_uncommon_codepoints = identifier contains {$codepoints_len ->
312316
313317
lint_ignored_unless_crate_specified = {$level}({$name}) is ignored unless specified at crate level
314318
319+
lint_ill_formed_attribute_input = {$num_suggestions ->
320+
[1] attribute must be of the form {$suggestions}
321+
*[other] valid forms for the attribute are {$suggestions}
322+
}
323+
315324
lint_improper_ctypes = `extern` {$desc} uses type `{$ty}`, which is not FFI-safe
316325
.label = not FFI-safe
317326
.note = the type is defined here
@@ -377,6 +386,7 @@ lint_incomplete_include =
377386
lint_inner_macro_attribute_unstable = inner macro attributes are unstable
378387
379388
lint_invalid_crate_type_value = invalid `crate_type` value
389+
.suggestion = did you mean
380390
381391
# FIXME: we should ordinalize $valid_up_to when we add support for doing so
382392
lint_invalid_from_utf8_checked = calls to `{$method}` with a invalid literal always return an error
@@ -406,14 +416,24 @@ lint_invalid_reference_casting_note_book = for more information, visit <https://
406416
407417
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`
408418
409-
lint_legacy_derive_helpers =
410-
derive helper attribute is used before it is introduced
419+
lint_legacy_derive_helpers = derive helper attribute is used before it is introduced
420+
.label = the attribute is introduced here
411421
412422
lint_lintpass_by_hand = implementing `LintPass` by hand
413423
.help = try using `declare_lint_pass!` or `impl_lint_pass!` instead
414424
415-
lint_macro_expanded_macro_exports_accessed_by_absolute_paths =
416-
macro-expanded `macro_export` macros from the current crate cannot be referred to by absolute paths
425+
lint_macro_expanded_macro_exports_accessed_by_absolute_paths = macro-expanded `macro_export` macros from the current crate cannot be referred to by absolute paths
426+
.note = the macro is defined here
427+
428+
lint_macro_is_private = macro `{$ident}` is private
429+
430+
lint_macro_rule_never_used = {NUMBER($n, type: "ordinal") ->
431+
[1] first
432+
[one] {$n}st
433+
[two] {$n}nd
434+
[few] {$n}rd
435+
*[other] {$n}th
436+
} rule of macro `{$name}` is never used
417437
418438
lint_macro_use_deprecated =
419439
deprecated `#[macro_use]` attribute used to import macros should be replaced at use sites with a `use` item to import the macro instead
@@ -427,6 +447,10 @@ lint_map_unit_fn = `Iterator::map` call that discard the iterator's values
427447
.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
428448
.suggestion = you might have meant to use `Iterator::for_each`
429449
450+
lint_metavariable_still_repeating = variable '{$name}' is still repeating at this depth
451+
452+
lint_metavariable_wrong_operator = meta-variable repeats with different Kleene operator
453+
430454
lint_missing_fragment_specifier = missing fragment specifier
431455
432456
lint_mixed_script_confusables =
@@ -545,8 +569,8 @@ lint_opaque_hidden_inferred_bound = opaque type `{$ty}` does not satisfy its ass
545569
546570
lint_opaque_hidden_inferred_bound_sugg = add this bound
547571
548-
lint_or_patterns_back_compat =
549-
the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro
572+
lint_or_patterns_back_compat = the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro
573+
.suggestion = use pat_param to preserve semantics
550574
551575
lint_overflowing_bin_hex = literal out of range for `{$ty}`
552576
.negative_note = the literal `{$lit}` (decimal `{$dec}`) does not fit into the type `{$ty}`
@@ -583,7 +607,14 @@ lint_pattern_in_bodiless = patterns aren't allowed in functions without bodies
583607
lint_pattern_in_foreign = patterns aren't allowed in foreign function declarations
584608
.label = pattern not allowed in foreign function
585609
586-
lint_proc_macro_back_compat_rental = using an old version of `rental`
610+
lint_private_extern_crate_reexport =
611+
extern crate `{$ident}` is private, and cannot be re-exported (error E0365), consider declaring with `pub`
612+
613+
lint_proc_macro_back_compat = using an old version of `{$crate_name}`
614+
.note = older versions of the `{$crate_name}` crate will stop compiling in future versions of Rust; please update to `{$crate_name}` v{$fixed_version}, or switch to one of the `{$crate_name}` alternatives
615+
616+
lint_proc_macro_derive_resolution_fallback = cannot find {$ns} `{$ident}` in this scope
617+
.label = names from parent modules are not accessible without an explicit import
587618
588619
lint_ptr_null_checks_fn_ptr = function pointers are not nullable, so checking them for null will always return false
589620
.help = wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
@@ -606,6 +637,12 @@ lint_reason_must_be_string_literal = reason must be a string literal
606637
607638
lint_reason_must_come_last = reason in lint attribute must come last
608639
640+
lint_redundant_import = the item `{$ident}` is imported redundantly
641+
.label_imported_here = the item `{ident}` is already imported here
642+
.label_defined_here = the item `{ident}` is already defined here
643+
.label_imported_prelude = the item `{ident}` is already imported by the extern prelude
644+
.label_defined_prelude = the item `{ident}` is already defined by the extern prelude
645+
609646
lint_redundant_semicolons =
610647
unnecessary trailing {$multiple ->
611648
[true] semicolons
@@ -618,6 +655,8 @@ lint_redundant_semicolons =
618655
619656
lint_reference_without_lifetime_not_allowed = `&` without an explicit lifetime name cannot be used here
620657
658+
lint_remove_mut_from_pattern = remove `mut` from the parameter
659+
621660
lint_removed_lint = lint `{$name}` has been removed: {$reason}
622661
623662
lint_renamed_lint = lint `{$name}` has been renamed to `{$replace}`
@@ -626,6 +665,10 @@ lint_renamed_lint = lint `{$name}` has been renamed to `{$replace}`
626665
627666
lint_requested_level = requested on the command line with `{$level} {$lint_name}`
628667
668+
lint_reserved_prefix = prefix `{$prefix}` is unknown
669+
.label = unknown prefix
670+
.suggestion = insert whitespace here to avoid this being parsed as a prefix in Rust 2021
671+
629672
lint_span_use_eq_ctxt = use `.eq_ctxt()` instead of `.ctxt() == .ctxt()`
630673
631674
lint_supertrait_as_deref_target = this `Deref` implementation is covered by an implicit supertrait coercion
@@ -639,8 +682,9 @@ lint_suspicious_double_ref_clone =
639682
lint_suspicious_double_ref_deref =
640683
using `.deref()` on a double reference, which returns `{$ty}` instead of dereferencing the inner type
641684
642-
lint_trailing_semi_macro =
643-
trailing semicolon in macro used in expression position
685+
lint_trailing_semi_macro = trailing semicolon in macro used in expression position
686+
.note1 = macro invocations at the end of a block are treated as expressions
687+
.note2 = to ignore the value produced by the macro, add a semicolon after the invocation of `{$name}`
644688
645689
lint_ty_qualified = usage of qualified `ty::{$ty}`
646690
.suggestion = try importing it and using it unqualified
@@ -658,8 +702,15 @@ lint_undropped_manually_drops = calls to `std::mem::drop` with `std::mem::Manual
658702
lint_ungated_async_fn_track_caller = `#[track_caller]` on async functions is a no-op
659703
.label = this function will not propagate the caller location
660704
661-
lint_unicode_text_flow =
662-
unicode codepoint changing visible direction of text present in comment
705+
lint_unicode_text_flow = unicode codepoint changing visible direction of text present in comment
706+
.label = {$num_codepoints ->
707+
[1] this comment contains an invisible unicode text flow control codepoint
708+
*[other] this comment contains invisible unicode text flow control codepoints
709+
}
710+
.note = these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen
711+
.suggestion = if their presence wasn't intentional, you can remove them
712+
.label_comment_char = {$c_debug}
713+
663714
664715
lint_unit_bindings = binding has unit type `()`
665716
.label = this pattern is inferred to be the unit type `()`
@@ -681,6 +732,8 @@ lint_unknown_lint =
681732
*[false] did you mean: `{$replace}`
682733
}
683734
735+
lint_unknown_macro_variable = unknown macro variable `{$name}`
736+
684737
lint_unknown_tool_in_scoped_lint = unknown tool name `{$tool_name}` found in scoped lint: `{$tool_name}::{$lint_name}`
685738
.help = add `#![register_tool({$tool_name})]` to the crate root
686739
@@ -695,6 +748,9 @@ lint_untranslatable_diag = diagnostics should be created using translatable mess
695748
lint_unused_allocation = unnecessary allocation, use `&` instead
696749
lint_unused_allocation_mut = unnecessary allocation, use `&mut` instead
697750
751+
lint_unused_builtin_attribute = unused attribute `{$attr_name}`
752+
.note = the built-in attribute `{$attr_name}` will be ignored, since it's applied to the macro invocation `{$macro_name}`
753+
698754
lint_unused_closure =
699755
unused {$pre}{$count ->
700756
[one] closure
@@ -711,18 +767,35 @@ lint_unused_coroutine =
711767
}{$post} that must be used
712768
.note = coroutines are lazy and do nothing unless resumed
713769
770+
lint_unused_crate_dependency = external crate `{$extern_crate}` unused in `{$local_crate}`: remove the dependency or add `use {$extern_crate} as _;`
771+
714772
lint_unused_def = unused {$pre}`{$def}`{$post} that must be used
715773
.suggestion = use `let _ = ...` to ignore the resulting value
716774
717775
lint_unused_delim = unnecessary {$delim} around {$item}
718776
.suggestion = remove these {$delim}
719777
720778
lint_unused_doc_comment = unused doc comment
779+
.label = rustdoc does not generate documentation for macro invocations
780+
.help = to document an item produced by a macro, the macro must produce the documentation as part of its expansion
721781
722782
lint_unused_import_braces = braces around {$node} is unnecessary
723783
784+
lint_unused_imports = {$num_snippets ->
785+
[one] unused import: {$span_snippets}
786+
*[other] unused imports: {$span_snippets}
787+
}
788+
.suggestion_remove_whole_use = remove the whole `use` item
789+
.suggestion_remove_imports = {$num_to_remove ->
790+
[one] remove the unused import
791+
*[other] remove the unused imports
792+
}
793+
.help = if this is a test module, consider adding a `#[cfg(test)]` to the containing module
794+
724795
lint_unused_label = unused label
725796
797+
lint_unused_macro_definition = unused macro definition: `{$name}`
798+
726799
lint_unused_macro_use = unused `#[macro_use]` import
727800
728801
lint_unused_op = unused {$op} that must be used

0 commit comments

Comments
 (0)