Skip to content

Commit 74d12e8

Browse files
committed
Move more early buffered lints to dyn lint diagnostics (5/N)
1 parent 03ce87d commit 74d12e8

File tree

9 files changed

+59
-84
lines changed

9 files changed

+59
-84
lines changed

compiler/rustc_lint/messages.ftl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,6 @@ lint_expectation = this lint expectation is unfulfilled
257257
.note = the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message
258258
.rationale = {$rationale}
259259
260-
lint_extern_crate_not_idiomatic = `extern crate` is not idiomatic in the new edition
261-
.suggestion = convert it to a `use`
262-
263260
lint_for_loops_over_fallibles =
264261
for loop over {$article} `{$ref_prefix}{$ty}`. This is more readably written as an `if let` statement
265262
.suggestion = consider using `if let` to clear intent
@@ -467,9 +464,6 @@ lint_lintpass_by_hand = implementing `LintPass` by hand
467464
lint_macro_expr_fragment_specifier_2024_migration =
468465
the `expr` fragment specifier will accept more expressions in the 2024 edition
469466
.suggestion = to keep the existing behavior, use the `expr_2021` fragment specifier
470-
lint_macro_is_private = macro `{$ident}` is private
471-
472-
lint_macro_rule_never_used = rule #{$n} of macro `{$name}` is never used
473467
474468
lint_malformed_attribute = malformed lint attribute input
475469
@@ -962,8 +956,6 @@ lint_unused_imports = {$num_snippets ->
962956
lint_unused_lifetime = lifetime parameter `{$ident}` never used
963957
.suggestion = elide the unused lifetime
964958
965-
lint_unused_macro_definition = unused macro definition: `{$name}`
966-
967959
lint_unused_op = unused {$op} that must be used
968960
.label = the {$op} produces a value
969961
.suggestion = use `let _ = ...` to ignore the resulting value

compiler/rustc_lint/src/early/diagnostics.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,6 @@ pub fn decorate_builtin_lint(
251251
}
252252
.decorate_lint(diag);
253253
}
254-
BuiltinLintDiag::ExternCrateNotIdiomatic { vis_span, ident_span } => {
255-
let suggestion_span = vis_span.between(ident_span);
256-
let code = if vis_span.is_empty() { "use " } else { " use " };
257-
258-
lints::ExternCrateNotIdiomatic { span: suggestion_span, code }.decorate_lint(diag);
259-
}
260254
BuiltinLintDiag::AmbiguousGlobImports { diag: ambiguity } => {
261255
lints::AmbiguousGlobImports { ambiguity }.decorate_lint(diag);
262256
}
@@ -332,18 +326,6 @@ pub fn decorate_builtin_lint(
332326
lints::PrivateExternCrateReexport { ident, sugg: extern_crate_span.shrink_to_lo() }
333327
.decorate_lint(diag);
334328
}
335-
BuiltinLintDiag::MacroIsPrivate(ident) => {
336-
lints::MacroIsPrivate { ident }.decorate_lint(diag);
337-
}
338-
BuiltinLintDiag::UnusedMacroDefinition(name) => {
339-
lints::UnusedMacroDefinition { name }.decorate_lint(diag);
340-
}
341-
BuiltinLintDiag::MacroRuleNeverUsed(n, name) => {
342-
lints::MacroRuleNeverUsed { n: n + 1, name }.decorate_lint(diag);
343-
}
344-
BuiltinLintDiag::UnstableFeature(msg) => {
345-
lints::UnstableFeature { msg }.decorate_lint(diag);
346-
}
347329
BuiltinLintDiag::UnusedCrateDependency { extern_crate, local_crate } => {
348330
lints::UnusedCrateDependency { extern_crate, local_crate }.decorate_lint(diag)
349331
}

compiler/rustc_lint/src/lints.rs

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,35 +2583,6 @@ pub(crate) struct PrivateExternCrateReexport {
25832583
pub sugg: Span,
25842584
}
25852585

2586-
#[derive(LintDiagnostic)]
2587-
#[diag(lint_macro_is_private)]
2588-
pub(crate) struct MacroIsPrivate {
2589-
pub ident: Ident,
2590-
}
2591-
2592-
#[derive(LintDiagnostic)]
2593-
#[diag(lint_unused_macro_definition)]
2594-
pub(crate) struct UnusedMacroDefinition {
2595-
pub name: Symbol,
2596-
}
2597-
2598-
#[derive(LintDiagnostic)]
2599-
#[diag(lint_macro_rule_never_used)]
2600-
pub(crate) struct MacroRuleNeverUsed {
2601-
pub n: usize,
2602-
pub name: Symbol,
2603-
}
2604-
2605-
pub(crate) struct UnstableFeature {
2606-
pub msg: DiagMessage,
2607-
}
2608-
2609-
impl<'a> LintDiagnostic<'a, ()> for UnstableFeature {
2610-
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
2611-
diag.primary_message(self.msg);
2612-
}
2613-
}
2614-
26152586
#[derive(LintDiagnostic)]
26162587
#[diag(lint_unused_crate_dependency)]
26172588
#[help]
@@ -2893,15 +2864,6 @@ pub(crate) struct NamedArgumentUsedPositionally {
28932864
pub named_arg_name: String,
28942865
}
28952866

2896-
#[derive(LintDiagnostic)]
2897-
#[diag(lint_extern_crate_not_idiomatic)]
2898-
pub(crate) struct ExternCrateNotIdiomatic {
2899-
#[suggestion(style = "verbose", code = "{code}", applicability = "machine-applicable")]
2900-
pub span: Span,
2901-
2902-
pub code: &'static str,
2903-
}
2904-
29052867
// FIXME: make this translatable
29062868
pub(crate) struct AmbiguousGlobImports {
29072869
pub ambiguity: AmbiguityErrorDiag,

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_data_structures::fx::FxIndexSet;
66
use rustc_data_structures::stable_hasher::{
77
HashStable, StableCompare, StableHasher, ToStableHashKey,
88
};
9-
use rustc_error_messages::{DiagArgValue, DiagMessage, IntoDiagArg, MultiSpan};
9+
use rustc_error_messages::{DiagArgValue, IntoDiagArg, MultiSpan};
1010
use rustc_hir_id::{HashStableContext, HirId, ItemLocalId};
1111
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
1212
use rustc_span::def_id::DefPathHash;
@@ -678,10 +678,6 @@ pub enum BuiltinLintDiag {
678678
/// Indicates if the named argument is used as a width/precision for formatting
679679
is_formatting_arg: bool,
680680
},
681-
ExternCrateNotIdiomatic {
682-
vis_span: Span,
683-
ident_span: Span,
684-
},
685681
AmbiguousGlobImports {
686682
diag: AmbiguityErrorDiag,
687683
},
@@ -731,10 +727,6 @@ pub enum BuiltinLintDiag {
731727
source: Ident,
732728
extern_crate_span: Span,
733729
},
734-
MacroIsPrivate(Ident),
735-
UnusedMacroDefinition(Symbol),
736-
MacroRuleNeverUsed(usize, Symbol),
737-
UnstableFeature(DiagMessage),
738730
UnusedCrateDependency {
739731
extern_crate: Symbol,
740732
local_crate: Symbol,

compiler/rustc_resolve/messages.ftl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ resolve_explicit_unsafe_traits =
146146
resolve_extern_crate_loading_macro_not_at_crate_root =
147147
an `extern crate` loading macros must be at the crate root
148148
149+
resolve_extern_crate_not_idiomatic = `extern crate` is not idiomatic in the new edition
150+
.suggestion = convert it to a `use`
151+
149152
resolve_extern_crate_self_requires_renaming =
150153
`extern crate self;` requires renaming
151154
.suggestion = rename the `self` crate to be able to import it
@@ -280,6 +283,10 @@ resolve_macro_extern_deprecated =
280283
`#[macro_escape]` is a deprecated synonym for `#[macro_use]`
281284
.help = try an outer attribute: `#[macro_use]`
282285
286+
resolve_macro_is_private = macro `{$ident}` is private
287+
288+
resolve_macro_rule_never_used = rule #{$n} of macro `{$name}` is never used
289+
283290
resolve_macro_use_deprecated =
284291
applying the `#[macro_use]` attribute to an `extern crate` item is deprecated
285292
.help = remove it and import macros at use sites with a `use` item instead
@@ -493,6 +500,8 @@ resolve_unused_extern_crate = unused extern crate
493500
494501
resolve_unused_label = unused label
495502
503+
resolve_unused_macro_definition = unused macro definition: `{$name}`
504+
496505
resolve_unused_macro_use = unused `#[macro_use]` import
497506
498507
resolve_variable_bound_with_different_mode =

compiler/rustc_resolve/src/check_unused.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,15 @@ impl<'a, 'ra, 'tcx> UnusedImportCheckVisitor<'a, 'ra, 'tcx> {
228228
.span
229229
.find_ancestor_inside(extern_crate.span)
230230
.unwrap_or(extern_crate.ident.span);
231+
231232
self.r.lint_buffer.buffer_lint(
232233
UNUSED_EXTERN_CRATES,
233234
extern_crate.id,
234235
extern_crate.span,
235-
BuiltinLintDiag::ExternCrateNotIdiomatic { vis_span, ident_span },
236+
crate::errors::ExternCrateNotIdiomatic {
237+
span: vis_span.between(ident_span),
238+
code: if vis_span.is_empty() { "use " } else { " use " },
239+
},
236240
);
237241
}
238242
}

compiler/rustc_resolve/src/errors.rs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_errors::codes::*;
22
use rustc_errors::{
3-
Applicability, Diag, ElidedLifetimeInPathSubdiag, EmissionGuarantee, IntoDiagArg, MultiSpan,
4-
Subdiagnostic,
3+
Applicability, Diag, DiagMessage, ElidedLifetimeInPathSubdiag, EmissionGuarantee, IntoDiagArg,
4+
LintDiagnostic, MultiSpan, Subdiagnostic,
55
};
66
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
77
use rustc_span::{Ident, Span, Symbol};
@@ -1359,3 +1359,40 @@ pub(crate) struct UnusedMacroUse;
13591359
#[diag(resolve_macro_use_deprecated)]
13601360
#[help]
13611361
pub(crate) struct MacroUseDeprecated;
1362+
1363+
#[derive(LintDiagnostic)]
1364+
#[diag(resolve_macro_is_private)]
1365+
pub(crate) struct MacroIsPrivate {
1366+
pub ident: Ident,
1367+
}
1368+
1369+
#[derive(LintDiagnostic)]
1370+
#[diag(resolve_unused_macro_definition)]
1371+
pub(crate) struct UnusedMacroDefinition {
1372+
pub name: Symbol,
1373+
}
1374+
1375+
#[derive(LintDiagnostic)]
1376+
#[diag(resolve_macro_rule_never_used)]
1377+
pub(crate) struct MacroRuleNeverUsed {
1378+
pub n: usize,
1379+
pub name: Symbol,
1380+
}
1381+
1382+
pub(crate) struct UnstableFeature {
1383+
pub msg: DiagMessage,
1384+
}
1385+
1386+
impl<'a> LintDiagnostic<'a, ()> for UnstableFeature {
1387+
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
1388+
diag.primary_message(self.msg);
1389+
}
1390+
}
1391+
1392+
#[derive(LintDiagnostic)]
1393+
#[diag(resolve_extern_crate_not_idiomatic)]
1394+
pub(crate) struct ExternCrateNotIdiomatic {
1395+
#[suggestion(style = "verbose", code = "{code}", applicability = "machine-applicable")]
1396+
pub span: Span,
1397+
pub code: &'static str,
1398+
}

compiler/rustc_resolve/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ use rustc_middle::ty::{
7373
ResolverGlobalCtxt, TyCtxt, TyCtxtFeed, Visibility,
7474
};
7575
use rustc_query_system::ich::StableHashingContext;
76-
use rustc_session::lint::BuiltinLintDiag;
7776
use rustc_session::lint::builtin::PRIVATE_MACRO_USE;
7877
use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind, SyntaxContext, Transparency};
7978
use rustc_span::{DUMMY_SP, Ident, Macros20NormalizedIdent, Span, Symbol, kw, sym};
@@ -2067,7 +2066,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
20672066
PRIVATE_MACRO_USE,
20682067
import.root_id,
20692068
ident.span,
2070-
BuiltinLintDiag::MacroIsPrivate(ident),
2069+
errors::MacroIsPrivate { ident },
20712070
);
20722071
}
20732072
}

compiler/rustc_resolve/src/macros.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> {
340340
UNUSED_MACROS,
341341
node_id,
342342
ident.span,
343-
BuiltinLintDiag::UnusedMacroDefinition(ident.name),
343+
errors::UnusedMacroDefinition { name: ident.name },
344344
);
345345
// Do not report unused individual rules if the entire macro is unused
346346
self.unused_macro_rules.swap_remove(&node_id);
@@ -361,7 +361,7 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> {
361361
UNUSED_MACRO_RULES,
362362
node_id,
363363
rule_span,
364-
BuiltinLintDiag::MacroRuleNeverUsed(arm_i, ident.name),
364+
errors::MacroRuleNeverUsed { n: arm_i + 1, name: ident.name },
365365
);
366366
}
367367
}
@@ -1031,10 +1031,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10311031
lint,
10321032
node_id,
10331033
span,
1034-
BuiltinLintDiag::UnstableFeature(
1035-
// FIXME make this translatable
1036-
msg.into(),
1037-
),
1034+
// FIXME make this translatable
1035+
errors::UnstableFeature { msg: msg.into() },
10381036
)
10391037
};
10401038
stability::report_unstable(

0 commit comments

Comments
 (0)