Skip to content

Commit 7d9c1e2

Browse files
committed
Move more early buffered lints to dyn lint diagnostics (4/N)
1 parent f0615d6 commit 7d9c1e2

File tree

11 files changed

+70
-98
lines changed

11 files changed

+70
-98
lines changed

compiler/rustc_expand/messages.ftl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ expand_mve_unrecognized_var =
160160
expand_non_inline_modules_in_proc_macro_input_are_unstable =
161161
non-inline modules in proc macro input are unstable
162162
163+
expand_or_patterns_back_compat = the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro
164+
.suggestion = use pat_param to preserve semantics
165+
163166
expand_proc_macro_back_compat = using an old version of `{$crate_name}`
164167
.note = older versions of the `{$crate_name}` crate no longer compile; please update to `{$crate_name}` v{$fixed_version}, or switch to one of the `{$crate_name}` alternatives
165168
@@ -189,8 +192,16 @@ expand_resolve_relative_path =
189192
190193
expand_trace_macro = trace_macro
191194
195+
expand_trailing_semi_macro = trailing semicolon in macro used in expression position
196+
.note1 = macro invocations at the end of a block are treated as expressions
197+
.note2 = to ignore the value produced by the macro, add a semicolon after the invocation of `{$name}`
198+
192199
expand_unknown_macro_variable = unknown macro variable `{$name}`
193200
201+
expand_unused_builtin_attribute = unused attribute `{$attr_name}`
202+
.note = the built-in attribute `{$attr_name}` will be ignored, since it's applied to the macro invocation `{$macro_name}`
203+
.suggestion = remove the attribute
204+
194205
expand_unsupported_key_value =
195206
key-value macro attributes are not supported
196207

compiler/rustc_expand/src/errors.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,3 +547,31 @@ pub(crate) struct MacroCallUnusedDocComment {
547547
#[label]
548548
pub span: Span,
549549
}
550+
551+
#[derive(LintDiagnostic)]
552+
#[diag(expand_or_patterns_back_compat)]
553+
pub(crate) struct OrPatternsBackCompat {
554+
#[suggestion(code = "{suggestion}", applicability = "machine-applicable")]
555+
pub span: Span,
556+
pub suggestion: String,
557+
}
558+
559+
#[derive(LintDiagnostic)]
560+
#[diag(expand_trailing_semi_macro)]
561+
pub(crate) struct TrailingMacro {
562+
#[note(expand_note1)]
563+
#[note(expand_note2)]
564+
pub is_trailing: bool,
565+
pub name: Ident,
566+
}
567+
568+
#[derive(LintDiagnostic)]
569+
#[diag(expand_unused_builtin_attribute)]
570+
pub(crate) struct UnusedBuiltinAttribute {
571+
#[note]
572+
pub invoc_span: Span,
573+
pub attr_name: Symbol,
574+
pub macro_name: String,
575+
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
576+
pub attr_span: Span,
577+
}

compiler/rustc_expand/src/expand.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use rustc_parse::parser::{
2525
token_descr,
2626
};
2727
use rustc_session::Session;
28-
use rustc_session::lint::BuiltinLintDiag;
2928
use rustc_session::lint::builtin::{UNUSED_ATTRIBUTES, UNUSED_DOC_COMMENTS};
3029
use rustc_session::parse::feature_err;
3130
use rustc_span::hygiene::SyntaxContext;
@@ -2196,7 +2195,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
21962195
UNUSED_ATTRIBUTES,
21972196
attr.span,
21982197
self.cx.current_expansion.lint_node_id,
2199-
BuiltinLintDiag::UnusedBuiltinAttribute {
2198+
crate::errors::UnusedBuiltinAttribute {
22002199
attr_name,
22012200
macro_name: pprust::path_to_string(&call.path),
22022201
invoc_span: call.path.span,

compiler/rustc_expand/src/mbe/macro_rules.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use rustc_hir as hir;
1717
use rustc_hir::attrs::AttributeKind;
1818
use rustc_hir::def::MacroKinds;
1919
use rustc_hir::find_attr;
20-
use rustc_lint_defs::BuiltinLintDiag;
2120
use rustc_lint_defs::builtin::{
2221
RUST_2021_INCOMPATIBLE_OR_PATTERNS, SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
2322
};
@@ -90,7 +89,7 @@ impl<'a> ParserAnyMacro<'a> {
9089
SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
9190
parser.token.span,
9291
lint_node_id,
93-
BuiltinLintDiag::TrailingMacro(is_trailing_mac, macro_ident),
92+
errors::TrailingMacro { is_trailing: is_trailing_mac, name: macro_ident },
9493
);
9594
}
9695
parser.bump();
@@ -1425,7 +1424,7 @@ fn check_matcher_core<'tt>(
14251424
RUST_2021_INCOMPATIBLE_OR_PATTERNS,
14261425
span,
14271426
ast::CRATE_NODE_ID,
1428-
BuiltinLintDiag::OrPatternsBackCompat(span, suggestion),
1427+
errors::OrPatternsBackCompat { span, suggestion },
14291428
);
14301429
}
14311430
match is_in_follow(next_token, kind) {

compiler/rustc_interface/messages.ftl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ interface_ignoring_out_dir = ignoring --out-dir flag due to -o flag
3030
interface_input_file_would_be_overwritten =
3131
the input file "{$path}" would be overwritten by the generated executable
3232
33+
interface_invalid_crate_type_value = invalid `crate_type` value
34+
.suggestion = did you mean
35+
36+
interface_limit_invalid =
37+
`limit` must be a non-negative integer
38+
.label = {$error_str}
39+
3340
interface_mixed_bin_crate =
3441
cannot mix `bin` crate type with others
3542

compiler/rustc_interface/src/errors.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::io;
22
use std::path::Path;
33

4-
use rustc_macros::Diagnostic;
4+
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
55
use rustc_span::{Span, Symbol};
66

77
#[derive(Diagnostic)]
@@ -108,3 +108,18 @@ pub(crate) struct AbiRequiredTargetFeature<'a> {
108108
pub feature: &'a str,
109109
pub enabled: &'a str,
110110
}
111+
112+
#[derive(LintDiagnostic)]
113+
#[diag(interface_invalid_crate_type_value)]
114+
pub(crate) struct UnknownCrateTypes {
115+
#[subdiagnostic]
116+
pub sugg: Option<UnknownCrateTypesSub>,
117+
}
118+
119+
#[derive(Subdiagnostic)]
120+
#[suggestion(interface_suggestion, code = r#""{snippet}""#, applicability = "maybe-incorrect")]
121+
pub(crate) struct UnknownCrateTypesSub {
122+
#[primary_span]
123+
pub span: Span,
124+
pub snippet: Symbol,
125+
}

compiler/rustc_interface/src/util.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ use rustc_errors::LintBuffer;
1313
use rustc_metadata::{DylibError, load_symbol_from_dylib};
1414
use rustc_middle::ty::CurrentGcx;
1515
use rustc_session::config::{Cfg, OutFileName, OutputFilenames, OutputTypes, Sysroot, host_tuple};
16-
use rustc_session::lint::{self, BuiltinLintDiag};
1716
use rustc_session::output::{CRATE_TYPES, categorize_crate_type};
18-
use rustc_session::{EarlyDiagCtxt, Session, filesearch};
17+
use rustc_session::{EarlyDiagCtxt, Session, filesearch, lint};
1918
use rustc_span::edit_distance::find_best_match_for_name;
2019
use rustc_span::edition::Edition;
2120
use rustc_span::source_map::SourceMapInputs;
@@ -468,7 +467,10 @@ pub(crate) fn check_attr_crate_type(
468467
lint::builtin::UNKNOWN_CRATE_TYPES,
469468
ast::CRATE_NODE_ID,
470469
span,
471-
BuiltinLintDiag::UnknownCrateTypes { span, candidate },
470+
errors::UnknownCrateTypes {
471+
sugg: candidate
472+
.map(|cand| errors::UnknownCrateTypesSub { span, snippet: cand }),
473+
},
472474
);
473475
}
474476
} else {

compiler/rustc_lint/messages.ftl

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,6 @@ lint_invalid_asm_label_named = avoid using named labels in inline assembly
407407
.note = see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information
408408
lint_invalid_asm_label_no_span = the label may be declared in the expansion of a macro
409409
410-
lint_invalid_crate_type_value = invalid `crate_type` value
411-
.suggestion = did you mean
412-
413410
# FIXME: we should ordinalize $valid_up_to when we add support for doing so
414411
lint_invalid_from_utf8_checked = calls to `{$method}` with an invalid literal always return an error
415412
.label = the literal was valid UTF-8 up to the {$valid_up_to} bytes
@@ -637,9 +634,6 @@ lint_opaque_hidden_inferred_bound = opaque type `{$ty}` does not satisfy its ass
637634
638635
lint_opaque_hidden_inferred_bound_sugg = add this bound
639636
640-
lint_or_patterns_back_compat = the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro
641-
.suggestion = use pat_param to preserve semantics
642-
643637
lint_out_of_scope_macro_calls = cannot find macro `{$path}` in the current scope when looking from {$location}
644638
.label = not found from {$location}
645639
.help = import `macro_rules` with `use` to make it callable above its definition
@@ -783,10 +777,6 @@ lint_symbol_intern_string_literal = using `Symbol::intern` on a string literal
783777
lint_too_large_char_cast = value exceeds maximum `char` value
784778
.note = maximum valid `char` value is `0x10FFFF`
785779
786-
lint_trailing_semi_macro = trailing semicolon in macro used in expression position
787-
.note1 = macro invocations at the end of a block are treated as expressions
788-
.note2 = to ignore the value produced by the macro, add a semicolon after the invocation of `{$name}`
789-
790780
lint_ty_qualified = usage of qualified `ty::{$ty}`
791781
.suggestion = try importing it and using it unqualified
792782
@@ -917,10 +907,6 @@ lint_untranslatable_diag = diagnostics should be created using translatable mess
917907
lint_unused_allocation = unnecessary allocation, use `&` instead
918908
lint_unused_allocation_mut = unnecessary allocation, use `&mut` instead
919909
920-
lint_unused_builtin_attribute = unused attribute `{$attr_name}`
921-
.note = the built-in attribute `{$attr_name}` will be ignored, since it's applied to the macro invocation `{$macro_name}`
922-
.suggestion = remove the attribute
923-
924910
lint_unused_closure =
925911
unused {$pre}{$count ->
926912
[one] closure

compiler/rustc_lint/src/early/diagnostics.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ pub fn decorate_builtin_lint(
7676
}
7777
.decorate_lint(diag);
7878
}
79-
BuiltinLintDiag::UnknownCrateTypes { span, candidate } => {
80-
let sugg = candidate.map(|candidate| lints::UnknownCrateTypesSub { span, candidate });
81-
lints::UnknownCrateTypes { sugg }.decorate_lint(diag);
82-
}
8379
BuiltinLintDiag::UnusedImports {
8480
remove_whole_use,
8581
num_to_remove,
@@ -144,9 +140,6 @@ pub fn decorate_builtin_lint(
144140
}
145141
.decorate_lint(diag);
146142
}
147-
BuiltinLintDiag::OrPatternsBackCompat(suggestion_span, suggestion) => {
148-
lints::OrPatternsBackCompat { span: suggestion_span, suggestion }.decorate_lint(diag);
149-
}
150143
BuiltinLintDiag::ReservedPrefix(label_span, prefix) => {
151144
lints::ReservedPrefix {
152145
label: label_span,
@@ -166,18 +159,6 @@ pub fn decorate_builtin_lint(
166159
lints::ReservedMultihash { suggestion }.decorate_lint(diag);
167160
}
168161
}
169-
BuiltinLintDiag::UnusedBuiltinAttribute {
170-
attr_name,
171-
macro_name,
172-
invoc_span,
173-
attr_span,
174-
} => {
175-
lints::UnusedBuiltinAttribute { invoc_span, attr_name, macro_name, attr_span }
176-
.decorate_lint(diag);
177-
}
178-
BuiltinLintDiag::TrailingMacro(is_trailing, name) => {
179-
lints::TrailingMacro { is_trailing, name }.decorate_lint(diag);
180-
}
181162
BuiltinLintDiag::BreakWithLabelAndLoop(sugg_span) => {
182163
lints::BreakWithLabelAndLoop {
183164
sub: lints::BreakWithLabelAndLoopSub {

compiler/rustc_lint/src/lints.rs

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2664,21 +2664,6 @@ pub(crate) struct ElidedLifetimesInPaths {
26642664
pub subdiag: ElidedLifetimeInPathSubdiag,
26652665
}
26662666

2667-
#[derive(LintDiagnostic)]
2668-
#[diag(lint_invalid_crate_type_value)]
2669-
pub(crate) struct UnknownCrateTypes {
2670-
#[subdiagnostic]
2671-
pub sugg: Option<UnknownCrateTypesSub>,
2672-
}
2673-
2674-
#[derive(Subdiagnostic)]
2675-
#[suggestion(lint_suggestion, code = r#""{candidate}""#, applicability = "maybe-incorrect")]
2676-
pub(crate) struct UnknownCrateTypesSub {
2677-
#[primary_span]
2678-
pub span: Span,
2679-
pub candidate: Symbol,
2680-
}
2681-
26822667
#[derive(LintDiagnostic)]
26832668
#[diag(lint_unused_imports)]
26842669
pub(crate) struct UnusedImports {
@@ -2759,14 +2744,6 @@ pub(crate) struct PatternsInFnsWithoutBodySub {
27592744
pub ident: Ident,
27602745
}
27612746

2762-
#[derive(LintDiagnostic)]
2763-
#[diag(lint_or_patterns_back_compat)]
2764-
pub(crate) struct OrPatternsBackCompat {
2765-
#[suggestion(code = "{suggestion}", applicability = "machine-applicable")]
2766-
pub span: Span,
2767-
pub suggestion: String,
2768-
}
2769-
27702747
#[derive(LintDiagnostic)]
27712748
#[diag(lint_reserved_prefix)]
27722749
pub(crate) struct ReservedPrefix {
@@ -2787,27 +2764,6 @@ pub(crate) struct RawPrefix {
27872764
pub suggestion: Span,
27882765
}
27892766

2790-
#[derive(LintDiagnostic)]
2791-
#[diag(lint_unused_builtin_attribute)]
2792-
pub(crate) struct UnusedBuiltinAttribute {
2793-
#[note]
2794-
pub invoc_span: Span,
2795-
pub attr_name: Symbol,
2796-
pub macro_name: String,
2797-
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
2798-
pub attr_span: Span,
2799-
}
2800-
2801-
#[derive(LintDiagnostic)]
2802-
#[diag(lint_trailing_semi_macro)]
2803-
pub(crate) struct TrailingMacro {
2804-
#[note(lint_note1)]
2805-
#[note(lint_note2)]
2806-
pub is_trailing: bool,
2807-
2808-
pub name: Ident,
2809-
}
2810-
28112767
#[derive(LintDiagnostic)]
28122768
#[diag(lint_break_with_label_and_loop)]
28132769
pub(crate) struct BreakWithLabelAndLoop {

0 commit comments

Comments
 (0)