Skip to content

Commit 3ad6359

Browse files
committed
Move more early buffered lints to dyn lint diagnostics (6/N)
1 parent 74d12e8 commit 3ad6359

File tree

8 files changed

+82
-116
lines changed

8 files changed

+82
-116
lines changed

compiler/rustc_lint/messages.ftl

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -642,10 +642,6 @@ lint_opaque_hidden_inferred_bound = opaque type `{$ty}` does not satisfy its ass
642642
643643
lint_opaque_hidden_inferred_bound_sugg = add this bound
644644
645-
lint_out_of_scope_macro_calls = cannot find macro `{$path}` in the current scope when looking from {$location}
646-
.label = not found from {$location}
647-
.help = import `macro_rules` with `use` to make it callable above its definition
648-
649645
lint_overflowing_bin_hex = literal out of range for `{$ty}`
650646
.negative_note = the literal `{$lit}` (decimal `{$dec}`) does not fit into the type `{$ty}`
651647
.negative_becomes_note = and the value `-{$lit}` will become `{$actually}{$ty}`
@@ -681,9 +677,6 @@ lint_pattern_in_bodiless = patterns aren't allowed in functions without bodies
681677
lint_pattern_in_foreign = patterns aren't allowed in foreign function declarations
682678
.label = pattern not allowed in foreign function
683679
684-
lint_private_extern_crate_reexport = extern crate `{$ident}` is private and cannot be re-exported
685-
.suggestion = consider making the `extern crate` item publicly accessible
686-
687680
lint_query_instability = using `{$query}` can result in unstable query results
688681
.note = if you believe this case to be fine, allow this lint and add a comment explaining your rationale
689682
@@ -709,10 +702,6 @@ lint_redundant_import = the item `{$ident}` is imported redundantly
709702
.label_imported_prelude = the item `{$ident}` is already imported by the extern prelude
710703
.label_defined_prelude = the item `{$ident}` is already defined by the extern prelude
711704
712-
lint_redundant_import_visibility = glob import doesn't reexport anything with visibility `{$import_vis}` because no imported item is public enough
713-
.note = the most public imported item is `{$max_vis}`
714-
.help = reduce the glob import's visibility or increase visibility of imported items
715-
716705
lint_redundant_semicolons =
717706
unnecessary trailing {$multiple ->
718707
[true] semicolons
@@ -872,9 +861,6 @@ lint_unicode_text_flow = unicode codepoint changing visible direction of text pr
872861
lint_unit_bindings = binding has unit type `()`
873862
.label = this pattern is inferred to be the unit type `()`
874863
875-
lint_unknown_diagnostic_attribute = unknown diagnostic attribute
876-
lint_unknown_diagnostic_attribute_typo_sugg = an attribute with a similar name exists
877-
878864
lint_unknown_gated_lint =
879865
unknown lint: `{$name}`
880866
.note = the `{$name}` lint is unstable

compiler/rustc_lint/src/early/diagnostics.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -311,21 +311,6 @@ pub fn decorate_builtin_lint(
311311
}
312312
.decorate_lint(diag);
313313
}
314-
BuiltinLintDiag::RedundantImportVisibility { max_vis, span: vis_span, import_vis } => {
315-
lints::RedundantImportVisibility { span: vis_span, help: (), max_vis, import_vis }
316-
.decorate_lint(diag);
317-
}
318-
BuiltinLintDiag::UnknownDiagnosticAttribute { span: typo_span, typo_name } => {
319-
let typo = typo_name.map(|typo_name| lints::UnknownDiagnosticAttributeTypoSugg {
320-
span: typo_span,
321-
typo_name,
322-
});
323-
lints::UnknownDiagnosticAttribute { typo }.decorate_lint(diag);
324-
}
325-
BuiltinLintDiag::PrivateExternCrateReexport { source: ident, extern_crate_span } => {
326-
lints::PrivateExternCrateReexport { ident, sugg: extern_crate_span.shrink_to_lo() }
327-
.decorate_lint(diag);
328-
}
329314
BuiltinLintDiag::UnusedCrateDependency { extern_crate, local_crate } => {
330315
lints::UnusedCrateDependency { extern_crate, local_crate }.decorate_lint(diag)
331316
}
@@ -340,8 +325,5 @@ pub fn decorate_builtin_lint(
340325
}
341326
.decorate_lint(diag)
342327
}
343-
BuiltinLintDiag::OutOfScopeMacroCalls { span, path, location } => {
344-
lints::OutOfScopeMacroCalls { span, path, location }.decorate_lint(diag)
345-
}
346328
}
347329
}

compiler/rustc_lint/src/lints.rs

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2575,14 +2575,6 @@ pub(crate) mod unexpected_cfg_value {
25752575
}
25762576
}
25772577

2578-
#[derive(LintDiagnostic)]
2579-
#[diag(lint_private_extern_crate_reexport, code = E0365)]
2580-
pub(crate) struct PrivateExternCrateReexport {
2581-
pub ident: Ident,
2582-
#[suggestion(code = "pub ", style = "verbose", applicability = "maybe-incorrect")]
2583-
pub sugg: Span,
2584-
}
2585-
25862578
#[derive(LintDiagnostic)]
25872579
#[diag(lint_unused_crate_dependency)]
25882580
#[help]
@@ -2602,26 +2594,6 @@ pub(crate) struct IllFormedAttributeInput {
26022594
pub docs: &'static str,
26032595
}
26042596

2605-
#[derive(LintDiagnostic)]
2606-
#[diag(lint_unknown_diagnostic_attribute)]
2607-
pub(crate) struct UnknownDiagnosticAttribute {
2608-
#[subdiagnostic]
2609-
pub typo: Option<UnknownDiagnosticAttributeTypoSugg>,
2610-
}
2611-
2612-
#[derive(Subdiagnostic)]
2613-
#[suggestion(
2614-
lint_unknown_diagnostic_attribute_typo_sugg,
2615-
style = "verbose",
2616-
code = "{typo_name}",
2617-
applicability = "machine-applicable"
2618-
)]
2619-
pub(crate) struct UnknownDiagnosticAttributeTypoSugg {
2620-
#[primary_span]
2621-
pub span: Span,
2622-
pub typo_name: Symbol,
2623-
}
2624-
26252597
#[derive(LintDiagnostic)]
26262598
#[diag(lint_unicode_text_flow)]
26272599
#[note]
@@ -2921,18 +2893,6 @@ pub(crate) struct AssociatedConstElidedLifetime {
29212893
pub lifetimes_in_scope: MultiSpan,
29222894
}
29232895

2924-
#[derive(LintDiagnostic)]
2925-
#[diag(lint_redundant_import_visibility)]
2926-
pub(crate) struct RedundantImportVisibility {
2927-
#[note]
2928-
pub span: Span,
2929-
#[help]
2930-
pub help: (),
2931-
2932-
pub import_vis: String,
2933-
pub max_vis: String,
2934-
}
2935-
29362896
#[derive(LintDiagnostic)]
29372897
#[diag(lint_unsafe_attr_outside_unsafe)]
29382898
pub(crate) struct UnsafeAttrOutsideUnsafe {
@@ -2954,16 +2914,6 @@ pub(crate) struct UnsafeAttrOutsideUnsafeSuggestion {
29542914
pub right: Span,
29552915
}
29562916

2957-
#[derive(LintDiagnostic)]
2958-
#[diag(lint_out_of_scope_macro_calls)]
2959-
#[help]
2960-
pub(crate) struct OutOfScopeMacroCalls {
2961-
#[label]
2962-
pub span: Span,
2963-
pub path: String,
2964-
pub location: String,
2965-
}
2966-
29672917
#[derive(LintDiagnostic)]
29682918
#[diag(lint_static_mut_refs_lint)]
29692919
pub(crate) struct RefOfMutStatic<'a> {

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -714,19 +714,6 @@ pub enum BuiltinLintDiag {
714714
span: Span,
715715
lifetimes_in_scope: MultiSpan,
716716
},
717-
RedundantImportVisibility {
718-
span: Span,
719-
max_vis: String,
720-
import_vis: String,
721-
},
722-
UnknownDiagnosticAttribute {
723-
span: Span,
724-
typo_name: Option<Symbol>,
725-
},
726-
PrivateExternCrateReexport {
727-
source: Ident,
728-
extern_crate_span: Span,
729-
},
730717
UnusedCrateDependency {
731718
extern_crate: Symbol,
732719
local_crate: Symbol,
@@ -735,11 +722,6 @@ pub enum BuiltinLintDiag {
735722
suggestions: Vec<String>,
736723
docs: Option<&'static str>,
737724
},
738-
OutOfScopeMacroCalls {
739-
span: Span,
740-
path: String,
741-
location: String,
742-
},
743725
}
744726

745727
pub type RegisteredTools = FxIndexSet<Ident>;

compiler/rustc_resolve/messages.ftl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,10 @@ resolve_note_and_refers_to_the_item_defined_here =
342342
}
343343
}
344344
345+
resolve_out_of_scope_macro_calls = cannot find macro `{$path}` in the current scope when looking from {$location}
346+
.label = not found from {$location}
347+
.help = import `macro_rules` with `use` to make it callable above its definition
348+
345349
resolve_outer_ident_is_not_publicly_reexported =
346350
{$outer_ident_descr} `{$outer_ident}` is not publicly re-exported
347351
@@ -362,12 +366,19 @@ resolve_param_in_ty_of_const_param =
362366
363367
resolve_pattern_doesnt_bind_name = pattern doesn't bind `{$name}`
364368
369+
resolve_private_extern_crate_reexport = extern crate `{$ident}` is private and cannot be re-exported
370+
.suggestion = consider making the `extern crate` item publicly accessible
371+
365372
resolve_proc_macro_derive_resolution_fallback = cannot find {$ns_descr} `{$ident}` in this scope
366373
.label = names from parent modules are not accessible without an explicit import
367374
368375
resolve_proc_macro_same_crate = can't use a procedural macro from the same crate that defines it
369376
.help = you can define integration tests in a directory named `tests`
370377
378+
resolve_redundant_import_visibility = glob import doesn't reexport anything with visibility `{$import_vis}` because no imported item is public enough
379+
.note = the most public imported item is `{$max_vis}`
380+
.help = reduce the glob import's visibility or increase visibility of imported items
381+
371382
resolve_reexport_of_crate_public =
372383
re-export of crate public `{$ident}`
373384
@@ -473,6 +484,9 @@ resolve_unexpected_res_change_ty_to_const_param_sugg =
473484
resolve_unexpected_res_use_at_op_in_slice_pat_with_range_sugg =
474485
if you meant to collect the rest of the slice in `{$ident}`, use the at operator
475486
487+
resolve_unknown_diagnostic_attribute = unknown diagnostic attribute
488+
resolve_unknown_diagnostic_attribute_typo_sugg = an attribute with a similar name exists
489+
476490
resolve_unnamed_crate_root_import =
477491
crate root imports need to be explicitly named: `use crate as name;`
478492

compiler/rustc_resolve/src/errors.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,14 @@ pub(crate) struct CannotBeReexportedCratePublicNS {
812812
pub(crate) ident: Ident,
813813
}
814814

815+
#[derive(LintDiagnostic)]
816+
#[diag(resolve_private_extern_crate_reexport, code = E0365)]
817+
pub(crate) struct PrivateExternCrateReexport {
818+
pub ident: Ident,
819+
#[suggestion(code = "pub ", style = "verbose", applicability = "maybe-incorrect")]
820+
pub sugg: Span,
821+
}
822+
815823
#[derive(Subdiagnostic)]
816824
#[help(resolve_consider_adding_macro_export)]
817825
pub(crate) struct ConsiderAddingMacroExport {
@@ -1396,3 +1404,44 @@ pub(crate) struct ExternCrateNotIdiomatic {
13961404
pub span: Span,
13971405
pub code: &'static str,
13981406
}
1407+
1408+
#[derive(LintDiagnostic)]
1409+
#[diag(resolve_out_of_scope_macro_calls)]
1410+
#[help]
1411+
pub(crate) struct OutOfScopeMacroCalls {
1412+
#[label]
1413+
pub span: Span,
1414+
pub path: String,
1415+
pub location: String,
1416+
}
1417+
1418+
#[derive(LintDiagnostic)]
1419+
#[diag(resolve_redundant_import_visibility)]
1420+
pub(crate) struct RedundantImportVisibility {
1421+
#[note]
1422+
pub span: Span,
1423+
#[help]
1424+
pub help: (),
1425+
pub import_vis: String,
1426+
pub max_vis: String,
1427+
}
1428+
1429+
#[derive(LintDiagnostic)]
1430+
#[diag(resolve_unknown_diagnostic_attribute)]
1431+
pub(crate) struct UnknownDiagnosticAttribute {
1432+
#[subdiagnostic]
1433+
pub typo: Option<UnknownDiagnosticAttributeTypoSugg>,
1434+
}
1435+
1436+
#[derive(Subdiagnostic)]
1437+
#[suggestion(
1438+
resolve_unknown_diagnostic_attribute_typo_sugg,
1439+
style = "verbose",
1440+
code = "{typo_name}",
1441+
applicability = "machine-applicable"
1442+
)]
1443+
pub(crate) struct UnknownDiagnosticAttributeTypoSugg {
1444+
#[primary_span]
1445+
pub span: Span,
1446+
pub typo_name: Symbol,
1447+
}

compiler/rustc_resolve/src/imports.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,10 +1095,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10951095
UNUSED_IMPORTS,
10961096
id,
10971097
import.span,
1098-
BuiltinLintDiag::RedundantImportVisibility {
1098+
crate::errors::RedundantImportVisibility {
1099+
span: import.span,
1100+
help: (),
10991101
max_vis: max_vis.to_string(def_id, self.tcx),
11001102
import_vis: import.vis.to_string(def_id, self.tcx),
1101-
span: import.span,
11021103
},
11031104
);
11041105
}
@@ -1330,13 +1331,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
13301331
if !any_successful_reexport {
13311332
let (ns, binding) = reexport_error.unwrap();
13321333
if let Some(extern_crate_id) = pub_use_of_private_extern_crate_hack(import, binding) {
1334+
let extern_crate_sp = self.tcx.source_span(self.local_def_id(extern_crate_id));
13331335
self.lint_buffer.buffer_lint(
13341336
PUB_USE_OF_PRIVATE_EXTERN_CRATE,
13351337
import_id,
13361338
import.span,
1337-
BuiltinLintDiag::PrivateExternCrateReexport {
1338-
source: ident,
1339-
extern_crate_span: self.tcx.source_span(self.local_def_id(extern_crate_id)),
1339+
crate::errors::PrivateExternCrateReexport {
1340+
ident,
1341+
sugg: extern_crate_sp.shrink_to_lo(),
13401342
},
13411343
);
13421344
} else if ns == TypeNS {

compiler/rustc_resolve/src/macros.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use rustc_hir::def::{self, DefKind, MacroKinds, Namespace, NonMacroAttrKind};
2121
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
2222
use rustc_middle::middle::stability;
2323
use rustc_middle::ty::{RegisteredTools, TyCtxt};
24-
use rustc_session::lint::BuiltinLintDiag;
2524
use rustc_session::lint::builtin::{
2625
LEGACY_DERIVE_HELPERS, OUT_OF_SCOPE_MACRO_CALLS, UNKNOWN_DIAGNOSTIC_ATTRIBUTES,
2726
UNUSED_MACRO_RULES, UNUSED_MACROS,
@@ -687,23 +686,24 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
687686
feature_err(&self.tcx.sess, sym::custom_inner_attributes, path.span, msg).emit();
688687
}
689688

689+
const DIAG_ATTRS: &[Symbol] =
690+
&[sym::on_unimplemented, sym::do_not_recommend, sym::on_const];
691+
690692
if res == Res::NonMacroAttr(NonMacroAttrKind::Tool)
691693
&& let [namespace, attribute, ..] = &*path.segments
692694
&& namespace.ident.name == sym::diagnostic
693-
&& ![sym::on_unimplemented, sym::do_not_recommend, sym::on_const]
694-
.contains(&attribute.ident.name)
695+
&& !DIAG_ATTRS.contains(&attribute.ident.name)
695696
{
696-
let typo_name = find_best_match_for_name(
697-
&[sym::on_unimplemented, sym::do_not_recommend, sym::on_const],
698-
attribute.ident.name,
699-
Some(5),
700-
);
697+
let span = attribute.span();
698+
699+
let typo = find_best_match_for_name(DIAG_ATTRS, attribute.ident.name, Some(5))
700+
.map(|typo_name| errors::UnknownDiagnosticAttributeTypoSugg { span, typo_name });
701701

702702
self.tcx.sess.psess.buffer_lint(
703703
UNKNOWN_DIAGNOSTIC_ATTRIBUTES,
704-
attribute.span(),
704+
span,
705705
node_id,
706-
BuiltinLintDiag::UnknownDiagnosticAttribute { span: attribute.span(), typo_name },
706+
errors::UnknownDiagnosticAttribute { typo },
707707
);
708708
}
709709

@@ -1130,9 +1130,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
11301130
OUT_OF_SCOPE_MACRO_CALLS,
11311131
path.span,
11321132
node_id,
1133-
BuiltinLintDiag::OutOfScopeMacroCalls {
1133+
errors::OutOfScopeMacroCalls {
11341134
span: path.span,
11351135
path: pprust::path_to_string(path),
1136+
// FIXME: Make this translatable.
11361137
location,
11371138
},
11381139
);

0 commit comments

Comments
 (0)