Move more early buffered lints to dyn lint diagnostics (6/N)
This commit is contained in:
parent
74d12e8598
commit
3ad6359f54
8 changed files with 82 additions and 116 deletions
|
|
@ -642,10 +642,6 @@ lint_opaque_hidden_inferred_bound = opaque type `{$ty}` does not satisfy its ass
|
|||
|
||||
lint_opaque_hidden_inferred_bound_sugg = add this bound
|
||||
|
||||
lint_out_of_scope_macro_calls = cannot find macro `{$path}` in the current scope when looking from {$location}
|
||||
.label = not found from {$location}
|
||||
.help = import `macro_rules` with `use` to make it callable above its definition
|
||||
|
||||
lint_overflowing_bin_hex = literal out of range for `{$ty}`
|
||||
.negative_note = the literal `{$lit}` (decimal `{$dec}`) does not fit into the type `{$ty}`
|
||||
.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
|
|||
lint_pattern_in_foreign = patterns aren't allowed in foreign function declarations
|
||||
.label = pattern not allowed in foreign function
|
||||
|
||||
lint_private_extern_crate_reexport = extern crate `{$ident}` is private and cannot be re-exported
|
||||
.suggestion = consider making the `extern crate` item publicly accessible
|
||||
|
||||
lint_query_instability = using `{$query}` can result in unstable query results
|
||||
.note = if you believe this case to be fine, allow this lint and add a comment explaining your rationale
|
||||
|
||||
|
|
@ -709,10 +702,6 @@ lint_redundant_import = the item `{$ident}` is imported redundantly
|
|||
.label_imported_prelude = the item `{$ident}` is already imported by the extern prelude
|
||||
.label_defined_prelude = the item `{$ident}` is already defined by the extern prelude
|
||||
|
||||
lint_redundant_import_visibility = glob import doesn't reexport anything with visibility `{$import_vis}` because no imported item is public enough
|
||||
.note = the most public imported item is `{$max_vis}`
|
||||
.help = reduce the glob import's visibility or increase visibility of imported items
|
||||
|
||||
lint_redundant_semicolons =
|
||||
unnecessary trailing {$multiple ->
|
||||
[true] semicolons
|
||||
|
|
@ -872,9 +861,6 @@ lint_unicode_text_flow = unicode codepoint changing visible direction of text pr
|
|||
lint_unit_bindings = binding has unit type `()`
|
||||
.label = this pattern is inferred to be the unit type `()`
|
||||
|
||||
lint_unknown_diagnostic_attribute = unknown diagnostic attribute
|
||||
lint_unknown_diagnostic_attribute_typo_sugg = an attribute with a similar name exists
|
||||
|
||||
lint_unknown_gated_lint =
|
||||
unknown lint: `{$name}`
|
||||
.note = the `{$name}` lint is unstable
|
||||
|
|
|
|||
|
|
@ -311,21 +311,6 @@ pub fn decorate_builtin_lint(
|
|||
}
|
||||
.decorate_lint(diag);
|
||||
}
|
||||
BuiltinLintDiag::RedundantImportVisibility { max_vis, span: vis_span, import_vis } => {
|
||||
lints::RedundantImportVisibility { span: vis_span, help: (), max_vis, import_vis }
|
||||
.decorate_lint(diag);
|
||||
}
|
||||
BuiltinLintDiag::UnknownDiagnosticAttribute { span: typo_span, typo_name } => {
|
||||
let typo = typo_name.map(|typo_name| lints::UnknownDiagnosticAttributeTypoSugg {
|
||||
span: typo_span,
|
||||
typo_name,
|
||||
});
|
||||
lints::UnknownDiagnosticAttribute { typo }.decorate_lint(diag);
|
||||
}
|
||||
BuiltinLintDiag::PrivateExternCrateReexport { source: ident, extern_crate_span } => {
|
||||
lints::PrivateExternCrateReexport { ident, sugg: extern_crate_span.shrink_to_lo() }
|
||||
.decorate_lint(diag);
|
||||
}
|
||||
BuiltinLintDiag::UnusedCrateDependency { extern_crate, local_crate } => {
|
||||
lints::UnusedCrateDependency { extern_crate, local_crate }.decorate_lint(diag)
|
||||
}
|
||||
|
|
@ -340,8 +325,5 @@ pub fn decorate_builtin_lint(
|
|||
}
|
||||
.decorate_lint(diag)
|
||||
}
|
||||
BuiltinLintDiag::OutOfScopeMacroCalls { span, path, location } => {
|
||||
lints::OutOfScopeMacroCalls { span, path, location }.decorate_lint(diag)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2575,14 +2575,6 @@ pub(crate) mod unexpected_cfg_value {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(lint_private_extern_crate_reexport, code = E0365)]
|
||||
pub(crate) struct PrivateExternCrateReexport {
|
||||
pub ident: Ident,
|
||||
#[suggestion(code = "pub ", style = "verbose", applicability = "maybe-incorrect")]
|
||||
pub sugg: Span,
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(lint_unused_crate_dependency)]
|
||||
#[help]
|
||||
|
|
@ -2602,26 +2594,6 @@ pub(crate) struct IllFormedAttributeInput {
|
|||
pub docs: &'static str,
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(lint_unknown_diagnostic_attribute)]
|
||||
pub(crate) struct UnknownDiagnosticAttribute {
|
||||
#[subdiagnostic]
|
||||
pub typo: Option<UnknownDiagnosticAttributeTypoSugg>,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[suggestion(
|
||||
lint_unknown_diagnostic_attribute_typo_sugg,
|
||||
style = "verbose",
|
||||
code = "{typo_name}",
|
||||
applicability = "machine-applicable"
|
||||
)]
|
||||
pub(crate) struct UnknownDiagnosticAttributeTypoSugg {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub typo_name: Symbol,
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(lint_unicode_text_flow)]
|
||||
#[note]
|
||||
|
|
@ -2921,18 +2893,6 @@ pub(crate) struct AssociatedConstElidedLifetime {
|
|||
pub lifetimes_in_scope: MultiSpan,
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(lint_redundant_import_visibility)]
|
||||
pub(crate) struct RedundantImportVisibility {
|
||||
#[note]
|
||||
pub span: Span,
|
||||
#[help]
|
||||
pub help: (),
|
||||
|
||||
pub import_vis: String,
|
||||
pub max_vis: String,
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(lint_unsafe_attr_outside_unsafe)]
|
||||
pub(crate) struct UnsafeAttrOutsideUnsafe {
|
||||
|
|
@ -2954,16 +2914,6 @@ pub(crate) struct UnsafeAttrOutsideUnsafeSuggestion {
|
|||
pub right: Span,
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(lint_out_of_scope_macro_calls)]
|
||||
#[help]
|
||||
pub(crate) struct OutOfScopeMacroCalls {
|
||||
#[label]
|
||||
pub span: Span,
|
||||
pub path: String,
|
||||
pub location: String,
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(lint_static_mut_refs_lint)]
|
||||
pub(crate) struct RefOfMutStatic<'a> {
|
||||
|
|
|
|||
|
|
@ -714,19 +714,6 @@ pub enum BuiltinLintDiag {
|
|||
span: Span,
|
||||
lifetimes_in_scope: MultiSpan,
|
||||
},
|
||||
RedundantImportVisibility {
|
||||
span: Span,
|
||||
max_vis: String,
|
||||
import_vis: String,
|
||||
},
|
||||
UnknownDiagnosticAttribute {
|
||||
span: Span,
|
||||
typo_name: Option<Symbol>,
|
||||
},
|
||||
PrivateExternCrateReexport {
|
||||
source: Ident,
|
||||
extern_crate_span: Span,
|
||||
},
|
||||
UnusedCrateDependency {
|
||||
extern_crate: Symbol,
|
||||
local_crate: Symbol,
|
||||
|
|
@ -735,11 +722,6 @@ pub enum BuiltinLintDiag {
|
|||
suggestions: Vec<String>,
|
||||
docs: Option<&'static str>,
|
||||
},
|
||||
OutOfScopeMacroCalls {
|
||||
span: Span,
|
||||
path: String,
|
||||
location: String,
|
||||
},
|
||||
}
|
||||
|
||||
pub type RegisteredTools = FxIndexSet<Ident>;
|
||||
|
|
|
|||
|
|
@ -342,6 +342,10 @@ resolve_note_and_refers_to_the_item_defined_here =
|
|||
}
|
||||
}
|
||||
|
||||
resolve_out_of_scope_macro_calls = cannot find macro `{$path}` in the current scope when looking from {$location}
|
||||
.label = not found from {$location}
|
||||
.help = import `macro_rules` with `use` to make it callable above its definition
|
||||
|
||||
resolve_outer_ident_is_not_publicly_reexported =
|
||||
{$outer_ident_descr} `{$outer_ident}` is not publicly re-exported
|
||||
|
||||
|
|
@ -362,12 +366,19 @@ resolve_param_in_ty_of_const_param =
|
|||
|
||||
resolve_pattern_doesnt_bind_name = pattern doesn't bind `{$name}`
|
||||
|
||||
resolve_private_extern_crate_reexport = extern crate `{$ident}` is private and cannot be re-exported
|
||||
.suggestion = consider making the `extern crate` item publicly accessible
|
||||
|
||||
resolve_proc_macro_derive_resolution_fallback = cannot find {$ns_descr} `{$ident}` in this scope
|
||||
.label = names from parent modules are not accessible without an explicit import
|
||||
|
||||
resolve_proc_macro_same_crate = can't use a procedural macro from the same crate that defines it
|
||||
.help = you can define integration tests in a directory named `tests`
|
||||
|
||||
resolve_redundant_import_visibility = glob import doesn't reexport anything with visibility `{$import_vis}` because no imported item is public enough
|
||||
.note = the most public imported item is `{$max_vis}`
|
||||
.help = reduce the glob import's visibility or increase visibility of imported items
|
||||
|
||||
resolve_reexport_of_crate_public =
|
||||
re-export of crate public `{$ident}`
|
||||
|
||||
|
|
@ -473,6 +484,9 @@ resolve_unexpected_res_change_ty_to_const_param_sugg =
|
|||
resolve_unexpected_res_use_at_op_in_slice_pat_with_range_sugg =
|
||||
if you meant to collect the rest of the slice in `{$ident}`, use the at operator
|
||||
|
||||
resolve_unknown_diagnostic_attribute = unknown diagnostic attribute
|
||||
resolve_unknown_diagnostic_attribute_typo_sugg = an attribute with a similar name exists
|
||||
|
||||
resolve_unnamed_crate_root_import =
|
||||
crate root imports need to be explicitly named: `use crate as name;`
|
||||
|
||||
|
|
|
|||
|
|
@ -812,6 +812,14 @@ pub(crate) struct CannotBeReexportedCratePublicNS {
|
|||
pub(crate) ident: Ident,
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(resolve_private_extern_crate_reexport, code = E0365)]
|
||||
pub(crate) struct PrivateExternCrateReexport {
|
||||
pub ident: Ident,
|
||||
#[suggestion(code = "pub ", style = "verbose", applicability = "maybe-incorrect")]
|
||||
pub sugg: Span,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[help(resolve_consider_adding_macro_export)]
|
||||
pub(crate) struct ConsiderAddingMacroExport {
|
||||
|
|
@ -1396,3 +1404,44 @@ pub(crate) struct ExternCrateNotIdiomatic {
|
|||
pub span: Span,
|
||||
pub code: &'static str,
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(resolve_out_of_scope_macro_calls)]
|
||||
#[help]
|
||||
pub(crate) struct OutOfScopeMacroCalls {
|
||||
#[label]
|
||||
pub span: Span,
|
||||
pub path: String,
|
||||
pub location: String,
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(resolve_redundant_import_visibility)]
|
||||
pub(crate) struct RedundantImportVisibility {
|
||||
#[note]
|
||||
pub span: Span,
|
||||
#[help]
|
||||
pub help: (),
|
||||
pub import_vis: String,
|
||||
pub max_vis: String,
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(resolve_unknown_diagnostic_attribute)]
|
||||
pub(crate) struct UnknownDiagnosticAttribute {
|
||||
#[subdiagnostic]
|
||||
pub typo: Option<UnknownDiagnosticAttributeTypoSugg>,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[suggestion(
|
||||
resolve_unknown_diagnostic_attribute_typo_sugg,
|
||||
style = "verbose",
|
||||
code = "{typo_name}",
|
||||
applicability = "machine-applicable"
|
||||
)]
|
||||
pub(crate) struct UnknownDiagnosticAttributeTypoSugg {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub typo_name: Symbol,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1095,10 +1095,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
UNUSED_IMPORTS,
|
||||
id,
|
||||
import.span,
|
||||
BuiltinLintDiag::RedundantImportVisibility {
|
||||
crate::errors::RedundantImportVisibility {
|
||||
span: import.span,
|
||||
help: (),
|
||||
max_vis: max_vis.to_string(def_id, self.tcx),
|
||||
import_vis: import.vis.to_string(def_id, self.tcx),
|
||||
span: import.span,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
@ -1330,13 +1331,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
if !any_successful_reexport {
|
||||
let (ns, binding) = reexport_error.unwrap();
|
||||
if let Some(extern_crate_id) = pub_use_of_private_extern_crate_hack(import, binding) {
|
||||
let extern_crate_sp = self.tcx.source_span(self.local_def_id(extern_crate_id));
|
||||
self.lint_buffer.buffer_lint(
|
||||
PUB_USE_OF_PRIVATE_EXTERN_CRATE,
|
||||
import_id,
|
||||
import.span,
|
||||
BuiltinLintDiag::PrivateExternCrateReexport {
|
||||
source: ident,
|
||||
extern_crate_span: self.tcx.source_span(self.local_def_id(extern_crate_id)),
|
||||
crate::errors::PrivateExternCrateReexport {
|
||||
ident,
|
||||
sugg: extern_crate_sp.shrink_to_lo(),
|
||||
},
|
||||
);
|
||||
} else if ns == TypeNS {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ use rustc_hir::def::{self, DefKind, MacroKinds, Namespace, NonMacroAttrKind};
|
|||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
|
||||
use rustc_middle::middle::stability;
|
||||
use rustc_middle::ty::{RegisteredTools, TyCtxt};
|
||||
use rustc_session::lint::BuiltinLintDiag;
|
||||
use rustc_session::lint::builtin::{
|
||||
LEGACY_DERIVE_HELPERS, OUT_OF_SCOPE_MACRO_CALLS, UNKNOWN_DIAGNOSTIC_ATTRIBUTES,
|
||||
UNUSED_MACRO_RULES, UNUSED_MACROS,
|
||||
|
|
@ -687,23 +686,24 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
feature_err(&self.tcx.sess, sym::custom_inner_attributes, path.span, msg).emit();
|
||||
}
|
||||
|
||||
const DIAG_ATTRS: &[Symbol] =
|
||||
&[sym::on_unimplemented, sym::do_not_recommend, sym::on_const];
|
||||
|
||||
if res == Res::NonMacroAttr(NonMacroAttrKind::Tool)
|
||||
&& let [namespace, attribute, ..] = &*path.segments
|
||||
&& namespace.ident.name == sym::diagnostic
|
||||
&& ![sym::on_unimplemented, sym::do_not_recommend, sym::on_const]
|
||||
.contains(&attribute.ident.name)
|
||||
&& !DIAG_ATTRS.contains(&attribute.ident.name)
|
||||
{
|
||||
let typo_name = find_best_match_for_name(
|
||||
&[sym::on_unimplemented, sym::do_not_recommend, sym::on_const],
|
||||
attribute.ident.name,
|
||||
Some(5),
|
||||
);
|
||||
let span = attribute.span();
|
||||
|
||||
let typo = find_best_match_for_name(DIAG_ATTRS, attribute.ident.name, Some(5))
|
||||
.map(|typo_name| errors::UnknownDiagnosticAttributeTypoSugg { span, typo_name });
|
||||
|
||||
self.tcx.sess.psess.buffer_lint(
|
||||
UNKNOWN_DIAGNOSTIC_ATTRIBUTES,
|
||||
attribute.span(),
|
||||
span,
|
||||
node_id,
|
||||
BuiltinLintDiag::UnknownDiagnosticAttribute { span: attribute.span(), typo_name },
|
||||
errors::UnknownDiagnosticAttribute { typo },
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -1130,9 +1130,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
OUT_OF_SCOPE_MACRO_CALLS,
|
||||
path.span,
|
||||
node_id,
|
||||
BuiltinLintDiag::OutOfScopeMacroCalls {
|
||||
errors::OutOfScopeMacroCalls {
|
||||
span: path.span,
|
||||
path: pprust::path_to_string(path),
|
||||
// FIXME: Make this translatable.
|
||||
location,
|
||||
},
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue