Skip to content

Commit 0fc7d04

Browse files
committed
Move more early buffered lints to dyn lint diagnostics (5/N)
1 parent 7a52736 commit 0fc7d04

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
@@ -249,9 +249,6 @@ lint_expectation = this lint expectation is unfulfilled
249249
.note = the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message
250250
.rationale = {$rationale}
251251
252-
lint_extern_crate_not_idiomatic = `extern crate` is not idiomatic in the new edition
253-
.suggestion = convert it to a `use`
254-
255252
lint_for_loops_over_fallibles =
256253
for loop over {$article} `{$ref_prefix}{$ty}`. This is more readably written as an `if let` statement
257254
.suggestion = consider using `if let` to clear intent
@@ -453,9 +450,6 @@ lint_lintpass_by_hand = implementing `LintPass` by hand
453450
lint_macro_expr_fragment_specifier_2024_migration =
454451
the `expr` fragment specifier will accept more expressions in the 2024 edition
455452
.suggestion = to keep the existing behavior, use the `expr_2021` fragment specifier
456-
lint_macro_is_private = macro `{$ident}` is private
457-
458-
lint_macro_rule_never_used = rule #{$n} of macro `{$name}` is never used
459453
460454
lint_malformed_attribute = malformed lint attribute input
461455
@@ -948,8 +942,6 @@ lint_unused_imports = {$num_snippets ->
948942
lint_unused_lifetime = lifetime parameter `{$ident}` never used
949943
.suggestion = elide the unused lifetime
950944
951-
lint_unused_macro_definition = unused macro definition: `{$name}`
952-
953945
lint_unused_op = unused {$op} that must be used
954946
.label = the {$op} produces a value
955947
.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
@@ -2543,35 +2543,6 @@ pub(crate) struct PrivateExternCrateReexport {
25432543
pub sugg: Span,
25442544
}
25452545

2546-
#[derive(LintDiagnostic)]
2547-
#[diag(lint_macro_is_private)]
2548-
pub(crate) struct MacroIsPrivate {
2549-
pub ident: Ident,
2550-
}
2551-
2552-
#[derive(LintDiagnostic)]
2553-
#[diag(lint_unused_macro_definition)]
2554-
pub(crate) struct UnusedMacroDefinition {
2555-
pub name: Symbol,
2556-
}
2557-
2558-
#[derive(LintDiagnostic)]
2559-
#[diag(lint_macro_rule_never_used)]
2560-
pub(crate) struct MacroRuleNeverUsed {
2561-
pub n: usize,
2562-
pub name: Symbol,
2563-
}
2564-
2565-
pub(crate) struct UnstableFeature {
2566-
pub msg: DiagMessage,
2567-
}
2568-
2569-
impl<'a> LintDiagnostic<'a, ()> for UnstableFeature {
2570-
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
2571-
diag.primary_message(self.msg);
2572-
}
2573-
}
2574-
25752546
#[derive(LintDiagnostic)]
25762547
#[diag(lint_unused_crate_dependency)]
25772548
#[help]
@@ -2853,15 +2824,6 @@ pub(crate) struct NamedArgumentUsedPositionally {
28532824
pub named_arg_name: String,
28542825
}
28552826

2856-
#[derive(LintDiagnostic)]
2857-
#[diag(lint_extern_crate_not_idiomatic)]
2858-
pub(crate) struct ExternCrateNotIdiomatic {
2859-
#[suggestion(style = "verbose", code = "{code}", applicability = "machine-applicable")]
2860-
pub span: Span,
2861-
2862-
pub code: &'static str,
2863-
}
2864-
28652827
// FIXME: make this translatable
28662828
pub(crate) struct AmbiguousGlobImports {
28672829
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
@@ -274,6 +277,10 @@ resolve_macro_extern_deprecated =
274277
`#[macro_escape]` is a deprecated synonym for `#[macro_use]`
275278
.help = try an outer attribute: `#[macro_use]`
276279
280+
resolve_macro_is_private = macro `{$ident}` is private
281+
282+
resolve_macro_rule_never_used = rule #{$n} of macro `{$name}` is never used
283+
277284
resolve_macro_use_deprecated =
278285
applying the `#[macro_use]` attribute to an `extern crate` item is deprecated
279286
.help = remove it and import macros at use sites with a `use` item instead
@@ -487,6 +494,8 @@ resolve_unused_extern_crate = unused extern crate
487494
488495
resolve_unused_label = unused label
489496
497+
resolve_unused_macro_definition = unused macro definition: `{$name}`
498+
490499
resolve_unused_macro_use = unused `#[macro_use]` import
491500
492501
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};
@@ -1329,3 +1329,40 @@ pub(crate) struct UnusedMacroUse;
13291329
#[diag(resolve_macro_use_deprecated)]
13301330
#[help]
13311331
pub(crate) struct MacroUseDeprecated;
1332+
1333+
#[derive(LintDiagnostic)]
1334+
#[diag(resolve_macro_is_private)]
1335+
pub(crate) struct MacroIsPrivate {
1336+
pub ident: Ident,
1337+
}
1338+
1339+
#[derive(LintDiagnostic)]
1340+
#[diag(resolve_unused_macro_definition)]
1341+
pub(crate) struct UnusedMacroDefinition {
1342+
pub name: Symbol,
1343+
}
1344+
1345+
#[derive(LintDiagnostic)]
1346+
#[diag(resolve_macro_rule_never_used)]
1347+
pub(crate) struct MacroRuleNeverUsed {
1348+
pub n: usize,
1349+
pub name: Symbol,
1350+
}
1351+
1352+
pub(crate) struct UnstableFeature {
1353+
pub msg: DiagMessage,
1354+
}
1355+
1356+
impl<'a> LintDiagnostic<'a, ()> for UnstableFeature {
1357+
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
1358+
diag.primary_message(self.msg);
1359+
}
1360+
}
1361+
1362+
#[derive(LintDiagnostic)]
1363+
#[diag(resolve_extern_crate_not_idiomatic)]
1364+
pub(crate) struct ExternCrateNotIdiomatic {
1365+
#[suggestion(style = "verbose", code = "{code}", applicability = "machine-applicable")]
1366+
pub span: Span,
1367+
pub code: &'static str,
1368+
}

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};
@@ -2075,7 +2074,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
20752074
PRIVATE_MACRO_USE,
20762075
import.root_id,
20772076
ident.span,
2078-
BuiltinLintDiag::MacroIsPrivate(ident),
2077+
errors::MacroIsPrivate { ident },
20792078
);
20802079
}
20812080
}

compiler/rustc_resolve/src/macros.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> {
341341
UNUSED_MACROS,
342342
node_id,
343343
ident.span,
344-
BuiltinLintDiag::UnusedMacroDefinition(ident.name),
344+
errors::UnusedMacroDefinition { name: ident.name },
345345
);
346346
// Do not report unused individual rules if the entire macro is unused
347347
self.unused_macro_rules.swap_remove(&node_id);
@@ -362,7 +362,7 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> {
362362
UNUSED_MACRO_RULES,
363363
node_id,
364364
rule_span,
365-
BuiltinLintDiag::MacroRuleNeverUsed(arm_i, ident.name),
365+
errors::MacroRuleNeverUsed { n: arm_i + 1, name: ident.name },
366366
);
367367
}
368368
}
@@ -1041,10 +1041,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10411041
lint,
10421042
node_id,
10431043
span,
1044-
BuiltinLintDiag::UnstableFeature(
1045-
// FIXME make this translatable
1046-
msg.into(),
1047-
),
1044+
// FIXME make this translatable
1045+
errors::UnstableFeature { msg: msg.into() },
10481046
)
10491047
};
10501048
stability::report_unstable(

0 commit comments

Comments
 (0)