Skip to content

Commit 7ec1804

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

File tree

8 files changed

+81
-115
lines changed

8 files changed

+81
-115
lines changed

compiler/rustc_lint/messages.ftl

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -628,10 +628,6 @@ lint_opaque_hidden_inferred_bound = opaque type `{$ty}` does not satisfy its ass
628628
629629
lint_opaque_hidden_inferred_bound_sugg = add this bound
630630
631-
lint_out_of_scope_macro_calls = cannot find macro `{$path}` in the current scope when looking from {$location}
632-
.label = not found from {$location}
633-
.help = import `macro_rules` with `use` to make it callable above its definition
634-
635631
lint_overflowing_bin_hex = literal out of range for `{$ty}`
636632
.negative_note = the literal `{$lit}` (decimal `{$dec}`) does not fit into the type `{$ty}`
637633
.negative_becomes_note = and the value `-{$lit}` will become `{$actually}{$ty}`
@@ -667,9 +663,6 @@ lint_pattern_in_bodiless = patterns aren't allowed in functions without bodies
667663
lint_pattern_in_foreign = patterns aren't allowed in foreign function declarations
668664
.label = pattern not allowed in foreign function
669665
670-
lint_private_extern_crate_reexport = extern crate `{$ident}` is private and cannot be re-exported
671-
.suggestion = consider making the `extern crate` item publicly accessible
672-
673666
lint_query_instability = using `{$query}` can result in unstable query results
674667
.note = if you believe this case to be fine, allow this lint and add a comment explaining your rationale
675668
@@ -695,10 +688,6 @@ lint_redundant_import = the item `{$ident}` is imported redundantly
695688
.label_imported_prelude = the item `{$ident}` is already imported by the extern prelude
696689
.label_defined_prelude = the item `{$ident}` is already defined by the extern prelude
697690
698-
lint_redundant_import_visibility = glob import doesn't reexport anything with visibility `{$import_vis}` because no imported item is public enough
699-
.note = the most public imported item is `{$max_vis}`
700-
.help = reduce the glob import's visibility or increase visibility of imported items
701-
702691
lint_redundant_semicolons =
703692
unnecessary trailing {$multiple ->
704693
[true] semicolons
@@ -858,9 +847,6 @@ lint_unicode_text_flow = unicode codepoint changing visible direction of text pr
858847
lint_unit_bindings = binding has unit type `()`
859848
.label = this pattern is inferred to be the unit type `()`
860849
861-
lint_unknown_diagnostic_attribute = unknown diagnostic attribute
862-
lint_unknown_diagnostic_attribute_typo_sugg = an attribute with a similar name exists
863-
864850
lint_unknown_gated_lint =
865851
unknown lint: `{$name}`
866852
.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
@@ -2535,14 +2535,6 @@ pub(crate) mod unexpected_cfg_value {
25352535
}
25362536
}
25372537

2538-
#[derive(LintDiagnostic)]
2539-
#[diag(lint_private_extern_crate_reexport, code = E0365)]
2540-
pub(crate) struct PrivateExternCrateReexport {
2541-
pub ident: Ident,
2542-
#[suggestion(code = "pub ", style = "verbose", applicability = "maybe-incorrect")]
2543-
pub sugg: Span,
2544-
}
2545-
25462538
#[derive(LintDiagnostic)]
25472539
#[diag(lint_unused_crate_dependency)]
25482540
#[help]
@@ -2562,26 +2554,6 @@ pub(crate) struct IllFormedAttributeInput {
25622554
pub docs: &'static str,
25632555
}
25642556

2565-
#[derive(LintDiagnostic)]
2566-
#[diag(lint_unknown_diagnostic_attribute)]
2567-
pub(crate) struct UnknownDiagnosticAttribute {
2568-
#[subdiagnostic]
2569-
pub typo: Option<UnknownDiagnosticAttributeTypoSugg>,
2570-
}
2571-
2572-
#[derive(Subdiagnostic)]
2573-
#[suggestion(
2574-
lint_unknown_diagnostic_attribute_typo_sugg,
2575-
style = "verbose",
2576-
code = "{typo_name}",
2577-
applicability = "machine-applicable"
2578-
)]
2579-
pub(crate) struct UnknownDiagnosticAttributeTypoSugg {
2580-
#[primary_span]
2581-
pub span: Span,
2582-
pub typo_name: Symbol,
2583-
}
2584-
25852557
#[derive(LintDiagnostic)]
25862558
#[diag(lint_unicode_text_flow)]
25872559
#[note]
@@ -2881,18 +2853,6 @@ pub(crate) struct AssociatedConstElidedLifetime {
28812853
pub lifetimes_in_scope: MultiSpan,
28822854
}
28832855

2884-
#[derive(LintDiagnostic)]
2885-
#[diag(lint_redundant_import_visibility)]
2886-
pub(crate) struct RedundantImportVisibility {
2887-
#[note]
2888-
pub span: Span,
2889-
#[help]
2890-
pub help: (),
2891-
2892-
pub import_vis: String,
2893-
pub max_vis: String,
2894-
}
2895-
28962856
#[derive(LintDiagnostic)]
28972857
#[diag(lint_unsafe_attr_outside_unsafe)]
28982858
pub(crate) struct UnsafeAttrOutsideUnsafe {
@@ -2914,16 +2874,6 @@ pub(crate) struct UnsafeAttrOutsideUnsafeSuggestion {
29142874
pub right: Span,
29152875
}
29162876

2917-
#[derive(LintDiagnostic)]
2918-
#[diag(lint_out_of_scope_macro_calls)]
2919-
#[help]
2920-
pub(crate) struct OutOfScopeMacroCalls {
2921-
#[label]
2922-
pub span: Span,
2923-
pub path: String,
2924-
pub location: String,
2925-
}
2926-
29272877
#[derive(LintDiagnostic)]
29282878
#[diag(lint_static_mut_refs_lint)]
29292879
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
@@ -336,6 +336,10 @@ resolve_note_and_refers_to_the_item_defined_here =
336336
}
337337
}
338338
339+
resolve_out_of_scope_macro_calls = cannot find macro `{$path}` in the current scope when looking from {$location}
340+
.label = not found from {$location}
341+
.help = import `macro_rules` with `use` to make it callable above its definition
342+
339343
resolve_outer_ident_is_not_publicly_reexported =
340344
{$outer_ident_descr} `{$outer_ident}` is not publicly re-exported
341345
@@ -356,12 +360,19 @@ resolve_param_in_ty_of_const_param =
356360
357361
resolve_pattern_doesnt_bind_name = pattern doesn't bind `{$name}`
358362
363+
resolve_private_extern_crate_reexport = extern crate `{$ident}` is private and cannot be re-exported
364+
.suggestion = consider making the `extern crate` item publicly accessible
365+
359366
resolve_proc_macro_derive_resolution_fallback = cannot find {$ns_descr} `{$ident}` in this scope
360367
.label = names from parent modules are not accessible without an explicit import
361368
362369
resolve_proc_macro_same_crate = can't use a procedural macro from the same crate that defines it
363370
.help = you can define integration tests in a directory named `tests`
364371
372+
resolve_redundant_import_visibility = glob import doesn't reexport anything with visibility `{$import_vis}` because no imported item is public enough
373+
.note = the most public imported item is `{$max_vis}`
374+
.help = reduce the glob import's visibility or increase visibility of imported items
375+
365376
resolve_reexport_of_crate_public =
366377
re-export of crate public `{$ident}`
367378
@@ -467,6 +478,9 @@ resolve_unexpected_res_change_ty_to_const_param_sugg =
467478
resolve_unexpected_res_use_at_op_in_slice_pat_with_range_sugg =
468479
if you meant to collect the rest of the slice in `{$ident}`, use the at operator
469480
481+
resolve_unknown_diagnostic_attribute = unknown diagnostic attribute
482+
resolve_unknown_diagnostic_attribute_typo_sugg = an attribute with a similar name exists
483+
470484
resolve_unnamed_crate_root_import =
471485
crate root imports need to be explicitly named: `use crate as name;`
472486

compiler/rustc_resolve/src/errors.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,14 @@ pub(crate) struct CannotBeReexportedCratePublicNS {
784784
pub(crate) ident: Ident,
785785
}
786786

787+
#[derive(LintDiagnostic)]
788+
#[diag(resolve_private_extern_crate_reexport, code = E0365)]
789+
pub(crate) struct PrivateExternCrateReexport {
790+
pub ident: Ident,
791+
#[suggestion(code = "pub ", style = "verbose", applicability = "maybe-incorrect")]
792+
pub sugg: Span,
793+
}
794+
787795
#[derive(Subdiagnostic)]
788796
#[help(resolve_consider_adding_macro_export)]
789797
pub(crate) struct ConsiderAddingMacroExport {
@@ -1366,3 +1374,44 @@ pub(crate) struct ExternCrateNotIdiomatic {
13661374
pub span: Span,
13671375
pub code: &'static str,
13681376
}
1377+
1378+
#[derive(LintDiagnostic)]
1379+
#[diag(resolve_out_of_scope_macro_calls)]
1380+
#[help]
1381+
pub(crate) struct OutOfScopeMacroCalls {
1382+
#[label]
1383+
pub span: Span,
1384+
pub path: String,
1385+
pub location: String,
1386+
}
1387+
1388+
#[derive(LintDiagnostic)]
1389+
#[diag(resolve_redundant_import_visibility)]
1390+
pub(crate) struct RedundantImportVisibility {
1391+
#[note]
1392+
pub span: Span,
1393+
#[help]
1394+
pub help: (),
1395+
pub import_vis: String,
1396+
pub max_vis: String,
1397+
}
1398+
1399+
#[derive(LintDiagnostic)]
1400+
#[diag(resolve_unknown_diagnostic_attribute)]
1401+
pub(crate) struct UnknownDiagnosticAttribute {
1402+
#[subdiagnostic]
1403+
pub typo: Option<UnknownDiagnosticAttributeTypoSugg>,
1404+
}
1405+
1406+
#[derive(Subdiagnostic)]
1407+
#[suggestion(
1408+
resolve_unknown_diagnostic_attribute_typo_sugg,
1409+
style = "verbose",
1410+
code = "{typo_name}",
1411+
applicability = "machine-applicable"
1412+
)]
1413+
pub(crate) struct UnknownDiagnosticAttributeTypoSugg {
1414+
#[primary_span]
1415+
pub span: Span,
1416+
pub typo_name: Symbol,
1417+
}

compiler/rustc_resolve/src/imports.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,10 +1103,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
11031103
UNUSED_IMPORTS,
11041104
id,
11051105
import.span,
1106-
BuiltinLintDiag::RedundantImportVisibility {
1106+
crate::errors::RedundantImportVisibility {
1107+
span: import.span,
1108+
help: (),
11071109
max_vis: max_vis.to_string(def_id, self.tcx),
11081110
import_vis: import.vis.to_string(def_id, self.tcx),
1109-
span: import.span,
11101111
},
11111112
);
11121113
}
@@ -1338,13 +1339,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
13381339
if !any_successful_reexport {
13391340
let (ns, binding) = reexport_error.unwrap();
13401341
if let Some(extern_crate_id) = pub_use_of_private_extern_crate_hack(import, binding) {
1342+
let extern_crate_sp = self.tcx.source_span(self.local_def_id(extern_crate_id));
13411343
self.lint_buffer.buffer_lint(
13421344
PUB_USE_OF_PRIVATE_EXTERN_CRATE,
13431345
import_id,
13441346
import.span,
1345-
BuiltinLintDiag::PrivateExternCrateReexport {
1346-
source: ident,
1347-
extern_crate_span: self.tcx.source_span(self.local_def_id(extern_crate_id)),
1347+
crate::errors::PrivateExternCrateReexport {
1348+
ident,
1349+
sugg: extern_crate_sp.shrink_to_lo(),
13481350
},
13491351
);
13501352
} else if ns == TypeNS {

compiler/rustc_resolve/src/macros.rs

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

687+
const DIAG_ATTRS: &[Symbol] = &[sym::on_unimplemented, sym::do_not_recommend];
688+
688689
if res == Res::NonMacroAttr(NonMacroAttrKind::Tool)
689690
&& let [namespace, attribute, ..] = &*path.segments
690691
&& namespace.ident.name == sym::diagnostic
691-
&& ![sym::on_unimplemented, sym::do_not_recommend].contains(&attribute.ident.name)
692+
&& !DIAG_ATTRS.contains(&attribute.ident.name)
692693
{
693-
let typo_name = find_best_match_for_name(
694-
&[sym::on_unimplemented, sym::do_not_recommend],
695-
attribute.ident.name,
696-
Some(5),
697-
);
694+
let span = attribute.span();
695+
696+
let typo = find_best_match_for_name(DIAG_ATTRS, attribute.ident.name, Some(5))
697+
.map(|typo_name| errors::UnknownDiagnosticAttributeTypoSugg { span, typo_name });
698698

699699
self.tcx.sess.psess.buffer_lint(
700700
UNKNOWN_DIAGNOSTIC_ATTRIBUTES,
701-
attribute.span(),
701+
span,
702702
node_id,
703-
BuiltinLintDiag::UnknownDiagnosticAttribute { span: attribute.span(), typo_name },
703+
errors::UnknownDiagnosticAttribute { typo },
704704
);
705705
}
706706

@@ -1134,9 +1134,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
11341134
OUT_OF_SCOPE_MACRO_CALLS,
11351135
path.span,
11361136
node_id,
1137-
BuiltinLintDiag::OutOfScopeMacroCalls {
1137+
errors::OutOfScopeMacroCalls {
11381138
span: path.span,
11391139
path: pprust::path_to_string(path),
1140+
// FIXME: Make this translatable.
11401141
location,
11411142
},
11421143
);

0 commit comments

Comments
 (0)