2022-11-13 15:42:49 +00:00
|
|
|
#![allow(rustc::diagnostic_outside_of_impl)]
|
2024-02-05 22:51:39 +00:00
|
|
|
#![allow(rustc::untranslatable_diagnostic)]
|
2024-01-29 22:59:09 +00:00
|
|
|
use std::num::NonZero;
|
2022-10-23 01:50:44 +00:00
|
|
|
|
2023-08-28 19:28:51 +00:00
|
|
|
use crate::errors::RequestedLevel;
|
2022-10-13 09:13:02 +00:00
|
|
|
use crate::fluent_generated as fluent;
|
2022-11-12 03:39:37 +00:00
|
|
|
use rustc_errors::{
|
2024-04-15 18:07:22 +00:00
|
|
|
codes::*, Applicability, Diag, DiagArgValue, DiagMessage, DiagStyledString,
|
2024-05-14 10:41:27 +00:00
|
|
|
ElidedLifetimeInPathSubdiag, EmissionGuarantee, LintDiagnostic, MultiSpan, SubdiagMessageOp,
|
2024-04-15 18:07:22 +00:00
|
|
|
Subdiagnostic, SuggestionStyle,
|
2022-11-12 03:39:37 +00:00
|
|
|
};
|
2024-04-15 18:07:22 +00:00
|
|
|
use rustc_hir::{def::Namespace, def_id::DefId};
|
2022-09-22 00:47:24 +00:00
|
|
|
use rustc_macros::{LintDiagnostic, Subdiagnostic};
|
2023-11-18 19:29:39 +00:00
|
|
|
use rustc_middle::ty::{
|
|
|
|
inhabitedness::InhabitedPredicate, Clause, PolyExistentialTraitRef, Ty, TyCtxt,
|
|
|
|
};
|
2024-04-15 18:07:22 +00:00
|
|
|
use rustc_session::{lint::AmbiguityErrorDiag, Session};
|
|
|
|
use rustc_span::{
|
|
|
|
edition::Edition,
|
|
|
|
sym,
|
|
|
|
symbol::{Ident, MacroRulesNormalizedIdent},
|
|
|
|
Span, Symbol,
|
|
|
|
};
|
2022-08-28 23:07:58 +00:00
|
|
|
|
2022-11-13 14:46:31 +00:00
|
|
|
use crate::{
|
|
|
|
builtin::InitError, builtin::TypeAliasBounds, errors::OverruledAttributeSub, LateContext,
|
|
|
|
};
|
2022-09-04 19:46:35 +00:00
|
|
|
|
2022-10-04 23:39:02 +00:00
|
|
|
// array_into_iter.rs
|
2022-09-18 14:03:35 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
2024-04-17 20:32:17 +00:00
|
|
|
#[diag(lint_shadowed_into_iter)]
|
|
|
|
pub struct ShadowedIntoIterDiag {
|
|
|
|
pub target: &'static str,
|
|
|
|
pub edition: &'static str,
|
2022-10-13 09:13:02 +00:00
|
|
|
#[suggestion(lint_use_iter_suggestion, code = "iter", applicability = "machine-applicable")]
|
2022-09-18 14:03:35 +00:00
|
|
|
pub suggestion: Span,
|
|
|
|
#[subdiagnostic]
|
2024-04-17 20:32:17 +00:00
|
|
|
pub sub: Option<ShadowedIntoIterDiagSub>,
|
2022-09-18 14:03:35 +00:00
|
|
|
}
|
|
|
|
|
2022-09-22 00:47:24 +00:00
|
|
|
#[derive(Subdiagnostic)]
|
2024-04-17 20:32:17 +00:00
|
|
|
pub enum ShadowedIntoIterDiagSub {
|
2022-10-13 09:13:02 +00:00
|
|
|
#[suggestion(lint_remove_into_iter_suggestion, code = "", applicability = "maybe-incorrect")]
|
2022-09-18 14:03:35 +00:00
|
|
|
RemoveIntoIter {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
},
|
2022-10-13 09:13:02 +00:00
|
|
|
#[multipart_suggestion(
|
|
|
|
lint_use_explicit_into_iter_suggestion,
|
|
|
|
applicability = "maybe-incorrect"
|
|
|
|
)]
|
2022-09-18 14:03:35 +00:00
|
|
|
UseExplicitIntoIter {
|
|
|
|
#[suggestion_part(code = "IntoIterator::into_iter(")]
|
|
|
|
start_span: Span,
|
|
|
|
#[suggestion_part(code = ")")]
|
|
|
|
end_span: Span,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-10-23 01:50:44 +00:00
|
|
|
// builtin.rs
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_builtin_while_true)]
|
|
|
|
pub struct BuiltinWhileTrue {
|
|
|
|
#[suggestion(style = "short", code = "{replace}", applicability = "machine-applicable")]
|
|
|
|
pub suggestion: Span,
|
|
|
|
pub replace: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_builtin_box_pointers)]
|
|
|
|
pub struct BuiltinBoxPointers<'a> {
|
|
|
|
pub ty: Ty<'a>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_builtin_non_shorthand_field_patterns)]
|
|
|
|
pub struct BuiltinNonShorthandFieldPatterns {
|
|
|
|
pub ident: Ident,
|
|
|
|
#[suggestion(code = "{prefix}{ident}", applicability = "machine-applicable")]
|
|
|
|
pub suggestion: Span,
|
|
|
|
pub prefix: &'static str,
|
|
|
|
}
|
|
|
|
|
2022-11-13 01:18:55 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
pub enum BuiltinUnsafe {
|
|
|
|
#[diag(lint_builtin_allow_internal_unsafe)]
|
|
|
|
AllowInternalUnsafe,
|
|
|
|
#[diag(lint_builtin_unsafe_block)]
|
|
|
|
UnsafeBlock,
|
|
|
|
#[diag(lint_builtin_unsafe_trait)]
|
|
|
|
UnsafeTrait,
|
|
|
|
#[diag(lint_builtin_unsafe_impl)]
|
|
|
|
UnsafeImpl,
|
|
|
|
#[diag(lint_builtin_no_mangle_fn)]
|
|
|
|
#[note(lint_builtin_overridden_symbol_name)]
|
|
|
|
NoMangleFn,
|
|
|
|
#[diag(lint_builtin_export_name_fn)]
|
|
|
|
#[note(lint_builtin_overridden_symbol_name)]
|
|
|
|
ExportNameFn,
|
|
|
|
#[diag(lint_builtin_link_section_fn)]
|
|
|
|
#[note(lint_builtin_overridden_symbol_section)]
|
|
|
|
LinkSectionFn,
|
|
|
|
#[diag(lint_builtin_no_mangle_static)]
|
|
|
|
#[note(lint_builtin_overridden_symbol_name)]
|
|
|
|
NoMangleStatic,
|
|
|
|
#[diag(lint_builtin_export_name_static)]
|
|
|
|
#[note(lint_builtin_overridden_symbol_name)]
|
|
|
|
ExportNameStatic,
|
|
|
|
#[diag(lint_builtin_link_section_static)]
|
|
|
|
#[note(lint_builtin_overridden_symbol_section)]
|
|
|
|
LinkSectionStatic,
|
|
|
|
#[diag(lint_builtin_no_mangle_method)]
|
|
|
|
#[note(lint_builtin_overridden_symbol_name)]
|
|
|
|
NoMangleMethod,
|
|
|
|
#[diag(lint_builtin_export_name_method)]
|
|
|
|
#[note(lint_builtin_overridden_symbol_name)]
|
|
|
|
ExportNameMethod,
|
|
|
|
#[diag(lint_builtin_decl_unsafe_fn)]
|
|
|
|
DeclUnsafeFn,
|
|
|
|
#[diag(lint_builtin_decl_unsafe_method)]
|
|
|
|
DeclUnsafeMethod,
|
|
|
|
#[diag(lint_builtin_impl_unsafe_method)]
|
|
|
|
ImplUnsafeMethod,
|
2024-02-19 23:14:53 +00:00
|
|
|
#[diag(lint_builtin_global_asm)]
|
|
|
|
#[note(lint_builtin_global_macro_unsafety)]
|
|
|
|
GlobalAsm,
|
2022-11-13 01:18:55 +00:00
|
|
|
}
|
2022-10-23 01:50:44 +00:00
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_builtin_missing_doc)]
|
|
|
|
pub struct BuiltinMissingDoc<'a> {
|
|
|
|
pub article: &'a str,
|
|
|
|
pub desc: &'a str,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_builtin_missing_copy_impl)]
|
|
|
|
pub struct BuiltinMissingCopyImpl;
|
|
|
|
|
|
|
|
pub struct BuiltinMissingDebugImpl<'a> {
|
|
|
|
pub tcx: TyCtxt<'a>,
|
|
|
|
pub def_id: DefId,
|
|
|
|
}
|
|
|
|
|
2022-11-11 00:32:30 +00:00
|
|
|
// Needed for def_path_str
|
2024-03-08 01:03:51 +00:00
|
|
|
impl<'a> LintDiagnostic<'a, ()> for BuiltinMissingDebugImpl<'_> {
|
2024-02-22 23:20:45 +00:00
|
|
|
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::Diag<'a, ()>) {
|
2024-05-22 14:46:05 +00:00
|
|
|
diag.primary_message(fluent::lint_builtin_missing_debug_impl);
|
2023-12-23 22:08:41 +00:00
|
|
|
diag.arg("debug", self.tcx.def_path_str(self.def_id));
|
2022-10-23 01:50:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_builtin_anonymous_params)]
|
|
|
|
pub struct BuiltinAnonymousParams<'a> {
|
|
|
|
#[suggestion(code = "_: {ty_snip}")]
|
|
|
|
pub suggestion: (Span, Applicability),
|
|
|
|
pub ty_snip: &'a str,
|
|
|
|
}
|
|
|
|
|
2022-11-13 14:46:31 +00:00
|
|
|
// FIXME(davidtwco) translatable deprecated attr
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_builtin_deprecated_attr_link)]
|
|
|
|
pub struct BuiltinDeprecatedAttrLink<'a> {
|
|
|
|
pub name: Symbol,
|
|
|
|
pub reason: &'a str,
|
|
|
|
pub link: &'a str,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub suggestion: BuiltinDeprecatedAttrLinkSuggestion<'a>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
pub enum BuiltinDeprecatedAttrLinkSuggestion<'a> {
|
2022-10-13 09:13:02 +00:00
|
|
|
#[suggestion(lint_msg_suggestion, code = "", applicability = "machine-applicable")]
|
2022-11-13 14:46:31 +00:00
|
|
|
Msg {
|
|
|
|
#[primary_span]
|
|
|
|
suggestion: Span,
|
|
|
|
msg: &'a str,
|
|
|
|
},
|
2022-10-13 09:13:02 +00:00
|
|
|
#[suggestion(lint_default_suggestion, code = "", applicability = "machine-applicable")]
|
2022-11-13 14:46:31 +00:00
|
|
|
Default {
|
|
|
|
#[primary_span]
|
|
|
|
suggestion: Span,
|
|
|
|
},
|
|
|
|
}
|
2022-10-23 01:50:44 +00:00
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_builtin_deprecated_attr_used)]
|
|
|
|
pub struct BuiltinDeprecatedAttrUsed {
|
|
|
|
pub name: String,
|
|
|
|
#[suggestion(
|
|
|
|
lint_builtin_deprecated_attr_default_suggestion,
|
|
|
|
style = "short",
|
|
|
|
code = "",
|
|
|
|
applicability = "machine-applicable"
|
|
|
|
)]
|
|
|
|
pub suggestion: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_builtin_unused_doc_comment)]
|
|
|
|
pub struct BuiltinUnusedDocComment<'a> {
|
|
|
|
pub kind: &'a str,
|
|
|
|
#[label]
|
|
|
|
pub label: Span,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub sub: BuiltinUnusedDocCommentSub,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
pub enum BuiltinUnusedDocCommentSub {
|
2022-10-13 09:13:02 +00:00
|
|
|
#[help(lint_plain_help)]
|
2022-10-23 01:50:44 +00:00
|
|
|
PlainHelp,
|
2022-10-13 09:13:02 +00:00
|
|
|
#[help(lint_block_help)]
|
2022-10-23 01:50:44 +00:00
|
|
|
BlockHelp,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_builtin_no_mangle_generic)]
|
|
|
|
pub struct BuiltinNoMangleGeneric {
|
|
|
|
// Use of `#[no_mangle]` suggests FFI intent; correct
|
|
|
|
// fix may be to monomorphize source by hand
|
|
|
|
#[suggestion(style = "short", code = "", applicability = "maybe-incorrect")]
|
|
|
|
pub suggestion: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_builtin_const_no_mangle)]
|
|
|
|
pub struct BuiltinConstNoMangle {
|
|
|
|
#[suggestion(code = "pub static", applicability = "machine-applicable")]
|
|
|
|
pub suggestion: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_builtin_mutable_transmutes)]
|
|
|
|
pub struct BuiltinMutablesTransmutes;
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_builtin_unstable_features)]
|
|
|
|
pub struct BuiltinUnstableFeatures;
|
|
|
|
|
2022-11-13 14:46:31 +00:00
|
|
|
// lint_ungated_async_fn_track_caller
|
|
|
|
pub struct BuiltinUngatedAsyncFnTrackCaller<'a> {
|
|
|
|
pub label: Span,
|
2024-01-10 05:37:30 +00:00
|
|
|
pub session: &'a Session,
|
2022-11-13 14:46:31 +00:00
|
|
|
}
|
|
|
|
|
2024-03-08 01:03:51 +00:00
|
|
|
impl<'a> LintDiagnostic<'a, ()> for BuiltinUngatedAsyncFnTrackCaller<'_> {
|
2024-02-22 23:20:45 +00:00
|
|
|
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
|
2024-05-22 14:46:05 +00:00
|
|
|
diag.primary_message(fluent::lint_ungated_async_fn_track_caller);
|
2022-10-13 09:13:02 +00:00
|
|
|
diag.span_label(self.label, fluent::lint_label);
|
2022-11-13 14:46:31 +00:00
|
|
|
rustc_session::parse::add_feature_diagnostics(
|
|
|
|
diag,
|
2024-01-10 05:37:30 +00:00
|
|
|
self.session,
|
2023-05-30 21:32:29 +00:00
|
|
|
sym::async_fn_track_caller,
|
2022-11-13 14:46:31 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-23 01:50:44 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_builtin_unreachable_pub)]
|
|
|
|
pub struct BuiltinUnreachablePub<'a> {
|
|
|
|
pub what: &'a str,
|
|
|
|
#[suggestion(code = "pub(crate)")]
|
|
|
|
pub suggestion: (Span, Applicability),
|
|
|
|
#[help]
|
|
|
|
pub help: Option<()>,
|
|
|
|
}
|
|
|
|
|
2022-11-13 14:46:31 +00:00
|
|
|
pub struct SuggestChangingAssocTypes<'a, 'b> {
|
|
|
|
pub ty: &'a rustc_hir::Ty<'b>,
|
|
|
|
}
|
|
|
|
|
2024-03-06 03:00:16 +00:00
|
|
|
impl<'a, 'b> Subdiagnostic for SuggestChangingAssocTypes<'a, 'b> {
|
|
|
|
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
|
Reduce capabilities of `Diagnostic`.
Currently many diagnostic modifier methods are available on both
`Diagnostic` and `DiagnosticBuilder`. This commit removes most of them
from `Diagnostic`. To minimize the diff size, it keeps them within
`diagnostic.rs` but changes the surrounding `impl Diagnostic` block to
`impl DiagnosticBuilder`. (I intend to move things around later, to give
a more sensible code layout.)
`Diagnostic` keeps a few methods that it still needs, like `sub`,
`arg`, and `replace_args`.
The `forward!` macro, which defined two additional methods per call
(e.g. `note` and `with_note`), is replaced by the `with_fn!` macro,
which defines one additional method per call (e.g. `with_note`). It's
now also only used when necessary -- not all modifier methods currently
need a `with_*` form. (New ones can be easily added as necessary.)
All this also requires changing `trait AddToDiagnostic` so its methods
take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many
mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`.
There are three subdiagnostics -- `DelayedAtWithoutNewline`,
`DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` --
that are created within the diagnostics machinery and appended to
external diagnostics. These are handled at the `Diagnostic` level, which
means it's now hard to construct them via `derive(Diagnostic)`, so
instead we construct them by hand. This has no effect on what they look
like when printed.
There are lots of new `allow` markers for `untranslatable_diagnostics`
and `diagnostics_outside_of_impl`. This is because
`#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic`
modifier methods, but missing from the `DiagnosticBuilder` modifier
methods. They're now present.
2024-02-06 05:44:30 +00:00
|
|
|
self,
|
2024-02-22 23:20:45 +00:00
|
|
|
diag: &mut Diag<'_, G>,
|
2024-04-18 19:18:35 +00:00
|
|
|
_f: &F,
|
Reduce capabilities of `Diagnostic`.
Currently many diagnostic modifier methods are available on both
`Diagnostic` and `DiagnosticBuilder`. This commit removes most of them
from `Diagnostic`. To minimize the diff size, it keeps them within
`diagnostic.rs` but changes the surrounding `impl Diagnostic` block to
`impl DiagnosticBuilder`. (I intend to move things around later, to give
a more sensible code layout.)
`Diagnostic` keeps a few methods that it still needs, like `sub`,
`arg`, and `replace_args`.
The `forward!` macro, which defined two additional methods per call
(e.g. `note` and `with_note`), is replaced by the `with_fn!` macro,
which defines one additional method per call (e.g. `with_note`). It's
now also only used when necessary -- not all modifier methods currently
need a `with_*` form. (New ones can be easily added as necessary.)
All this also requires changing `trait AddToDiagnostic` so its methods
take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many
mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`.
There are three subdiagnostics -- `DelayedAtWithoutNewline`,
`DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` --
that are created within the diagnostics machinery and appended to
external diagnostics. These are handled at the `Diagnostic` level, which
means it's now hard to construct them via `derive(Diagnostic)`, so
instead we construct them by hand. This has no effect on what they look
like when printed.
There are lots of new `allow` markers for `untranslatable_diagnostics`
and `diagnostics_outside_of_impl`. This is because
`#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic`
modifier methods, but missing from the `DiagnosticBuilder` modifier
methods. They're now present.
2024-02-06 05:44:30 +00:00
|
|
|
) {
|
2022-11-13 14:46:31 +00:00
|
|
|
// Access to associates types should use `<T as Bound>::Assoc`, which does not need a
|
2022-11-16 20:34:16 +00:00
|
|
|
// bound. Let's see if this type does that.
|
2022-11-13 14:46:31 +00:00
|
|
|
|
|
|
|
// We use a HIR visitor to walk the type.
|
|
|
|
use rustc_hir::intravisit::{self, Visitor};
|
Reduce capabilities of `Diagnostic`.
Currently many diagnostic modifier methods are available on both
`Diagnostic` and `DiagnosticBuilder`. This commit removes most of them
from `Diagnostic`. To minimize the diff size, it keeps them within
`diagnostic.rs` but changes the surrounding `impl Diagnostic` block to
`impl DiagnosticBuilder`. (I intend to move things around later, to give
a more sensible code layout.)
`Diagnostic` keeps a few methods that it still needs, like `sub`,
`arg`, and `replace_args`.
The `forward!` macro, which defined two additional methods per call
(e.g. `note` and `with_note`), is replaced by the `with_fn!` macro,
which defines one additional method per call (e.g. `with_note`). It's
now also only used when necessary -- not all modifier methods currently
need a `with_*` form. (New ones can be easily added as necessary.)
All this also requires changing `trait AddToDiagnostic` so its methods
take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many
mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`.
There are three subdiagnostics -- `DelayedAtWithoutNewline`,
`DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` --
that are created within the diagnostics machinery and appended to
external diagnostics. These are handled at the `Diagnostic` level, which
means it's now hard to construct them via `derive(Diagnostic)`, so
instead we construct them by hand. This has no effect on what they look
like when printed.
There are lots of new `allow` markers for `untranslatable_diagnostics`
and `diagnostics_outside_of_impl`. This is because
`#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic`
modifier methods, but missing from the `DiagnosticBuilder` modifier
methods. They're now present.
2024-02-06 05:44:30 +00:00
|
|
|
struct WalkAssocTypes<'a, 'b, G: EmissionGuarantee> {
|
2024-02-22 23:20:45 +00:00
|
|
|
err: &'a mut Diag<'b, G>,
|
2022-11-13 14:46:31 +00:00
|
|
|
}
|
Reduce capabilities of `Diagnostic`.
Currently many diagnostic modifier methods are available on both
`Diagnostic` and `DiagnosticBuilder`. This commit removes most of them
from `Diagnostic`. To minimize the diff size, it keeps them within
`diagnostic.rs` but changes the surrounding `impl Diagnostic` block to
`impl DiagnosticBuilder`. (I intend to move things around later, to give
a more sensible code layout.)
`Diagnostic` keeps a few methods that it still needs, like `sub`,
`arg`, and `replace_args`.
The `forward!` macro, which defined two additional methods per call
(e.g. `note` and `with_note`), is replaced by the `with_fn!` macro,
which defines one additional method per call (e.g. `with_note`). It's
now also only used when necessary -- not all modifier methods currently
need a `with_*` form. (New ones can be easily added as necessary.)
All this also requires changing `trait AddToDiagnostic` so its methods
take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many
mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`.
There are three subdiagnostics -- `DelayedAtWithoutNewline`,
`DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` --
that are created within the diagnostics machinery and appended to
external diagnostics. These are handled at the `Diagnostic` level, which
means it's now hard to construct them via `derive(Diagnostic)`, so
instead we construct them by hand. This has no effect on what they look
like when printed.
There are lots of new `allow` markers for `untranslatable_diagnostics`
and `diagnostics_outside_of_impl`. This is because
`#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic`
modifier methods, but missing from the `DiagnosticBuilder` modifier
methods. They're now present.
2024-02-06 05:44:30 +00:00
|
|
|
impl<'a, 'b, G: EmissionGuarantee> Visitor<'_> for WalkAssocTypes<'a, 'b, G> {
|
2022-11-13 14:46:31 +00:00
|
|
|
fn visit_qpath(
|
|
|
|
&mut self,
|
|
|
|
qpath: &rustc_hir::QPath<'_>,
|
|
|
|
id: rustc_hir::HirId,
|
|
|
|
span: Span,
|
|
|
|
) {
|
|
|
|
if TypeAliasBounds::is_type_variable_assoc(qpath) {
|
|
|
|
self.err.span_help(span, fluent::lint_builtin_type_alias_bounds_help);
|
|
|
|
}
|
|
|
|
intravisit::walk_qpath(self, qpath, id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Let's go for a walk!
|
|
|
|
let mut visitor = WalkAssocTypes { err: diag };
|
|
|
|
visitor.visit_ty(self.ty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_builtin_type_alias_where_clause)]
|
|
|
|
pub struct BuiltinTypeAliasWhereClause<'a, 'b> {
|
|
|
|
#[suggestion(code = "", applicability = "machine-applicable")]
|
|
|
|
pub suggestion: Span,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub sub: Option<SuggestChangingAssocTypes<'a, 'b>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_builtin_type_alias_generic_bounds)]
|
|
|
|
pub struct BuiltinTypeAliasGenericBounds<'a, 'b> {
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub suggestion: BuiltinTypeAliasGenericBoundsSuggestion,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub sub: Option<SuggestChangingAssocTypes<'a, 'b>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct BuiltinTypeAliasGenericBoundsSuggestion {
|
|
|
|
pub suggestions: Vec<(Span, String)>,
|
|
|
|
}
|
2022-10-23 01:50:44 +00:00
|
|
|
|
2024-03-06 03:00:16 +00:00
|
|
|
impl Subdiagnostic for BuiltinTypeAliasGenericBoundsSuggestion {
|
|
|
|
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
|
Reduce capabilities of `Diagnostic`.
Currently many diagnostic modifier methods are available on both
`Diagnostic` and `DiagnosticBuilder`. This commit removes most of them
from `Diagnostic`. To minimize the diff size, it keeps them within
`diagnostic.rs` but changes the surrounding `impl Diagnostic` block to
`impl DiagnosticBuilder`. (I intend to move things around later, to give
a more sensible code layout.)
`Diagnostic` keeps a few methods that it still needs, like `sub`,
`arg`, and `replace_args`.
The `forward!` macro, which defined two additional methods per call
(e.g. `note` and `with_note`), is replaced by the `with_fn!` macro,
which defines one additional method per call (e.g. `with_note`). It's
now also only used when necessary -- not all modifier methods currently
need a `with_*` form. (New ones can be easily added as necessary.)
All this also requires changing `trait AddToDiagnostic` so its methods
take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many
mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`.
There are three subdiagnostics -- `DelayedAtWithoutNewline`,
`DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` --
that are created within the diagnostics machinery and appended to
external diagnostics. These are handled at the `Diagnostic` level, which
means it's now hard to construct them via `derive(Diagnostic)`, so
instead we construct them by hand. This has no effect on what they look
like when printed.
There are lots of new `allow` markers for `untranslatable_diagnostics`
and `diagnostics_outside_of_impl`. This is because
`#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic`
modifier methods, but missing from the `DiagnosticBuilder` modifier
methods. They're now present.
2024-02-06 05:44:30 +00:00
|
|
|
self,
|
2024-02-22 23:20:45 +00:00
|
|
|
diag: &mut Diag<'_, G>,
|
2024-04-18 19:18:35 +00:00
|
|
|
_f: &F,
|
Reduce capabilities of `Diagnostic`.
Currently many diagnostic modifier methods are available on both
`Diagnostic` and `DiagnosticBuilder`. This commit removes most of them
from `Diagnostic`. To minimize the diff size, it keeps them within
`diagnostic.rs` but changes the surrounding `impl Diagnostic` block to
`impl DiagnosticBuilder`. (I intend to move things around later, to give
a more sensible code layout.)
`Diagnostic` keeps a few methods that it still needs, like `sub`,
`arg`, and `replace_args`.
The `forward!` macro, which defined two additional methods per call
(e.g. `note` and `with_note`), is replaced by the `with_fn!` macro,
which defines one additional method per call (e.g. `with_note`). It's
now also only used when necessary -- not all modifier methods currently
need a `with_*` form. (New ones can be easily added as necessary.)
All this also requires changing `trait AddToDiagnostic` so its methods
take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many
mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`.
There are three subdiagnostics -- `DelayedAtWithoutNewline`,
`DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` --
that are created within the diagnostics machinery and appended to
external diagnostics. These are handled at the `Diagnostic` level, which
means it's now hard to construct them via `derive(Diagnostic)`, so
instead we construct them by hand. This has no effect on what they look
like when printed.
There are lots of new `allow` markers for `untranslatable_diagnostics`
and `diagnostics_outside_of_impl`. This is because
`#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic`
modifier methods, but missing from the `DiagnosticBuilder` modifier
methods. They're now present.
2024-02-06 05:44:30 +00:00
|
|
|
) {
|
2022-11-13 14:46:31 +00:00
|
|
|
diag.multipart_suggestion(
|
2022-10-13 09:13:02 +00:00
|
|
|
fluent::lint_suggestion,
|
2022-11-13 14:46:31 +00:00
|
|
|
self.suggestions,
|
|
|
|
Applicability::MachineApplicable,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2022-10-23 01:50:44 +00:00
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_builtin_trivial_bounds)]
|
|
|
|
pub struct BuiltinTrivialBounds<'a> {
|
|
|
|
pub predicate_kind_name: &'a str,
|
2023-06-22 18:17:13 +00:00
|
|
|
pub predicate: Clause<'a>,
|
2022-10-23 01:50:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
pub enum BuiltinEllipsisInclusiveRangePatternsLint {
|
|
|
|
#[diag(lint_builtin_ellipsis_inclusive_range_patterns)]
|
|
|
|
Parenthesise {
|
|
|
|
#[suggestion(code = "{replace}", applicability = "machine-applicable")]
|
|
|
|
suggestion: Span,
|
|
|
|
replace: String,
|
|
|
|
},
|
|
|
|
#[diag(lint_builtin_ellipsis_inclusive_range_patterns)]
|
|
|
|
NonParenthesise {
|
|
|
|
#[suggestion(style = "short", code = "..=", applicability = "machine-applicable")]
|
|
|
|
suggestion: Span,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_builtin_keyword_idents)]
|
|
|
|
pub struct BuiltinKeywordIdents {
|
|
|
|
pub kw: Ident,
|
|
|
|
pub next: Edition,
|
|
|
|
#[suggestion(code = "r#{kw}", applicability = "machine-applicable")]
|
|
|
|
pub suggestion: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_builtin_explicit_outlives)]
|
|
|
|
pub struct BuiltinExplicitOutlives {
|
|
|
|
pub count: usize,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub suggestion: BuiltinExplicitOutlivesSuggestion,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
2022-10-13 09:13:02 +00:00
|
|
|
#[multipart_suggestion(lint_suggestion)]
|
2022-10-23 01:50:44 +00:00
|
|
|
pub struct BuiltinExplicitOutlivesSuggestion {
|
|
|
|
#[suggestion_part(code = "")]
|
|
|
|
pub spans: Vec<Span>,
|
|
|
|
#[applicability]
|
|
|
|
pub applicability: Applicability,
|
|
|
|
}
|
|
|
|
|
2022-11-11 00:32:30 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_builtin_incomplete_features)]
|
2022-10-23 01:50:44 +00:00
|
|
|
pub struct BuiltinIncompleteFeatures {
|
|
|
|
pub name: Symbol,
|
2022-11-11 00:32:30 +00:00
|
|
|
#[subdiagnostic]
|
2023-03-09 20:54:53 +00:00
|
|
|
pub note: Option<BuiltinFeatureIssueNote>,
|
2022-11-11 00:32:30 +00:00
|
|
|
#[subdiagnostic]
|
|
|
|
pub help: Option<BuiltinIncompleteFeaturesHelp>,
|
2022-10-23 01:50:44 +00:00
|
|
|
}
|
|
|
|
|
2023-03-09 20:54:53 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_builtin_internal_features)]
|
|
|
|
#[note]
|
|
|
|
pub struct BuiltinInternalFeatures {
|
|
|
|
pub name: Symbol,
|
|
|
|
}
|
|
|
|
|
2022-11-11 00:32:30 +00:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-10-13 09:13:02 +00:00
|
|
|
#[help(lint_help)]
|
2022-11-11 00:32:30 +00:00
|
|
|
pub struct BuiltinIncompleteFeaturesHelp;
|
2022-10-23 01:50:44 +00:00
|
|
|
|
2022-11-11 00:32:30 +00:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-10-13 09:13:02 +00:00
|
|
|
#[note(lint_note)]
|
2023-03-09 20:54:53 +00:00
|
|
|
pub struct BuiltinFeatureIssueNote {
|
2024-01-29 22:59:09 +00:00
|
|
|
pub n: NonZero<u32>,
|
2022-10-23 01:50:44 +00:00
|
|
|
}
|
|
|
|
|
2022-11-13 14:46:31 +00:00
|
|
|
pub struct BuiltinUnpermittedTypeInit<'a> {
|
2024-02-29 00:58:51 +00:00
|
|
|
pub msg: DiagMessage,
|
2022-11-13 14:46:31 +00:00
|
|
|
pub ty: Ty<'a>,
|
|
|
|
pub label: Span,
|
|
|
|
pub sub: BuiltinUnpermittedTypeInitSub,
|
2023-02-13 14:38:23 +00:00
|
|
|
pub tcx: TyCtxt<'a>,
|
2022-11-13 14:46:31 +00:00
|
|
|
}
|
|
|
|
|
2024-03-08 01:03:51 +00:00
|
|
|
impl<'a> LintDiagnostic<'a, ()> for BuiltinUnpermittedTypeInit<'_> {
|
2024-02-22 23:20:45 +00:00
|
|
|
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
|
2024-05-22 14:46:05 +00:00
|
|
|
diag.primary_message(self.msg);
|
2023-12-23 22:08:41 +00:00
|
|
|
diag.arg("ty", self.ty);
|
2022-11-13 14:46:31 +00:00
|
|
|
diag.span_label(self.label, fluent::lint_builtin_unpermitted_type_init_label);
|
2023-02-13 14:38:23 +00:00
|
|
|
if let InhabitedPredicate::True = self.ty.inhabited_predicate(self.tcx) {
|
|
|
|
// Only suggest late `MaybeUninit::assume_init` initialization if the type is inhabited.
|
|
|
|
diag.span_label(
|
|
|
|
self.label,
|
|
|
|
fluent::lint_builtin_unpermitted_type_init_label_suggestion,
|
|
|
|
);
|
|
|
|
}
|
2024-03-06 03:00:16 +00:00
|
|
|
self.sub.add_to_diag(diag);
|
2022-11-13 14:46:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME(davidtwco): make translatable
|
|
|
|
pub struct BuiltinUnpermittedTypeInitSub {
|
|
|
|
pub err: InitError,
|
|
|
|
}
|
|
|
|
|
2024-03-06 03:00:16 +00:00
|
|
|
impl Subdiagnostic for BuiltinUnpermittedTypeInitSub {
|
|
|
|
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
|
Reduce capabilities of `Diagnostic`.
Currently many diagnostic modifier methods are available on both
`Diagnostic` and `DiagnosticBuilder`. This commit removes most of them
from `Diagnostic`. To minimize the diff size, it keeps them within
`diagnostic.rs` but changes the surrounding `impl Diagnostic` block to
`impl DiagnosticBuilder`. (I intend to move things around later, to give
a more sensible code layout.)
`Diagnostic` keeps a few methods that it still needs, like `sub`,
`arg`, and `replace_args`.
The `forward!` macro, which defined two additional methods per call
(e.g. `note` and `with_note`), is replaced by the `with_fn!` macro,
which defines one additional method per call (e.g. `with_note`). It's
now also only used when necessary -- not all modifier methods currently
need a `with_*` form. (New ones can be easily added as necessary.)
All this also requires changing `trait AddToDiagnostic` so its methods
take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many
mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`.
There are three subdiagnostics -- `DelayedAtWithoutNewline`,
`DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` --
that are created within the diagnostics machinery and appended to
external diagnostics. These are handled at the `Diagnostic` level, which
means it's now hard to construct them via `derive(Diagnostic)`, so
instead we construct them by hand. This has no effect on what they look
like when printed.
There are lots of new `allow` markers for `untranslatable_diagnostics`
and `diagnostics_outside_of_impl`. This is because
`#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic`
modifier methods, but missing from the `DiagnosticBuilder` modifier
methods. They're now present.
2024-02-06 05:44:30 +00:00
|
|
|
self,
|
2024-02-22 23:20:45 +00:00
|
|
|
diag: &mut Diag<'_, G>,
|
2024-04-18 19:18:35 +00:00
|
|
|
_f: &F,
|
Reduce capabilities of `Diagnostic`.
Currently many diagnostic modifier methods are available on both
`Diagnostic` and `DiagnosticBuilder`. This commit removes most of them
from `Diagnostic`. To minimize the diff size, it keeps them within
`diagnostic.rs` but changes the surrounding `impl Diagnostic` block to
`impl DiagnosticBuilder`. (I intend to move things around later, to give
a more sensible code layout.)
`Diagnostic` keeps a few methods that it still needs, like `sub`,
`arg`, and `replace_args`.
The `forward!` macro, which defined two additional methods per call
(e.g. `note` and `with_note`), is replaced by the `with_fn!` macro,
which defines one additional method per call (e.g. `with_note`). It's
now also only used when necessary -- not all modifier methods currently
need a `with_*` form. (New ones can be easily added as necessary.)
All this also requires changing `trait AddToDiagnostic` so its methods
take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many
mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`.
There are three subdiagnostics -- `DelayedAtWithoutNewline`,
`DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` --
that are created within the diagnostics machinery and appended to
external diagnostics. These are handled at the `Diagnostic` level, which
means it's now hard to construct them via `derive(Diagnostic)`, so
instead we construct them by hand. This has no effect on what they look
like when printed.
There are lots of new `allow` markers for `untranslatable_diagnostics`
and `diagnostics_outside_of_impl`. This is because
`#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic`
modifier methods, but missing from the `DiagnosticBuilder` modifier
methods. They're now present.
2024-02-06 05:44:30 +00:00
|
|
|
) {
|
2022-11-13 14:46:31 +00:00
|
|
|
let mut err = self.err;
|
|
|
|
loop {
|
|
|
|
if let Some(span) = err.span {
|
|
|
|
diag.span_note(span, err.message);
|
|
|
|
} else {
|
|
|
|
diag.note(err.message);
|
|
|
|
}
|
|
|
|
if let Some(e) = err.nested {
|
|
|
|
err = *e;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
pub enum BuiltinClashingExtern<'a> {
|
|
|
|
#[diag(lint_builtin_clashing_extern_same_name)]
|
|
|
|
SameName {
|
|
|
|
this: Symbol,
|
|
|
|
orig: Symbol,
|
2022-10-13 09:13:02 +00:00
|
|
|
#[label(lint_previous_decl_label)]
|
2022-11-13 14:46:31 +00:00
|
|
|
previous_decl_label: Span,
|
2022-10-13 09:13:02 +00:00
|
|
|
#[label(lint_mismatch_label)]
|
2022-11-13 14:46:31 +00:00
|
|
|
mismatch_label: Span,
|
|
|
|
#[subdiagnostic]
|
|
|
|
sub: BuiltinClashingExternSub<'a>,
|
|
|
|
},
|
|
|
|
#[diag(lint_builtin_clashing_extern_diff_name)]
|
|
|
|
DiffName {
|
|
|
|
this: Symbol,
|
|
|
|
orig: Symbol,
|
2022-10-13 09:13:02 +00:00
|
|
|
#[label(lint_previous_decl_label)]
|
2022-11-13 14:46:31 +00:00
|
|
|
previous_decl_label: Span,
|
2022-10-13 09:13:02 +00:00
|
|
|
#[label(lint_mismatch_label)]
|
2022-11-13 14:46:31 +00:00
|
|
|
mismatch_label: Span,
|
|
|
|
#[subdiagnostic]
|
|
|
|
sub: BuiltinClashingExternSub<'a>,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME(davidtwco): translatable expected/found
|
|
|
|
pub struct BuiltinClashingExternSub<'a> {
|
|
|
|
pub tcx: TyCtxt<'a>,
|
|
|
|
pub expected: Ty<'a>,
|
|
|
|
pub found: Ty<'a>,
|
|
|
|
}
|
|
|
|
|
2024-03-06 03:00:16 +00:00
|
|
|
impl Subdiagnostic for BuiltinClashingExternSub<'_> {
|
|
|
|
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
|
Reduce capabilities of `Diagnostic`.
Currently many diagnostic modifier methods are available on both
`Diagnostic` and `DiagnosticBuilder`. This commit removes most of them
from `Diagnostic`. To minimize the diff size, it keeps them within
`diagnostic.rs` but changes the surrounding `impl Diagnostic` block to
`impl DiagnosticBuilder`. (I intend to move things around later, to give
a more sensible code layout.)
`Diagnostic` keeps a few methods that it still needs, like `sub`,
`arg`, and `replace_args`.
The `forward!` macro, which defined two additional methods per call
(e.g. `note` and `with_note`), is replaced by the `with_fn!` macro,
which defines one additional method per call (e.g. `with_note`). It's
now also only used when necessary -- not all modifier methods currently
need a `with_*` form. (New ones can be easily added as necessary.)
All this also requires changing `trait AddToDiagnostic` so its methods
take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many
mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`.
There are three subdiagnostics -- `DelayedAtWithoutNewline`,
`DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` --
that are created within the diagnostics machinery and appended to
external diagnostics. These are handled at the `Diagnostic` level, which
means it's now hard to construct them via `derive(Diagnostic)`, so
instead we construct them by hand. This has no effect on what they look
like when printed.
There are lots of new `allow` markers for `untranslatable_diagnostics`
and `diagnostics_outside_of_impl`. This is because
`#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic`
modifier methods, but missing from the `DiagnosticBuilder` modifier
methods. They're now present.
2024-02-06 05:44:30 +00:00
|
|
|
self,
|
2024-02-22 23:20:45 +00:00
|
|
|
diag: &mut Diag<'_, G>,
|
2024-04-18 19:18:35 +00:00
|
|
|
_f: &F,
|
Reduce capabilities of `Diagnostic`.
Currently many diagnostic modifier methods are available on both
`Diagnostic` and `DiagnosticBuilder`. This commit removes most of them
from `Diagnostic`. To minimize the diff size, it keeps them within
`diagnostic.rs` but changes the surrounding `impl Diagnostic` block to
`impl DiagnosticBuilder`. (I intend to move things around later, to give
a more sensible code layout.)
`Diagnostic` keeps a few methods that it still needs, like `sub`,
`arg`, and `replace_args`.
The `forward!` macro, which defined two additional methods per call
(e.g. `note` and `with_note`), is replaced by the `with_fn!` macro,
which defines one additional method per call (e.g. `with_note`). It's
now also only used when necessary -- not all modifier methods currently
need a `with_*` form. (New ones can be easily added as necessary.)
All this also requires changing `trait AddToDiagnostic` so its methods
take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many
mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`.
There are three subdiagnostics -- `DelayedAtWithoutNewline`,
`DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` --
that are created within the diagnostics machinery and appended to
external diagnostics. These are handled at the `Diagnostic` level, which
means it's now hard to construct them via `derive(Diagnostic)`, so
instead we construct them by hand. This has no effect on what they look
like when printed.
There are lots of new `allow` markers for `untranslatable_diagnostics`
and `diagnostics_outside_of_impl`. This is because
`#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic`
modifier methods, but missing from the `DiagnosticBuilder` modifier
methods. They're now present.
2024-02-06 05:44:30 +00:00
|
|
|
) {
|
2024-02-23 05:01:50 +00:00
|
|
|
let mut expected_str = DiagStyledString::new();
|
2022-11-13 14:46:31 +00:00
|
|
|
expected_str.push(self.expected.fn_sig(self.tcx).to_string(), false);
|
2024-02-23 05:01:50 +00:00
|
|
|
let mut found_str = DiagStyledString::new();
|
2022-11-13 14:46:31 +00:00
|
|
|
found_str.push(self.found.fn_sig(self.tcx).to_string(), true);
|
|
|
|
diag.note_expected_found(&"", expected_str, &"", found_str);
|
|
|
|
}
|
|
|
|
}
|
2022-10-23 01:50:44 +00:00
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_builtin_deref_nullptr)]
|
|
|
|
pub struct BuiltinDerefNullptr {
|
|
|
|
#[label]
|
|
|
|
pub label: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: migrate fluent::lint::builtin_asm_labels
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
pub enum BuiltinSpecialModuleNameUsed {
|
|
|
|
#[diag(lint_builtin_special_module_name_used_lib)]
|
|
|
|
#[note]
|
|
|
|
#[help]
|
|
|
|
Lib,
|
|
|
|
#[diag(lint_builtin_special_module_name_used_main)]
|
|
|
|
#[note]
|
|
|
|
Main,
|
|
|
|
}
|
|
|
|
|
2022-11-25 01:03:06 +00:00
|
|
|
// deref_into_dyn_supertrait.rs
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_supertrait_as_deref_target)]
|
|
|
|
pub struct SupertraitAsDerefTarget<'a> {
|
2023-11-18 19:29:39 +00:00
|
|
|
pub self_ty: Ty<'a>,
|
|
|
|
pub supertrait_principal: PolyExistentialTraitRef<'a>,
|
|
|
|
pub target_principal: PolyExistentialTraitRef<'a>,
|
|
|
|
#[label]
|
|
|
|
pub label: Span,
|
2022-11-25 01:03:06 +00:00
|
|
|
#[subdiagnostic]
|
2023-11-18 19:29:39 +00:00
|
|
|
pub label2: Option<SupertraitAsDerefTargetLabel>,
|
2022-11-25 01:03:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
2023-11-18 19:29:39 +00:00
|
|
|
#[label(lint_label2)]
|
2022-11-25 01:03:06 +00:00
|
|
|
pub struct SupertraitAsDerefTargetLabel {
|
|
|
|
#[primary_span]
|
|
|
|
pub label: Span,
|
|
|
|
}
|
|
|
|
|
2022-10-04 23:39:02 +00:00
|
|
|
// enum_intrinsics_non_enums.rs
|
2022-09-18 14:31:35 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_enum_intrinsics_mem_discriminant)]
|
|
|
|
pub struct EnumIntrinsicsMemDiscriminate<'a> {
|
|
|
|
pub ty_param: Ty<'a>,
|
|
|
|
#[note]
|
|
|
|
pub note: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_enum_intrinsics_mem_variant)]
|
|
|
|
#[note]
|
|
|
|
pub struct EnumIntrinsicsMemVariant<'a> {
|
|
|
|
pub ty_param: Ty<'a>,
|
|
|
|
}
|
|
|
|
|
2022-11-09 23:22:48 +00:00
|
|
|
// expect.rs
|
2022-11-11 00:32:30 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_expectation)]
|
|
|
|
pub struct Expectation {
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub rationale: Option<ExpectationNote>,
|
|
|
|
#[note]
|
|
|
|
pub note: Option<()>,
|
2022-11-09 23:22:48 +00:00
|
|
|
}
|
|
|
|
|
2022-11-11 00:32:30 +00:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-10-13 09:13:02 +00:00
|
|
|
#[note(lint_rationale)]
|
2022-11-11 00:32:30 +00:00
|
|
|
pub struct ExpectationNote {
|
|
|
|
pub rationale: Symbol,
|
2022-11-09 23:22:48 +00:00
|
|
|
}
|
|
|
|
|
2023-07-13 10:01:13 +00:00
|
|
|
// ptr_nulls.rs
|
2023-05-17 09:22:26 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
2023-07-13 10:01:13 +00:00
|
|
|
pub enum PtrNullChecksDiag<'a> {
|
|
|
|
#[diag(lint_ptr_null_checks_fn_ptr)]
|
2023-07-12 14:17:58 +00:00
|
|
|
#[help(lint_help)]
|
2023-08-03 08:57:11 +00:00
|
|
|
FnPtr {
|
|
|
|
orig_ty: Ty<'a>,
|
|
|
|
#[label]
|
|
|
|
label: Span,
|
|
|
|
},
|
2023-07-13 10:01:13 +00:00
|
|
|
#[diag(lint_ptr_null_checks_ref)]
|
2023-07-12 14:17:58 +00:00
|
|
|
Ref {
|
|
|
|
orig_ty: Ty<'a>,
|
|
|
|
#[label]
|
|
|
|
label: Span,
|
|
|
|
},
|
2023-08-05 23:25:24 +00:00
|
|
|
#[diag(lint_ptr_null_checks_fn_ret)]
|
|
|
|
FnRet { fn_name: Ident },
|
2023-07-12 14:17:58 +00:00
|
|
|
}
|
2023-05-17 09:22:26 +00:00
|
|
|
|
2022-11-10 00:34:49 +00:00
|
|
|
// for_loops_over_fallibles.rs
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_for_loops_over_fallibles)]
|
|
|
|
pub struct ForLoopsOverFalliblesDiag<'a> {
|
|
|
|
pub article: &'static str,
|
2024-05-15 15:59:13 +00:00
|
|
|
pub ref_prefix: &'static str,
|
2022-11-10 00:34:49 +00:00
|
|
|
pub ty: &'static str,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub sub: ForLoopsOverFalliblesLoopSub<'a>,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub question_mark: Option<ForLoopsOverFalliblesQuestionMark>,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub suggestion: ForLoopsOverFalliblesSuggestion<'a>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
pub enum ForLoopsOverFalliblesLoopSub<'a> {
|
2022-10-13 09:13:02 +00:00
|
|
|
#[suggestion(lint_remove_next, code = ".by_ref()", applicability = "maybe-incorrect")]
|
2022-11-10 00:34:49 +00:00
|
|
|
RemoveNext {
|
|
|
|
#[primary_span]
|
|
|
|
suggestion: Span,
|
|
|
|
recv_snip: String,
|
|
|
|
},
|
2022-10-13 09:13:02 +00:00
|
|
|
#[multipart_suggestion(lint_use_while_let, applicability = "maybe-incorrect")]
|
2022-11-10 00:34:49 +00:00
|
|
|
UseWhileLet {
|
|
|
|
#[suggestion_part(code = "while let {var}(")]
|
|
|
|
start_span: Span,
|
|
|
|
#[suggestion_part(code = ") = ")]
|
|
|
|
end_span: Span,
|
|
|
|
var: &'a str,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
2022-10-13 09:13:02 +00:00
|
|
|
#[suggestion(lint_use_question_mark, code = "?", applicability = "maybe-incorrect")]
|
2022-11-10 00:34:49 +00:00
|
|
|
pub struct ForLoopsOverFalliblesQuestionMark {
|
|
|
|
#[primary_span]
|
|
|
|
pub suggestion: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
2022-10-13 09:13:02 +00:00
|
|
|
#[multipart_suggestion(lint_suggestion, applicability = "maybe-incorrect")]
|
2022-11-10 00:34:49 +00:00
|
|
|
pub struct ForLoopsOverFalliblesSuggestion<'a> {
|
|
|
|
pub var: &'a str,
|
|
|
|
#[suggestion_part(code = "if let {var}(")]
|
|
|
|
pub start_span: Span,
|
|
|
|
#[suggestion_part(code = ") = ")]
|
|
|
|
pub end_span: Span,
|
|
|
|
}
|
2023-03-26 10:25:08 +00:00
|
|
|
|
2024-05-25 01:55:49 +00:00
|
|
|
#[derive(Subdiagnostic)]
|
2024-05-25 03:44:14 +00:00
|
|
|
pub enum UseLetUnderscoreIgnoreSuggestion {
|
|
|
|
#[note(lint_use_let_underscore_ignore_suggestion)]
|
2024-05-25 01:55:49 +00:00
|
|
|
Note,
|
2024-05-25 03:44:14 +00:00
|
|
|
#[multipart_suggestion(
|
|
|
|
lint_use_let_underscore_ignore_suggestion,
|
|
|
|
style = "verbose",
|
|
|
|
applicability = "maybe-incorrect"
|
|
|
|
)]
|
2024-05-25 01:55:49 +00:00
|
|
|
Suggestion {
|
|
|
|
#[suggestion_part(code = "let _ = ")]
|
|
|
|
start_span: Span,
|
|
|
|
#[suggestion_part(code = "")]
|
|
|
|
end_span: Span,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-05-19 09:25:35 +00:00
|
|
|
// drop_forget_useless.rs
|
2023-03-26 10:25:08 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
2023-05-19 09:25:35 +00:00
|
|
|
#[diag(lint_dropping_references)]
|
2023-03-26 10:25:08 +00:00
|
|
|
pub struct DropRefDiag<'a> {
|
|
|
|
pub arg_ty: Ty<'a>,
|
2023-04-10 09:55:37 +00:00
|
|
|
#[label]
|
|
|
|
pub label: Span,
|
2024-05-25 01:55:49 +00:00
|
|
|
#[subdiagnostic]
|
2024-05-25 03:44:14 +00:00
|
|
|
pub sugg: UseLetUnderscoreIgnoreSuggestion,
|
2023-03-26 10:25:08 +00:00
|
|
|
}
|
2023-03-27 18:59:59 +00:00
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
2023-05-19 09:14:55 +00:00
|
|
|
#[diag(lint_dropping_copy_types)]
|
2023-03-27 18:59:59 +00:00
|
|
|
pub struct DropCopyDiag<'a> {
|
|
|
|
pub arg_ty: Ty<'a>,
|
2023-04-10 09:55:37 +00:00
|
|
|
#[label]
|
|
|
|
pub label: Span,
|
2024-05-22 10:25:26 +00:00
|
|
|
#[subdiagnostic]
|
2024-05-29 10:09:20 +00:00
|
|
|
pub sugg: UseLetUnderscoreIgnoreSuggestion,
|
2023-03-27 18:59:59 +00:00
|
|
|
}
|
2023-03-28 16:31:21 +00:00
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
2023-05-19 09:30:11 +00:00
|
|
|
#[diag(lint_forgetting_references)]
|
2023-03-28 16:31:21 +00:00
|
|
|
pub struct ForgetRefDiag<'a> {
|
|
|
|
pub arg_ty: Ty<'a>,
|
2023-04-10 09:55:37 +00:00
|
|
|
#[label]
|
|
|
|
pub label: Span,
|
2024-05-25 03:44:14 +00:00
|
|
|
#[subdiagnostic]
|
|
|
|
pub sugg: UseLetUnderscoreIgnoreSuggestion,
|
2023-03-28 16:31:21 +00:00
|
|
|
}
|
2023-03-28 16:47:37 +00:00
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
2023-05-19 09:19:31 +00:00
|
|
|
#[diag(lint_forgetting_copy_types)]
|
2023-03-28 16:47:37 +00:00
|
|
|
pub struct ForgetCopyDiag<'a> {
|
|
|
|
pub arg_ty: Ty<'a>,
|
2023-04-10 09:55:37 +00:00
|
|
|
#[label]
|
|
|
|
pub label: Span,
|
2024-05-25 03:04:13 +00:00
|
|
|
#[subdiagnostic]
|
2024-05-25 03:44:14 +00:00
|
|
|
pub sugg: UseLetUnderscoreIgnoreSuggestion,
|
2023-03-28 16:47:37 +00:00
|
|
|
}
|
2022-11-10 00:34:49 +00:00
|
|
|
|
2023-05-12 17:30:15 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_undropped_manually_drops)]
|
|
|
|
pub struct UndroppedManuallyDropsDiag<'a> {
|
|
|
|
pub arg_ty: Ty<'a>,
|
|
|
|
#[label]
|
|
|
|
pub label: Span,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub suggestion: UndroppedManuallyDropsSuggestion,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
#[multipart_suggestion(lint_suggestion, applicability = "machine-applicable")]
|
|
|
|
pub struct UndroppedManuallyDropsSuggestion {
|
|
|
|
#[suggestion_part(code = "std::mem::ManuallyDrop::into_inner(")]
|
|
|
|
pub start_span: Span,
|
|
|
|
#[suggestion_part(code = ")")]
|
|
|
|
pub end_span: Span,
|
|
|
|
}
|
|
|
|
|
2023-05-13 15:12:45 +00:00
|
|
|
// invalid_from_utf8.rs
|
|
|
|
#[derive(LintDiagnostic)]
|
2023-05-13 16:33:19 +00:00
|
|
|
pub enum InvalidFromUtf8Diag {
|
|
|
|
#[diag(lint_invalid_from_utf8_unchecked)]
|
|
|
|
Unchecked {
|
|
|
|
method: String,
|
|
|
|
valid_up_to: usize,
|
|
|
|
#[label]
|
|
|
|
label: Span,
|
|
|
|
},
|
|
|
|
#[diag(lint_invalid_from_utf8_checked)]
|
|
|
|
Checked {
|
|
|
|
method: String,
|
|
|
|
valid_up_to: usize,
|
|
|
|
#[label]
|
|
|
|
label: Span,
|
|
|
|
},
|
2023-05-13 15:12:45 +00:00
|
|
|
}
|
2022-11-10 00:34:49 +00:00
|
|
|
|
2023-07-06 19:45:24 +00:00
|
|
|
// reference_casting.rs
|
2023-05-14 14:20:32 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
2023-12-13 13:40:19 +00:00
|
|
|
pub enum InvalidReferenceCastingDiag<'tcx> {
|
2023-07-14 20:25:47 +00:00
|
|
|
#[diag(lint_invalid_reference_casting_borrow_as_mut)]
|
2023-08-22 15:17:44 +00:00
|
|
|
#[note(lint_invalid_reference_casting_note_book)]
|
2023-07-14 20:25:47 +00:00
|
|
|
BorrowAsMut {
|
|
|
|
#[label]
|
|
|
|
orig_cast: Option<Span>,
|
2023-10-04 14:03:39 +00:00
|
|
|
#[note(lint_invalid_reference_casting_note_ty_has_interior_mutability)]
|
|
|
|
ty_has_interior_mutability: Option<()>,
|
2023-07-14 20:25:47 +00:00
|
|
|
},
|
|
|
|
#[diag(lint_invalid_reference_casting_assign_to_ref)]
|
2023-08-22 15:17:44 +00:00
|
|
|
#[note(lint_invalid_reference_casting_note_book)]
|
2023-07-14 20:25:47 +00:00
|
|
|
AssignToRef {
|
|
|
|
#[label]
|
|
|
|
orig_cast: Option<Span>,
|
2023-10-04 14:03:39 +00:00
|
|
|
#[note(lint_invalid_reference_casting_note_ty_has_interior_mutability)]
|
|
|
|
ty_has_interior_mutability: Option<()>,
|
2023-07-14 20:25:47 +00:00
|
|
|
},
|
2023-12-13 13:40:19 +00:00
|
|
|
#[diag(lint_invalid_reference_casting_bigger_layout)]
|
|
|
|
#[note(lint_layout)]
|
|
|
|
BiggerLayout {
|
|
|
|
#[label]
|
|
|
|
orig_cast: Option<Span>,
|
|
|
|
#[label(lint_alloc)]
|
|
|
|
alloc: Span,
|
|
|
|
from_ty: Ty<'tcx>,
|
|
|
|
from_size: u64,
|
|
|
|
to_ty: Ty<'tcx>,
|
|
|
|
to_size: u64,
|
|
|
|
},
|
2023-07-14 20:10:14 +00:00
|
|
|
}
|
2023-05-14 14:20:32 +00:00
|
|
|
|
2022-11-12 03:39:37 +00:00
|
|
|
// hidden_unicode_codepoints.rs
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_hidden_unicode_codepoints)]
|
|
|
|
#[note]
|
|
|
|
pub struct HiddenUnicodeCodepointsDiag<'a> {
|
|
|
|
pub label: &'a str,
|
|
|
|
pub count: usize,
|
|
|
|
#[label]
|
|
|
|
pub span_label: Span,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub labels: Option<HiddenUnicodeCodepointsDiagLabels>,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub sub: HiddenUnicodeCodepointsDiagSub,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct HiddenUnicodeCodepointsDiagLabels {
|
|
|
|
pub spans: Vec<(char, Span)>,
|
|
|
|
}
|
|
|
|
|
2024-03-06 03:00:16 +00:00
|
|
|
impl Subdiagnostic for HiddenUnicodeCodepointsDiagLabels {
|
|
|
|
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
|
Reduce capabilities of `Diagnostic`.
Currently many diagnostic modifier methods are available on both
`Diagnostic` and `DiagnosticBuilder`. This commit removes most of them
from `Diagnostic`. To minimize the diff size, it keeps them within
`diagnostic.rs` but changes the surrounding `impl Diagnostic` block to
`impl DiagnosticBuilder`. (I intend to move things around later, to give
a more sensible code layout.)
`Diagnostic` keeps a few methods that it still needs, like `sub`,
`arg`, and `replace_args`.
The `forward!` macro, which defined two additional methods per call
(e.g. `note` and `with_note`), is replaced by the `with_fn!` macro,
which defines one additional method per call (e.g. `with_note`). It's
now also only used when necessary -- not all modifier methods currently
need a `with_*` form. (New ones can be easily added as necessary.)
All this also requires changing `trait AddToDiagnostic` so its methods
take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many
mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`.
There are three subdiagnostics -- `DelayedAtWithoutNewline`,
`DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` --
that are created within the diagnostics machinery and appended to
external diagnostics. These are handled at the `Diagnostic` level, which
means it's now hard to construct them via `derive(Diagnostic)`, so
instead we construct them by hand. This has no effect on what they look
like when printed.
There are lots of new `allow` markers for `untranslatable_diagnostics`
and `diagnostics_outside_of_impl`. This is because
`#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic`
modifier methods, but missing from the `DiagnosticBuilder` modifier
methods. They're now present.
2024-02-06 05:44:30 +00:00
|
|
|
self,
|
2024-02-22 23:20:45 +00:00
|
|
|
diag: &mut Diag<'_, G>,
|
2024-04-18 19:18:35 +00:00
|
|
|
_f: &F,
|
Reduce capabilities of `Diagnostic`.
Currently many diagnostic modifier methods are available on both
`Diagnostic` and `DiagnosticBuilder`. This commit removes most of them
from `Diagnostic`. To minimize the diff size, it keeps them within
`diagnostic.rs` but changes the surrounding `impl Diagnostic` block to
`impl DiagnosticBuilder`. (I intend to move things around later, to give
a more sensible code layout.)
`Diagnostic` keeps a few methods that it still needs, like `sub`,
`arg`, and `replace_args`.
The `forward!` macro, which defined two additional methods per call
(e.g. `note` and `with_note`), is replaced by the `with_fn!` macro,
which defines one additional method per call (e.g. `with_note`). It's
now also only used when necessary -- not all modifier methods currently
need a `with_*` form. (New ones can be easily added as necessary.)
All this also requires changing `trait AddToDiagnostic` so its methods
take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many
mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`.
There are three subdiagnostics -- `DelayedAtWithoutNewline`,
`DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` --
that are created within the diagnostics machinery and appended to
external diagnostics. These are handled at the `Diagnostic` level, which
means it's now hard to construct them via `derive(Diagnostic)`, so
instead we construct them by hand. This has no effect on what they look
like when printed.
There are lots of new `allow` markers for `untranslatable_diagnostics`
and `diagnostics_outside_of_impl`. This is because
`#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic`
modifier methods, but missing from the `DiagnosticBuilder` modifier
methods. They're now present.
2024-02-06 05:44:30 +00:00
|
|
|
) {
|
2022-11-12 03:39:37 +00:00
|
|
|
for (c, span) in self.spans {
|
2023-07-25 21:17:39 +00:00
|
|
|
diag.span_label(span, format!("{c:?}"));
|
2022-11-12 03:39:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum HiddenUnicodeCodepointsDiagSub {
|
|
|
|
Escape { spans: Vec<(char, Span)> },
|
|
|
|
NoEscape { spans: Vec<(char, Span)> },
|
|
|
|
}
|
|
|
|
|
|
|
|
// Used because of multiple multipart_suggestion and note
|
2024-03-06 03:00:16 +00:00
|
|
|
impl Subdiagnostic for HiddenUnicodeCodepointsDiagSub {
|
|
|
|
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
|
Reduce capabilities of `Diagnostic`.
Currently many diagnostic modifier methods are available on both
`Diagnostic` and `DiagnosticBuilder`. This commit removes most of them
from `Diagnostic`. To minimize the diff size, it keeps them within
`diagnostic.rs` but changes the surrounding `impl Diagnostic` block to
`impl DiagnosticBuilder`. (I intend to move things around later, to give
a more sensible code layout.)
`Diagnostic` keeps a few methods that it still needs, like `sub`,
`arg`, and `replace_args`.
The `forward!` macro, which defined two additional methods per call
(e.g. `note` and `with_note`), is replaced by the `with_fn!` macro,
which defines one additional method per call (e.g. `with_note`). It's
now also only used when necessary -- not all modifier methods currently
need a `with_*` form. (New ones can be easily added as necessary.)
All this also requires changing `trait AddToDiagnostic` so its methods
take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many
mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`.
There are three subdiagnostics -- `DelayedAtWithoutNewline`,
`DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` --
that are created within the diagnostics machinery and appended to
external diagnostics. These are handled at the `Diagnostic` level, which
means it's now hard to construct them via `derive(Diagnostic)`, so
instead we construct them by hand. This has no effect on what they look
like when printed.
There are lots of new `allow` markers for `untranslatable_diagnostics`
and `diagnostics_outside_of_impl`. This is because
`#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic`
modifier methods, but missing from the `DiagnosticBuilder` modifier
methods. They're now present.
2024-02-06 05:44:30 +00:00
|
|
|
self,
|
2024-02-22 23:20:45 +00:00
|
|
|
diag: &mut Diag<'_, G>,
|
2024-04-18 19:18:35 +00:00
|
|
|
_f: &F,
|
Reduce capabilities of `Diagnostic`.
Currently many diagnostic modifier methods are available on both
`Diagnostic` and `DiagnosticBuilder`. This commit removes most of them
from `Diagnostic`. To minimize the diff size, it keeps them within
`diagnostic.rs` but changes the surrounding `impl Diagnostic` block to
`impl DiagnosticBuilder`. (I intend to move things around later, to give
a more sensible code layout.)
`Diagnostic` keeps a few methods that it still needs, like `sub`,
`arg`, and `replace_args`.
The `forward!` macro, which defined two additional methods per call
(e.g. `note` and `with_note`), is replaced by the `with_fn!` macro,
which defines one additional method per call (e.g. `with_note`). It's
now also only used when necessary -- not all modifier methods currently
need a `with_*` form. (New ones can be easily added as necessary.)
All this also requires changing `trait AddToDiagnostic` so its methods
take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many
mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`.
There are three subdiagnostics -- `DelayedAtWithoutNewline`,
`DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` --
that are created within the diagnostics machinery and appended to
external diagnostics. These are handled at the `Diagnostic` level, which
means it's now hard to construct them via `derive(Diagnostic)`, so
instead we construct them by hand. This has no effect on what they look
like when printed.
There are lots of new `allow` markers for `untranslatable_diagnostics`
and `diagnostics_outside_of_impl`. This is because
`#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic`
modifier methods, but missing from the `DiagnosticBuilder` modifier
methods. They're now present.
2024-02-06 05:44:30 +00:00
|
|
|
) {
|
2022-11-12 03:39:37 +00:00
|
|
|
match self {
|
|
|
|
HiddenUnicodeCodepointsDiagSub::Escape { spans } => {
|
|
|
|
diag.multipart_suggestion_with_style(
|
2022-10-13 09:13:02 +00:00
|
|
|
fluent::lint_suggestion_remove,
|
2022-11-12 03:39:37 +00:00
|
|
|
spans.iter().map(|(_, span)| (*span, "".to_string())).collect(),
|
|
|
|
Applicability::MachineApplicable,
|
|
|
|
SuggestionStyle::HideCodeAlways,
|
|
|
|
);
|
|
|
|
diag.multipart_suggestion(
|
2022-10-13 09:13:02 +00:00
|
|
|
fluent::lint_suggestion_escape,
|
2022-11-12 03:39:37 +00:00
|
|
|
spans
|
|
|
|
.into_iter()
|
|
|
|
.map(|(c, span)| {
|
2023-07-25 21:17:39 +00:00
|
|
|
let c = format!("{c:?}");
|
2022-11-12 03:39:37 +00:00
|
|
|
(span, c[1..c.len() - 1].to_string())
|
|
|
|
})
|
|
|
|
.collect(),
|
|
|
|
Applicability::MachineApplicable,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
HiddenUnicodeCodepointsDiagSub::NoEscape { spans } => {
|
|
|
|
// FIXME: in other suggestions we've reversed the inner spans of doc comments. We
|
|
|
|
// should do the same here to provide the same good suggestions as we do for
|
|
|
|
// literals above.
|
2023-12-23 22:08:41 +00:00
|
|
|
diag.arg(
|
2022-11-12 03:39:37 +00:00
|
|
|
"escaped",
|
|
|
|
spans
|
|
|
|
.into_iter()
|
2023-07-25 21:17:39 +00:00
|
|
|
.map(|(c, _)| format!("{c:?}"))
|
2022-11-12 03:39:37 +00:00
|
|
|
.collect::<Vec<String>>()
|
|
|
|
.join(", "),
|
|
|
|
);
|
2022-10-13 09:13:02 +00:00
|
|
|
diag.note(fluent::lint_suggestion_remove);
|
|
|
|
diag.note(fluent::lint_no_suggestion_note_escape);
|
2022-11-12 03:39:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-16 19:04:59 +00:00
|
|
|
// map_unit_fn.rs
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_map_unit_fn)]
|
|
|
|
#[note]
|
|
|
|
pub struct MappingToUnit {
|
|
|
|
#[label(lint_function_label)]
|
|
|
|
pub function_label: Span,
|
|
|
|
#[label(lint_argument_label)]
|
|
|
|
pub argument_label: Span,
|
|
|
|
#[label(lint_map_label)]
|
|
|
|
pub map_label: Span,
|
|
|
|
#[suggestion(style = "verbose", code = "{replace}", applicability = "maybe-incorrect")]
|
|
|
|
pub suggestion: Span,
|
|
|
|
pub replace: String,
|
|
|
|
}
|
|
|
|
|
2022-10-22 20:32:54 +00:00
|
|
|
// internal.rs
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_default_hash_types)]
|
|
|
|
#[note]
|
|
|
|
pub struct DefaultHashTypesDiag<'a> {
|
|
|
|
pub preferred: &'a str,
|
|
|
|
pub used: Symbol,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_query_instability)]
|
|
|
|
#[note]
|
|
|
|
pub struct QueryInstability {
|
|
|
|
pub query: Symbol,
|
|
|
|
}
|
|
|
|
|
2023-09-25 07:15:00 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_span_use_eq_ctxt)]
|
2023-10-16 08:05:11 +00:00
|
|
|
pub struct SpanUseEqCtxtDiag;
|
2023-09-25 07:15:00 +00:00
|
|
|
|
2022-10-22 20:32:54 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_tykind_kind)]
|
|
|
|
pub struct TykindKind {
|
|
|
|
#[suggestion(code = "ty", applicability = "maybe-incorrect")]
|
|
|
|
pub suggestion: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_tykind)]
|
|
|
|
#[help]
|
|
|
|
pub struct TykindDiag;
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_ty_qualified)]
|
|
|
|
pub struct TyQualified {
|
|
|
|
pub ty: String,
|
|
|
|
#[suggestion(code = "{ty}", applicability = "maybe-incorrect")]
|
|
|
|
pub suggestion: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_lintpass_by_hand)]
|
|
|
|
#[help]
|
|
|
|
pub struct LintPassByHand;
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
2023-04-10 20:02:52 +00:00
|
|
|
#[diag(lint_non_existent_doc_keyword)]
|
2022-10-22 20:32:54 +00:00
|
|
|
#[help]
|
2023-04-10 20:02:52 +00:00
|
|
|
pub struct NonExistentDocKeyword {
|
2022-10-22 20:32:54 +00:00
|
|
|
pub keyword: Symbol,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_diag_out_of_impl)]
|
|
|
|
pub struct DiagOutOfImpl;
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_untranslatable_diag)]
|
|
|
|
pub struct UntranslatableDiag;
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_bad_opt_access)]
|
|
|
|
pub struct BadOptAccessDiag<'a> {
|
|
|
|
pub msg: &'a str,
|
|
|
|
}
|
|
|
|
|
2022-10-07 10:14:56 +00:00
|
|
|
// let_underscore.rs
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
pub enum NonBindingLet {
|
2022-10-07 10:38:20 +00:00
|
|
|
#[diag(lint_non_binding_let_on_sync_lock)]
|
2022-10-07 10:14:56 +00:00
|
|
|
SyncLock {
|
|
|
|
#[subdiagnostic]
|
|
|
|
sub: NonBindingLetSub,
|
|
|
|
},
|
2022-10-07 10:38:20 +00:00
|
|
|
#[diag(lint_non_binding_let_on_drop_type)]
|
2022-10-07 10:14:56 +00:00
|
|
|
DropType {
|
|
|
|
#[subdiagnostic]
|
|
|
|
sub: NonBindingLetSub,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct NonBindingLetSub {
|
|
|
|
pub suggestion: Span,
|
2024-01-07 19:37:51 +00:00
|
|
|
pub drop_fn_start_end: Option<(Span, Span)>,
|
2024-01-07 17:15:02 +00:00
|
|
|
pub is_assign_desugar: bool,
|
2022-10-07 10:14:56 +00:00
|
|
|
}
|
|
|
|
|
2024-03-06 03:00:16 +00:00
|
|
|
impl Subdiagnostic for NonBindingLetSub {
|
|
|
|
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
|
Reduce capabilities of `Diagnostic`.
Currently many diagnostic modifier methods are available on both
`Diagnostic` and `DiagnosticBuilder`. This commit removes most of them
from `Diagnostic`. To minimize the diff size, it keeps them within
`diagnostic.rs` but changes the surrounding `impl Diagnostic` block to
`impl DiagnosticBuilder`. (I intend to move things around later, to give
a more sensible code layout.)
`Diagnostic` keeps a few methods that it still needs, like `sub`,
`arg`, and `replace_args`.
The `forward!` macro, which defined two additional methods per call
(e.g. `note` and `with_note`), is replaced by the `with_fn!` macro,
which defines one additional method per call (e.g. `with_note`). It's
now also only used when necessary -- not all modifier methods currently
need a `with_*` form. (New ones can be easily added as necessary.)
All this also requires changing `trait AddToDiagnostic` so its methods
take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many
mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`.
There are three subdiagnostics -- `DelayedAtWithoutNewline`,
`DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` --
that are created within the diagnostics machinery and appended to
external diagnostics. These are handled at the `Diagnostic` level, which
means it's now hard to construct them via `derive(Diagnostic)`, so
instead we construct them by hand. This has no effect on what they look
like when printed.
There are lots of new `allow` markers for `untranslatable_diagnostics`
and `diagnostics_outside_of_impl`. This is because
`#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic`
modifier methods, but missing from the `DiagnosticBuilder` modifier
methods. They're now present.
2024-02-06 05:44:30 +00:00
|
|
|
self,
|
2024-02-22 23:20:45 +00:00
|
|
|
diag: &mut Diag<'_, G>,
|
2024-04-18 19:18:35 +00:00
|
|
|
_f: &F,
|
Reduce capabilities of `Diagnostic`.
Currently many diagnostic modifier methods are available on both
`Diagnostic` and `DiagnosticBuilder`. This commit removes most of them
from `Diagnostic`. To minimize the diff size, it keeps them within
`diagnostic.rs` but changes the surrounding `impl Diagnostic` block to
`impl DiagnosticBuilder`. (I intend to move things around later, to give
a more sensible code layout.)
`Diagnostic` keeps a few methods that it still needs, like `sub`,
`arg`, and `replace_args`.
The `forward!` macro, which defined two additional methods per call
(e.g. `note` and `with_note`), is replaced by the `with_fn!` macro,
which defines one additional method per call (e.g. `with_note`). It's
now also only used when necessary -- not all modifier methods currently
need a `with_*` form. (New ones can be easily added as necessary.)
All this also requires changing `trait AddToDiagnostic` so its methods
take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many
mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`.
There are three subdiagnostics -- `DelayedAtWithoutNewline`,
`DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` --
that are created within the diagnostics machinery and appended to
external diagnostics. These are handled at the `Diagnostic` level, which
means it's now hard to construct them via `derive(Diagnostic)`, so
instead we construct them by hand. This has no effect on what they look
like when printed.
There are lots of new `allow` markers for `untranslatable_diagnostics`
and `diagnostics_outside_of_impl`. This is because
`#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic`
modifier methods, but missing from the `DiagnosticBuilder` modifier
methods. They're now present.
2024-02-06 05:44:30 +00:00
|
|
|
) {
|
2024-01-07 19:37:51 +00:00
|
|
|
let can_suggest_binding = self.drop_fn_start_end.is_some() || !self.is_assign_desugar;
|
|
|
|
|
|
|
|
if can_suggest_binding {
|
|
|
|
let prefix = if self.is_assign_desugar { "let " } else { "" };
|
|
|
|
diag.span_suggestion_verbose(
|
|
|
|
self.suggestion,
|
|
|
|
fluent::lint_non_binding_let_suggestion,
|
|
|
|
format!("{prefix}_unused"),
|
|
|
|
Applicability::MachineApplicable,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
diag.span_help(self.suggestion, fluent::lint_non_binding_let_suggestion);
|
|
|
|
}
|
|
|
|
if let Some(drop_fn_start_end) = self.drop_fn_start_end {
|
|
|
|
diag.multipart_suggestion(
|
|
|
|
fluent::lint_non_binding_let_multi_suggestion,
|
|
|
|
vec![
|
|
|
|
(drop_fn_start_end.0, "drop(".to_string()),
|
|
|
|
(drop_fn_start_end.1, ")".to_string()),
|
|
|
|
],
|
|
|
|
Applicability::MachineApplicable,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
diag.help(fluent::lint_non_binding_let_multi_drop_fn);
|
|
|
|
}
|
2022-10-07 10:14:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-05 12:23:00 +00:00
|
|
|
// levels.rs
|
|
|
|
#[derive(LintDiagnostic)]
|
2022-10-07 00:28:51 +00:00
|
|
|
#[diag(lint_overruled_attribute)]
|
2023-04-10 20:02:52 +00:00
|
|
|
pub struct OverruledAttributeLint<'a> {
|
2022-10-07 00:28:51 +00:00
|
|
|
#[label]
|
|
|
|
pub overruled: Span,
|
|
|
|
pub lint_level: &'a str,
|
|
|
|
pub lint_source: Symbol,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub sub: OverruledAttributeSub,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_deprecated_lint_name)]
|
2022-10-05 12:23:00 +00:00
|
|
|
pub struct DeprecatedLintName<'a> {
|
|
|
|
pub name: String,
|
|
|
|
#[suggestion(code = "{replace}", applicability = "machine-applicable")]
|
|
|
|
pub suggestion: Span,
|
|
|
|
pub replace: &'a str,
|
|
|
|
}
|
|
|
|
|
2023-08-28 19:28:51 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_deprecated_lint_name)]
|
|
|
|
#[help]
|
|
|
|
pub struct DeprecatedLintNameFromCommandLine<'a> {
|
|
|
|
pub name: String,
|
|
|
|
pub replace: &'a str,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub requested_level: RequestedLevel<'a>,
|
|
|
|
}
|
|
|
|
|
2022-11-11 00:32:30 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
2023-08-23 22:53:37 +00:00
|
|
|
#[diag(lint_renamed_lint)]
|
|
|
|
pub struct RenamedLint<'a> {
|
|
|
|
pub name: &'a str,
|
2022-11-11 00:32:30 +00:00
|
|
|
#[subdiagnostic]
|
2023-08-23 22:53:37 +00:00
|
|
|
pub suggestion: RenamedLintSuggestion<'a>,
|
2022-10-07 00:28:51 +00:00
|
|
|
}
|
|
|
|
|
2022-11-11 00:32:30 +00:00
|
|
|
#[derive(Subdiagnostic)]
|
2023-08-28 19:28:51 +00:00
|
|
|
pub enum RenamedLintSuggestion<'a> {
|
|
|
|
#[suggestion(lint_suggestion, code = "{replace}", applicability = "machine-applicable")]
|
|
|
|
WithSpan {
|
|
|
|
#[primary_span]
|
|
|
|
suggestion: Span,
|
|
|
|
replace: &'a str,
|
|
|
|
},
|
|
|
|
#[help(lint_help)]
|
|
|
|
WithoutSpan { replace: &'a str },
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_renamed_lint)]
|
|
|
|
pub struct RenamedLintFromCommandLine<'a> {
|
|
|
|
pub name: &'a str,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub suggestion: RenamedLintSuggestion<'a>,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub requested_level: RequestedLevel<'a>,
|
2022-10-07 00:28:51 +00:00
|
|
|
}
|
|
|
|
|
2023-08-23 22:53:37 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_removed_lint)]
|
|
|
|
pub struct RemovedLint<'a> {
|
|
|
|
pub name: &'a str,
|
|
|
|
pub reason: &'a str,
|
|
|
|
}
|
|
|
|
|
2023-08-28 19:28:51 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_removed_lint)]
|
|
|
|
pub struct RemovedLintFromCommandLine<'a> {
|
|
|
|
pub name: &'a str,
|
|
|
|
pub reason: &'a str,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub requested_level: RequestedLevel<'a>,
|
|
|
|
}
|
|
|
|
|
2022-11-11 00:32:30 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unknown_lint)]
|
|
|
|
pub struct UnknownLint {
|
2022-10-07 00:28:51 +00:00
|
|
|
pub name: String,
|
2022-11-11 00:32:30 +00:00
|
|
|
#[subdiagnostic]
|
|
|
|
pub suggestion: Option<UnknownLintSuggestion>,
|
2022-10-07 00:28:51 +00:00
|
|
|
}
|
|
|
|
|
2022-11-11 00:32:30 +00:00
|
|
|
#[derive(Subdiagnostic)]
|
2023-08-28 19:28:51 +00:00
|
|
|
pub enum UnknownLintSuggestion {
|
|
|
|
#[suggestion(lint_suggestion, code = "{replace}", applicability = "maybe-incorrect")]
|
|
|
|
WithSpan {
|
|
|
|
#[primary_span]
|
|
|
|
suggestion: Span,
|
|
|
|
replace: Symbol,
|
2024-01-10 16:24:46 +00:00
|
|
|
from_rustc: bool,
|
2023-08-28 19:28:51 +00:00
|
|
|
},
|
|
|
|
#[help(lint_help)]
|
2024-01-10 16:24:46 +00:00
|
|
|
WithoutSpan { replace: Symbol, from_rustc: bool },
|
2023-08-28 19:28:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
Stop using `String` for error codes.
Error codes are integers, but `String` is used everywhere to represent
them. Gross!
This commit introduces `ErrCode`, an integral newtype for error codes,
replacing `String`. It also introduces a constant for every error code,
e.g. `E0123`, and removes the `error_code!` macro. The constants are
imported wherever used with `use rustc_errors::codes::*`.
With the old code, we have three different ways to specify an error code
at a use point:
```
error_code!(E0123) // macro call
struct_span_code_err!(dcx, span, E0123, "msg"); // bare ident arg to macro call
\#[diag(name, code = "E0123")] // string
struct Diag;
```
With the new code, they all use the `E0123` constant.
```
E0123 // constant
struct_span_code_err!(dcx, span, E0123, "msg"); // constant
\#[diag(name, code = E0123)] // constant
struct Diag;
```
The commit also changes the structure of the error code definitions:
- `rustc_error_codes` now just defines a higher-order macro listing the
used error codes and nothing else.
- Because that's now the only thing in the `rustc_error_codes` crate, I
moved it into the `lib.rs` file and removed the `error_codes.rs` file.
- `rustc_errors` uses that macro to define everything, e.g. the error
code constants and the `DIAGNOSTIC_TABLES`. This is in its new
`codes.rs` file.
2024-01-13 23:57:07 +00:00
|
|
|
#[diag(lint_unknown_lint, code = E0602)]
|
2023-08-28 19:28:51 +00:00
|
|
|
pub struct UnknownLintFromCommandLine<'a> {
|
|
|
|
pub name: String,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub suggestion: Option<UnknownLintSuggestion>,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub requested_level: RequestedLevel<'a>,
|
2022-10-07 00:28:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_ignored_unless_crate_specified)]
|
|
|
|
pub struct IgnoredUnlessCrateSpecified<'a> {
|
|
|
|
pub level: &'a str,
|
|
|
|
pub name: Symbol,
|
|
|
|
}
|
|
|
|
|
2022-10-04 23:39:02 +00:00
|
|
|
// methods.rs
|
2022-09-05 19:37:30 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_cstring_ptr)]
|
|
|
|
#[note]
|
|
|
|
#[help]
|
|
|
|
pub struct CStringPtr {
|
2022-10-13 09:13:02 +00:00
|
|
|
#[label(lint_as_ptr_label)]
|
2022-09-05 19:37:30 +00:00
|
|
|
pub as_ptr: Span,
|
2022-10-13 09:13:02 +00:00
|
|
|
#[label(lint_unwrap_label)]
|
2022-09-05 19:37:30 +00:00
|
|
|
pub unwrap: Span,
|
|
|
|
}
|
2022-10-04 23:39:02 +00:00
|
|
|
|
2022-12-09 02:27:03 +00:00
|
|
|
// multiple_supertrait_upcastable.rs
|
|
|
|
#[derive(LintDiagnostic)]
|
2023-04-10 20:02:52 +00:00
|
|
|
#[diag(lint_multiple_supertrait_upcastable)]
|
2022-12-09 02:27:03 +00:00
|
|
|
pub struct MultipleSupertraitUpcastable {
|
|
|
|
pub ident: Ident,
|
|
|
|
}
|
|
|
|
|
2022-10-04 23:39:02 +00:00
|
|
|
// non_ascii_idents.rs
|
2022-09-05 19:05:19 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_identifier_non_ascii_char)]
|
|
|
|
pub struct IdentifierNonAsciiChar;
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_identifier_uncommon_codepoints)]
|
2024-02-09 10:26:30 +00:00
|
|
|
#[note]
|
2024-01-23 02:56:33 +00:00
|
|
|
pub struct IdentifierUncommonCodepoints {
|
|
|
|
pub codepoints: Vec<char>,
|
2024-01-23 13:16:24 +00:00
|
|
|
pub codepoints_len: usize,
|
2024-02-09 10:26:30 +00:00
|
|
|
pub identifier_type: &'static str,
|
2024-01-23 02:56:33 +00:00
|
|
|
}
|
2022-09-05 19:05:19 +00:00
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_confusable_identifier_pair)]
|
|
|
|
pub struct ConfusableIdentifierPair {
|
|
|
|
pub existing_sym: Symbol,
|
|
|
|
pub sym: Symbol,
|
2023-08-04 16:46:08 +00:00
|
|
|
#[label(lint_other_use)]
|
2022-09-05 19:05:19 +00:00
|
|
|
pub label: Span,
|
2023-08-04 16:46:08 +00:00
|
|
|
#[label(lint_current_use)]
|
|
|
|
pub main_label: Span,
|
2022-09-05 19:05:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_mixed_script_confusables)]
|
2022-10-13 09:13:02 +00:00
|
|
|
#[note(lint_includes_note)]
|
2022-09-05 19:05:19 +00:00
|
|
|
#[note]
|
|
|
|
pub struct MixedScriptConfusables {
|
|
|
|
pub set: String,
|
|
|
|
pub includes: String,
|
|
|
|
}
|
|
|
|
|
2022-10-04 23:39:02 +00:00
|
|
|
// non_fmt_panic.rs
|
2022-09-05 18:38:36 +00:00
|
|
|
pub struct NonFmtPanicUnused {
|
|
|
|
pub count: usize,
|
|
|
|
pub suggestion: Option<Span>,
|
|
|
|
}
|
|
|
|
|
2022-11-11 00:32:30 +00:00
|
|
|
// Used because of two suggestions based on one Option<Span>
|
2024-03-08 01:03:51 +00:00
|
|
|
impl<'a> LintDiagnostic<'a, ()> for NonFmtPanicUnused {
|
2024-02-22 23:20:45 +00:00
|
|
|
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
|
2024-05-22 14:46:05 +00:00
|
|
|
diag.primary_message(fluent::lint_non_fmt_panic_unused);
|
2023-12-23 22:08:41 +00:00
|
|
|
diag.arg("count", self.count);
|
2022-10-13 09:13:02 +00:00
|
|
|
diag.note(fluent::lint_note);
|
2022-09-05 18:38:36 +00:00
|
|
|
if let Some(span) = self.suggestion {
|
|
|
|
diag.span_suggestion(
|
|
|
|
span.shrink_to_hi(),
|
2022-10-13 09:13:02 +00:00
|
|
|
fluent::lint_add_args_suggestion,
|
2022-09-05 18:38:36 +00:00
|
|
|
", ...",
|
|
|
|
Applicability::HasPlaceholders,
|
|
|
|
);
|
|
|
|
diag.span_suggestion(
|
|
|
|
span.shrink_to_lo(),
|
2022-10-13 09:13:02 +00:00
|
|
|
fluent::lint_add_fmt_suggestion,
|
2022-09-05 18:38:36 +00:00
|
|
|
"\"{}\", ",
|
|
|
|
Applicability::MachineApplicable,
|
|
|
|
);
|
|
|
|
}
|
2022-10-04 21:54:47 +00:00
|
|
|
}
|
2022-09-05 18:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_non_fmt_panic_braces)]
|
|
|
|
#[note]
|
|
|
|
pub struct NonFmtPanicBraces {
|
|
|
|
pub count: usize,
|
|
|
|
#[suggestion(code = "\"{{}}\", ", applicability = "machine-applicable")]
|
|
|
|
pub suggestion: Option<Span>,
|
|
|
|
}
|
|
|
|
|
2022-10-04 23:39:02 +00:00
|
|
|
// nonstandard_style.rs
|
2022-09-05 17:37:57 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_non_camel_case_type)]
|
|
|
|
pub struct NonCamelCaseType<'a> {
|
|
|
|
pub sort: &'a str,
|
|
|
|
pub name: &'a str,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub sub: NonCamelCaseTypeSub,
|
|
|
|
}
|
|
|
|
|
2022-09-22 00:47:24 +00:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-09-05 17:37:57 +00:00
|
|
|
pub enum NonCamelCaseTypeSub {
|
2022-10-13 09:13:02 +00:00
|
|
|
#[label(lint_label)]
|
2022-09-05 17:37:57 +00:00
|
|
|
Label {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
},
|
2022-10-13 09:13:02 +00:00
|
|
|
#[suggestion(lint_suggestion, code = "{replace}", applicability = "maybe-incorrect")]
|
2022-09-05 17:37:57 +00:00
|
|
|
Suggestion {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
replace: String,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_non_snake_case)]
|
|
|
|
pub struct NonSnakeCaseDiag<'a> {
|
|
|
|
pub sort: &'a str,
|
|
|
|
pub name: &'a str,
|
|
|
|
pub sc: String,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub sub: NonSnakeCaseDiagSub,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum NonSnakeCaseDiagSub {
|
|
|
|
Label { span: Span },
|
|
|
|
Help,
|
|
|
|
RenameOrConvertSuggestion { span: Span, suggestion: Ident },
|
|
|
|
ConvertSuggestion { span: Span, suggestion: String },
|
|
|
|
SuggestionAndNote { span: Span },
|
|
|
|
}
|
|
|
|
|
2024-03-06 03:00:16 +00:00
|
|
|
impl Subdiagnostic for NonSnakeCaseDiagSub {
|
|
|
|
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
|
Reduce capabilities of `Diagnostic`.
Currently many diagnostic modifier methods are available on both
`Diagnostic` and `DiagnosticBuilder`. This commit removes most of them
from `Diagnostic`. To minimize the diff size, it keeps them within
`diagnostic.rs` but changes the surrounding `impl Diagnostic` block to
`impl DiagnosticBuilder`. (I intend to move things around later, to give
a more sensible code layout.)
`Diagnostic` keeps a few methods that it still needs, like `sub`,
`arg`, and `replace_args`.
The `forward!` macro, which defined two additional methods per call
(e.g. `note` and `with_note`), is replaced by the `with_fn!` macro,
which defines one additional method per call (e.g. `with_note`). It's
now also only used when necessary -- not all modifier methods currently
need a `with_*` form. (New ones can be easily added as necessary.)
All this also requires changing `trait AddToDiagnostic` so its methods
take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many
mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`.
There are three subdiagnostics -- `DelayedAtWithoutNewline`,
`DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` --
that are created within the diagnostics machinery and appended to
external diagnostics. These are handled at the `Diagnostic` level, which
means it's now hard to construct them via `derive(Diagnostic)`, so
instead we construct them by hand. This has no effect on what they look
like when printed.
There are lots of new `allow` markers for `untranslatable_diagnostics`
and `diagnostics_outside_of_impl`. This is because
`#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic`
modifier methods, but missing from the `DiagnosticBuilder` modifier
methods. They're now present.
2024-02-06 05:44:30 +00:00
|
|
|
self,
|
2024-02-22 23:20:45 +00:00
|
|
|
diag: &mut Diag<'_, G>,
|
2024-04-18 19:18:35 +00:00
|
|
|
_f: &F,
|
Reduce capabilities of `Diagnostic`.
Currently many diagnostic modifier methods are available on both
`Diagnostic` and `DiagnosticBuilder`. This commit removes most of them
from `Diagnostic`. To minimize the diff size, it keeps them within
`diagnostic.rs` but changes the surrounding `impl Diagnostic` block to
`impl DiagnosticBuilder`. (I intend to move things around later, to give
a more sensible code layout.)
`Diagnostic` keeps a few methods that it still needs, like `sub`,
`arg`, and `replace_args`.
The `forward!` macro, which defined two additional methods per call
(e.g. `note` and `with_note`), is replaced by the `with_fn!` macro,
which defines one additional method per call (e.g. `with_note`). It's
now also only used when necessary -- not all modifier methods currently
need a `with_*` form. (New ones can be easily added as necessary.)
All this also requires changing `trait AddToDiagnostic` so its methods
take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many
mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`.
There are three subdiagnostics -- `DelayedAtWithoutNewline`,
`DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` --
that are created within the diagnostics machinery and appended to
external diagnostics. These are handled at the `Diagnostic` level, which
means it's now hard to construct them via `derive(Diagnostic)`, so
instead we construct them by hand. This has no effect on what they look
like when printed.
There are lots of new `allow` markers for `untranslatable_diagnostics`
and `diagnostics_outside_of_impl`. This is because
`#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic`
modifier methods, but missing from the `DiagnosticBuilder` modifier
methods. They're now present.
2024-02-06 05:44:30 +00:00
|
|
|
) {
|
2022-09-05 17:37:57 +00:00
|
|
|
match self {
|
|
|
|
NonSnakeCaseDiagSub::Label { span } => {
|
2022-10-13 09:13:02 +00:00
|
|
|
diag.span_label(span, fluent::lint_label);
|
2022-09-05 17:37:57 +00:00
|
|
|
}
|
|
|
|
NonSnakeCaseDiagSub::Help => {
|
2022-10-13 09:13:02 +00:00
|
|
|
diag.help(fluent::lint_help);
|
2022-09-05 17:37:57 +00:00
|
|
|
}
|
|
|
|
NonSnakeCaseDiagSub::ConvertSuggestion { span, suggestion } => {
|
|
|
|
diag.span_suggestion(
|
|
|
|
span,
|
2022-10-13 09:13:02 +00:00
|
|
|
fluent::lint_convert_suggestion,
|
2022-09-05 17:37:57 +00:00
|
|
|
suggestion,
|
|
|
|
Applicability::MaybeIncorrect,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
NonSnakeCaseDiagSub::RenameOrConvertSuggestion { span, suggestion } => {
|
|
|
|
diag.span_suggestion(
|
|
|
|
span,
|
2022-10-13 09:13:02 +00:00
|
|
|
fluent::lint_rename_or_convert_suggestion,
|
2022-09-05 17:37:57 +00:00
|
|
|
suggestion,
|
|
|
|
Applicability::MaybeIncorrect,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
NonSnakeCaseDiagSub::SuggestionAndNote { span } => {
|
2022-10-13 09:13:02 +00:00
|
|
|
diag.note(fluent::lint_cannot_convert_note);
|
2022-09-05 17:37:57 +00:00
|
|
|
diag.span_suggestion(
|
|
|
|
span,
|
2022-10-13 09:13:02 +00:00
|
|
|
fluent::lint_rename_suggestion,
|
2022-09-05 17:37:57 +00:00
|
|
|
"",
|
|
|
|
Applicability::MaybeIncorrect,
|
|
|
|
);
|
|
|
|
}
|
2022-10-04 21:54:47 +00:00
|
|
|
}
|
2022-09-05 17:37:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_non_upper_case_global)]
|
|
|
|
pub struct NonUpperCaseGlobal<'a> {
|
|
|
|
pub sort: &'a str,
|
|
|
|
pub name: &'a str,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub sub: NonUpperCaseGlobalSub,
|
|
|
|
}
|
|
|
|
|
2022-09-22 00:47:24 +00:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-09-05 17:37:57 +00:00
|
|
|
pub enum NonUpperCaseGlobalSub {
|
2022-10-13 09:13:02 +00:00
|
|
|
#[label(lint_label)]
|
2022-09-05 17:37:57 +00:00
|
|
|
Label {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
},
|
2022-10-13 09:13:02 +00:00
|
|
|
#[suggestion(lint_suggestion, code = "{replace}", applicability = "maybe-incorrect")]
|
2022-09-05 17:37:57 +00:00
|
|
|
Suggestion {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
replace: String,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-10-04 23:39:02 +00:00
|
|
|
// noop_method_call.rs
|
2022-09-05 16:42:58 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_noop_method_call)]
|
|
|
|
#[note]
|
|
|
|
pub struct NoopMethodCallDiag<'a> {
|
|
|
|
pub method: Symbol,
|
2023-05-25 05:21:44 +00:00
|
|
|
pub orig_ty: Ty<'a>,
|
|
|
|
pub trait_: Symbol,
|
2023-07-23 09:56:56 +00:00
|
|
|
#[suggestion(code = "", applicability = "machine-applicable")]
|
2022-09-05 16:42:58 +00:00
|
|
|
pub label: Span,
|
2024-02-22 18:01:12 +00:00
|
|
|
#[suggestion(
|
|
|
|
lint_derive_suggestion,
|
|
|
|
code = "#[derive(Clone)]\n",
|
|
|
|
applicability = "maybe-incorrect"
|
|
|
|
)]
|
|
|
|
pub suggest_derive: Option<Span>,
|
2022-09-05 16:42:58 +00:00
|
|
|
}
|
|
|
|
|
2023-04-28 17:17:46 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
2023-06-11 08:18:56 +00:00
|
|
|
#[diag(lint_suspicious_double_ref_deref)]
|
|
|
|
pub struct SuspiciousDoubleRefDerefDiag<'a> {
|
|
|
|
pub ty: Ty<'a>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_suspicious_double_ref_clone)]
|
|
|
|
pub struct SuspiciousDoubleRefCloneDiag<'a> {
|
2023-04-28 17:17:46 +00:00
|
|
|
pub ty: Ty<'a>,
|
|
|
|
}
|
|
|
|
|
2024-01-26 14:25:18 +00:00
|
|
|
// non_local_defs.rs
|
|
|
|
pub enum NonLocalDefinitionsDiag {
|
2024-02-15 19:30:16 +00:00
|
|
|
Impl {
|
|
|
|
depth: u32,
|
|
|
|
body_kind_descr: &'static str,
|
|
|
|
body_name: String,
|
2024-02-15 19:33:30 +00:00
|
|
|
cargo_update: Option<NonLocalDefinitionsCargoUpdateNote>,
|
2024-05-13 18:15:57 +00:00
|
|
|
const_anon: Option<Option<Span>>,
|
2024-05-18 13:07:28 +00:00
|
|
|
move_to: Option<(Span, Vec<Span>)>,
|
2024-05-15 12:55:40 +00:00
|
|
|
may_remove: Option<(Span, String)>,
|
2024-05-13 18:15:57 +00:00
|
|
|
has_trait: bool,
|
2024-05-15 17:13:02 +00:00
|
|
|
self_ty_str: String,
|
|
|
|
of_trait_str: Option<String>,
|
2024-02-15 19:30:16 +00:00
|
|
|
},
|
2024-02-15 19:33:30 +00:00
|
|
|
MacroRules {
|
|
|
|
depth: u32,
|
|
|
|
body_kind_descr: &'static str,
|
|
|
|
body_name: String,
|
2024-04-30 20:40:19 +00:00
|
|
|
help: Option<()>,
|
|
|
|
doctest_help: Option<()>,
|
2024-02-15 19:33:30 +00:00
|
|
|
cargo_update: Option<NonLocalDefinitionsCargoUpdateNote>,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-05-13 17:35:52 +00:00
|
|
|
impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag {
|
|
|
|
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
|
|
|
|
match self {
|
|
|
|
NonLocalDefinitionsDiag::Impl {
|
|
|
|
depth,
|
|
|
|
body_kind_descr,
|
|
|
|
body_name,
|
|
|
|
cargo_update,
|
|
|
|
const_anon,
|
2024-05-18 13:07:28 +00:00
|
|
|
move_to,
|
2024-05-15 12:55:40 +00:00
|
|
|
may_remove,
|
2024-05-13 18:15:57 +00:00
|
|
|
has_trait,
|
2024-05-15 17:13:02 +00:00
|
|
|
self_ty_str,
|
|
|
|
of_trait_str,
|
2024-05-13 17:35:52 +00:00
|
|
|
} => {
|
|
|
|
diag.primary_message(fluent::lint_non_local_definitions_impl);
|
|
|
|
diag.arg("depth", depth);
|
|
|
|
diag.arg("body_kind_descr", body_kind_descr);
|
|
|
|
diag.arg("body_name", body_name);
|
2024-05-15 17:13:02 +00:00
|
|
|
diag.arg("self_ty_str", self_ty_str);
|
|
|
|
if let Some(of_trait_str) = of_trait_str {
|
|
|
|
diag.arg("of_trait_str", of_trait_str);
|
|
|
|
}
|
2024-05-13 17:35:52 +00:00
|
|
|
|
2024-05-13 18:15:57 +00:00
|
|
|
if has_trait {
|
|
|
|
diag.note(fluent::lint_bounds);
|
|
|
|
diag.note(fluent::lint_with_trait);
|
|
|
|
} else {
|
|
|
|
diag.note(fluent::lint_without_trait);
|
|
|
|
}
|
2024-05-15 12:08:28 +00:00
|
|
|
|
2024-05-18 13:07:28 +00:00
|
|
|
if let Some((move_help, may_move)) = move_to {
|
|
|
|
let mut ms = MultiSpan::from_span(move_help);
|
|
|
|
for sp in may_move {
|
|
|
|
ms.push_span_label(sp, fluent::lint_non_local_definitions_may_move);
|
|
|
|
}
|
|
|
|
diag.span_help(ms, fluent::lint_non_local_definitions_impl_move_help);
|
2024-05-14 10:41:27 +00:00
|
|
|
}
|
2024-05-15 12:55:40 +00:00
|
|
|
|
|
|
|
if let Some((span, part)) = may_remove {
|
|
|
|
diag.arg("may_remove_part", part);
|
|
|
|
diag.span_suggestion(
|
|
|
|
span,
|
|
|
|
fluent::lint_remove_help,
|
|
|
|
"",
|
|
|
|
Applicability::MaybeIncorrect,
|
|
|
|
);
|
|
|
|
}
|
2024-05-13 17:35:52 +00:00
|
|
|
|
|
|
|
if let Some(cargo_update) = cargo_update {
|
|
|
|
diag.subdiagnostic(&diag.dcx, cargo_update);
|
|
|
|
}
|
|
|
|
if let Some(const_anon) = const_anon {
|
2024-05-13 18:15:57 +00:00
|
|
|
diag.note(fluent::lint_exception);
|
|
|
|
if let Some(const_anon) = const_anon {
|
|
|
|
diag.span_suggestion(
|
|
|
|
const_anon,
|
|
|
|
fluent::lint_const_anon,
|
|
|
|
"_",
|
|
|
|
Applicability::MachineApplicable,
|
|
|
|
);
|
|
|
|
}
|
2024-05-13 17:35:52 +00:00
|
|
|
}
|
2024-05-13 18:15:57 +00:00
|
|
|
|
|
|
|
diag.note(fluent::lint_non_local_definitions_deprecation);
|
2024-05-13 17:35:52 +00:00
|
|
|
}
|
|
|
|
NonLocalDefinitionsDiag::MacroRules {
|
|
|
|
depth,
|
|
|
|
body_kind_descr,
|
|
|
|
body_name,
|
|
|
|
help,
|
|
|
|
doctest_help,
|
|
|
|
cargo_update,
|
|
|
|
} => {
|
|
|
|
diag.primary_message(fluent::lint_non_local_definitions_macro_rules);
|
|
|
|
diag.arg("depth", depth);
|
|
|
|
diag.arg("body_kind_descr", body_kind_descr);
|
|
|
|
diag.arg("body_name", body_name);
|
|
|
|
|
|
|
|
if let Some(()) = help {
|
|
|
|
diag.help(fluent::lint_help);
|
|
|
|
}
|
|
|
|
if let Some(()) = doctest_help {
|
|
|
|
diag.help(fluent::lint_help_doctest);
|
|
|
|
}
|
|
|
|
|
|
|
|
diag.note(fluent::lint_non_local);
|
|
|
|
diag.note(fluent::lint_non_local_definitions_deprecation);
|
|
|
|
|
|
|
|
if let Some(cargo_update) = cargo_update {
|
|
|
|
diag.subdiagnostic(&diag.dcx, cargo_update);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-15 19:33:30 +00:00
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
#[note(lint_non_local_definitions_cargo_update)]
|
|
|
|
pub struct NonLocalDefinitionsCargoUpdateNote {
|
|
|
|
pub macro_kind: &'static str,
|
|
|
|
pub macro_name: Symbol,
|
|
|
|
pub crate_name: Symbol,
|
2024-01-26 14:25:18 +00:00
|
|
|
}
|
|
|
|
|
2022-10-04 23:39:02 +00:00
|
|
|
// pass_by_value.rs
|
2022-09-05 16:38:55 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_pass_by_value)]
|
|
|
|
pub struct PassByValueDiag {
|
|
|
|
pub ty: String,
|
|
|
|
#[suggestion(code = "{ty}", applicability = "maybe-incorrect")]
|
|
|
|
pub suggestion: Span,
|
|
|
|
}
|
|
|
|
|
2022-10-04 23:39:02 +00:00
|
|
|
// redundant_semicolon.rs
|
2022-09-05 16:32:01 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_redundant_semicolons)]
|
|
|
|
pub struct RedundantSemicolonsDiag {
|
|
|
|
pub multiple: bool,
|
|
|
|
#[suggestion(code = "", applicability = "maybe-incorrect")]
|
|
|
|
pub suggestion: Span,
|
|
|
|
}
|
|
|
|
|
2022-10-04 23:39:02 +00:00
|
|
|
// traits.rs
|
2022-09-05 15:52:08 +00:00
|
|
|
pub struct DropTraitConstraintsDiag<'a> {
|
2023-06-22 18:17:13 +00:00
|
|
|
pub predicate: Clause<'a>,
|
2022-09-05 15:52:08 +00:00
|
|
|
pub tcx: TyCtxt<'a>,
|
|
|
|
pub def_id: DefId,
|
|
|
|
}
|
|
|
|
|
2022-11-11 00:32:30 +00:00
|
|
|
// Needed for def_path_str
|
2024-03-08 01:03:51 +00:00
|
|
|
impl<'a> LintDiagnostic<'a, ()> for DropTraitConstraintsDiag<'_> {
|
2024-02-22 23:20:45 +00:00
|
|
|
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
|
2024-05-22 14:46:05 +00:00
|
|
|
diag.primary_message(fluent::lint_drop_trait_constraints);
|
2023-12-23 22:08:41 +00:00
|
|
|
diag.arg("predicate", self.predicate);
|
|
|
|
diag.arg("needs_drop", self.tcx.def_path_str(self.def_id));
|
2022-10-04 21:54:47 +00:00
|
|
|
}
|
2022-09-05 15:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct DropGlue<'a> {
|
|
|
|
pub tcx: TyCtxt<'a>,
|
|
|
|
pub def_id: DefId,
|
|
|
|
}
|
|
|
|
|
2022-11-11 00:32:30 +00:00
|
|
|
// Needed for def_path_str
|
2024-03-08 01:03:51 +00:00
|
|
|
impl<'a> LintDiagnostic<'a, ()> for DropGlue<'_> {
|
2024-02-22 23:20:45 +00:00
|
|
|
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
|
2024-05-22 14:46:05 +00:00
|
|
|
diag.primary_message(fluent::lint_drop_glue);
|
2023-12-23 22:08:41 +00:00
|
|
|
diag.arg("needs_drop", self.tcx.def_path_str(self.def_id));
|
2022-10-04 21:54:47 +00:00
|
|
|
}
|
2022-09-05 15:52:08 +00:00
|
|
|
}
|
|
|
|
|
2022-10-04 23:39:02 +00:00
|
|
|
// types.rs
|
2022-08-28 23:07:58 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_range_endpoint_out_of_range)]
|
|
|
|
pub struct RangeEndpointOutOfRange<'a> {
|
|
|
|
pub ty: &'a str,
|
2023-03-24 17:00:49 +00:00
|
|
|
#[subdiagnostic]
|
|
|
|
pub sub: UseInclusiveRange<'a>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
pub enum UseInclusiveRange<'a> {
|
|
|
|
#[suggestion(
|
|
|
|
lint_range_use_inclusive_range,
|
|
|
|
code = "{start}..={literal}{suffix}",
|
|
|
|
applicability = "machine-applicable"
|
|
|
|
)]
|
|
|
|
WithoutParen {
|
|
|
|
#[primary_span]
|
|
|
|
sugg: Span,
|
|
|
|
start: String,
|
|
|
|
literal: u128,
|
|
|
|
suffix: &'a str,
|
|
|
|
},
|
|
|
|
#[multipart_suggestion(lint_range_use_inclusive_range, applicability = "machine-applicable")]
|
|
|
|
WithParen {
|
|
|
|
#[suggestion_part(code = "=")]
|
|
|
|
eq_sugg: Span,
|
|
|
|
#[suggestion_part(code = "{literal}{suffix}")]
|
|
|
|
lit_sugg: Span,
|
|
|
|
literal: u128,
|
|
|
|
suffix: &'a str,
|
|
|
|
},
|
2022-08-28 23:07:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_overflowing_bin_hex)]
|
|
|
|
pub struct OverflowingBinHex<'a> {
|
|
|
|
pub ty: &'a str,
|
|
|
|
pub lit: String,
|
|
|
|
pub dec: u128,
|
|
|
|
pub actually: String,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub sign: OverflowingBinHexSign,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub sub: Option<OverflowingBinHexSub<'a>>,
|
2023-05-04 17:29:11 +00:00
|
|
|
#[subdiagnostic]
|
|
|
|
pub sign_bit_sub: Option<OverflowingBinHexSignBitSub<'a>>,
|
2022-08-28 23:07:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub enum OverflowingBinHexSign {
|
|
|
|
Positive,
|
|
|
|
Negative,
|
|
|
|
}
|
|
|
|
|
2024-03-06 03:00:16 +00:00
|
|
|
impl Subdiagnostic for OverflowingBinHexSign {
|
|
|
|
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
|
Reduce capabilities of `Diagnostic`.
Currently many diagnostic modifier methods are available on both
`Diagnostic` and `DiagnosticBuilder`. This commit removes most of them
from `Diagnostic`. To minimize the diff size, it keeps them within
`diagnostic.rs` but changes the surrounding `impl Diagnostic` block to
`impl DiagnosticBuilder`. (I intend to move things around later, to give
a more sensible code layout.)
`Diagnostic` keeps a few methods that it still needs, like `sub`,
`arg`, and `replace_args`.
The `forward!` macro, which defined two additional methods per call
(e.g. `note` and `with_note`), is replaced by the `with_fn!` macro,
which defines one additional method per call (e.g. `with_note`). It's
now also only used when necessary -- not all modifier methods currently
need a `with_*` form. (New ones can be easily added as necessary.)
All this also requires changing `trait AddToDiagnostic` so its methods
take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many
mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`.
There are three subdiagnostics -- `DelayedAtWithoutNewline`,
`DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` --
that are created within the diagnostics machinery and appended to
external diagnostics. These are handled at the `Diagnostic` level, which
means it's now hard to construct them via `derive(Diagnostic)`, so
instead we construct them by hand. This has no effect on what they look
like when printed.
There are lots of new `allow` markers for `untranslatable_diagnostics`
and `diagnostics_outside_of_impl`. This is because
`#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic`
modifier methods, but missing from the `DiagnosticBuilder` modifier
methods. They're now present.
2024-02-06 05:44:30 +00:00
|
|
|
self,
|
2024-02-22 23:20:45 +00:00
|
|
|
diag: &mut Diag<'_, G>,
|
2024-04-18 19:18:35 +00:00
|
|
|
_f: &F,
|
Reduce capabilities of `Diagnostic`.
Currently many diagnostic modifier methods are available on both
`Diagnostic` and `DiagnosticBuilder`. This commit removes most of them
from `Diagnostic`. To minimize the diff size, it keeps them within
`diagnostic.rs` but changes the surrounding `impl Diagnostic` block to
`impl DiagnosticBuilder`. (I intend to move things around later, to give
a more sensible code layout.)
`Diagnostic` keeps a few methods that it still needs, like `sub`,
`arg`, and `replace_args`.
The `forward!` macro, which defined two additional methods per call
(e.g. `note` and `with_note`), is replaced by the `with_fn!` macro,
which defines one additional method per call (e.g. `with_note`). It's
now also only used when necessary -- not all modifier methods currently
need a `with_*` form. (New ones can be easily added as necessary.)
All this also requires changing `trait AddToDiagnostic` so its methods
take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many
mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`.
There are three subdiagnostics -- `DelayedAtWithoutNewline`,
`DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` --
that are created within the diagnostics machinery and appended to
external diagnostics. These are handled at the `Diagnostic` level, which
means it's now hard to construct them via `derive(Diagnostic)`, so
instead we construct them by hand. This has no effect on what they look
like when printed.
There are lots of new `allow` markers for `untranslatable_diagnostics`
and `diagnostics_outside_of_impl`. This is because
`#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic`
modifier methods, but missing from the `DiagnosticBuilder` modifier
methods. They're now present.
2024-02-06 05:44:30 +00:00
|
|
|
) {
|
2022-08-28 23:07:58 +00:00
|
|
|
match self {
|
|
|
|
OverflowingBinHexSign::Positive => {
|
2022-10-13 09:13:02 +00:00
|
|
|
diag.note(fluent::lint_positive_note);
|
2022-08-28 23:07:58 +00:00
|
|
|
}
|
|
|
|
OverflowingBinHexSign::Negative => {
|
2022-10-13 09:13:02 +00:00
|
|
|
diag.note(fluent::lint_negative_note);
|
|
|
|
diag.note(fluent::lint_negative_becomes_note);
|
2022-08-28 23:07:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-22 00:47:24 +00:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-08-28 23:07:58 +00:00
|
|
|
pub enum OverflowingBinHexSub<'a> {
|
|
|
|
#[suggestion(
|
2022-10-13 09:13:02 +00:00
|
|
|
lint_suggestion,
|
2022-08-28 23:07:58 +00:00
|
|
|
code = "{sans_suffix}{suggestion_ty}",
|
|
|
|
applicability = "machine-applicable"
|
|
|
|
)]
|
|
|
|
Suggestion {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
suggestion_ty: &'a str,
|
|
|
|
sans_suffix: &'a str,
|
|
|
|
},
|
2022-10-13 09:13:02 +00:00
|
|
|
#[help(lint_help)]
|
2022-08-28 23:07:58 +00:00
|
|
|
Help { suggestion_ty: &'a str },
|
|
|
|
}
|
|
|
|
|
2023-05-04 17:29:11 +00:00
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
#[suggestion(
|
|
|
|
lint_sign_bit_suggestion,
|
|
|
|
code = "{lit_no_suffix}{uint_ty} as {int_ty}",
|
|
|
|
applicability = "maybe-incorrect"
|
|
|
|
)]
|
|
|
|
pub struct OverflowingBinHexSignBitSub<'a> {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub lit_no_suffix: &'a str,
|
|
|
|
pub negative_val: String,
|
|
|
|
pub uint_ty: &'a str,
|
|
|
|
pub int_ty: &'a str,
|
|
|
|
}
|
|
|
|
|
2022-11-11 00:32:30 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_overflowing_int)]
|
|
|
|
#[note]
|
2022-08-28 23:07:58 +00:00
|
|
|
pub struct OverflowingInt<'a> {
|
|
|
|
pub ty: &'a str,
|
|
|
|
pub lit: String,
|
|
|
|
pub min: i128,
|
|
|
|
pub max: u128,
|
2022-11-11 00:32:30 +00:00
|
|
|
#[subdiagnostic]
|
|
|
|
pub help: Option<OverflowingIntHelp<'a>>,
|
2022-08-28 23:07:58 +00:00
|
|
|
}
|
|
|
|
|
2022-11-11 00:32:30 +00:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-10-13 09:13:02 +00:00
|
|
|
#[help(lint_help)]
|
2022-11-11 00:32:30 +00:00
|
|
|
pub struct OverflowingIntHelp<'a> {
|
|
|
|
pub suggestion_ty: &'a str,
|
2022-08-28 23:07:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_only_cast_u8_to_char)]
|
|
|
|
pub struct OnlyCastu8ToChar {
|
|
|
|
#[suggestion(code = "'\\u{{{literal:X}}}'", applicability = "machine-applicable")]
|
|
|
|
pub span: Span,
|
|
|
|
pub literal: u128,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_overflowing_uint)]
|
|
|
|
#[note]
|
|
|
|
pub struct OverflowingUInt<'a> {
|
|
|
|
pub ty: &'a str,
|
|
|
|
pub lit: String,
|
|
|
|
pub min: u128,
|
|
|
|
pub max: u128,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_overflowing_literal)]
|
|
|
|
#[note]
|
|
|
|
pub struct OverflowingLiteral<'a> {
|
|
|
|
pub ty: &'a str,
|
|
|
|
pub lit: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unused_comparisons)]
|
|
|
|
pub struct UnusedComparisons;
|
|
|
|
|
2023-05-20 21:05:09 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
pub enum InvalidNanComparisons {
|
|
|
|
#[diag(lint_invalid_nan_comparisons_eq_ne)]
|
|
|
|
EqNe {
|
|
|
|
#[subdiagnostic]
|
2023-08-04 21:40:55 +00:00
|
|
|
suggestion: Option<InvalidNanComparisonsSuggestion>,
|
2023-05-20 21:05:09 +00:00
|
|
|
},
|
|
|
|
#[diag(lint_invalid_nan_comparisons_lt_le_gt_ge)]
|
|
|
|
LtLeGtGe,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
pub enum InvalidNanComparisonsSuggestion {
|
|
|
|
#[multipart_suggestion(
|
|
|
|
lint_suggestion,
|
|
|
|
style = "verbose",
|
|
|
|
applicability = "machine-applicable"
|
|
|
|
)]
|
|
|
|
Spanful {
|
|
|
|
#[suggestion_part(code = "!")]
|
|
|
|
neg: Option<Span>,
|
|
|
|
#[suggestion_part(code = ".is_nan()")]
|
|
|
|
float: Span,
|
|
|
|
#[suggestion_part(code = "")]
|
|
|
|
nan_plus_binop: Span,
|
|
|
|
},
|
|
|
|
#[help(lint_suggestion)]
|
|
|
|
Spanless,
|
|
|
|
}
|
|
|
|
|
2023-11-09 16:37:27 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
pub enum AmbiguousWidePointerComparisons<'a> {
|
|
|
|
#[diag(lint_ambiguous_wide_pointer_comparisons)]
|
|
|
|
Spanful {
|
|
|
|
#[subdiagnostic]
|
|
|
|
addr_suggestion: AmbiguousWidePointerComparisonsAddrSuggestion<'a>,
|
|
|
|
#[subdiagnostic]
|
|
|
|
addr_metadata_suggestion: Option<AmbiguousWidePointerComparisonsAddrMetadataSuggestion<'a>>,
|
|
|
|
},
|
|
|
|
#[diag(lint_ambiguous_wide_pointer_comparisons)]
|
|
|
|
#[help(lint_addr_metadata_suggestion)]
|
|
|
|
#[help(lint_addr_suggestion)]
|
|
|
|
Spanless,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
#[multipart_suggestion(
|
|
|
|
lint_addr_metadata_suggestion,
|
|
|
|
style = "verbose",
|
2024-02-20 11:35:13 +00:00
|
|
|
// FIXME(#53934): make machine-applicable again
|
|
|
|
applicability = "maybe-incorrect"
|
2023-11-09 16:37:27 +00:00
|
|
|
)]
|
|
|
|
pub struct AmbiguousWidePointerComparisonsAddrMetadataSuggestion<'a> {
|
|
|
|
pub ne: &'a str,
|
|
|
|
pub deref_left: &'a str,
|
|
|
|
pub deref_right: &'a str,
|
2024-02-19 20:50:33 +00:00
|
|
|
pub l_modifiers: &'a str,
|
|
|
|
pub r_modifiers: &'a str,
|
2023-11-09 16:37:27 +00:00
|
|
|
#[suggestion_part(code = "{ne}std::ptr::eq({deref_left}")]
|
|
|
|
pub left: Span,
|
2024-02-19 20:50:33 +00:00
|
|
|
#[suggestion_part(code = "{l_modifiers}, {deref_right}")]
|
2023-11-09 16:37:27 +00:00
|
|
|
pub middle: Span,
|
2024-02-19 20:50:33 +00:00
|
|
|
#[suggestion_part(code = "{r_modifiers})")]
|
2023-11-09 16:37:27 +00:00
|
|
|
pub right: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
pub enum AmbiguousWidePointerComparisonsAddrSuggestion<'a> {
|
|
|
|
#[multipart_suggestion(
|
|
|
|
lint_addr_suggestion,
|
|
|
|
style = "verbose",
|
2024-02-20 11:35:13 +00:00
|
|
|
// FIXME(#53934): make machine-applicable again
|
|
|
|
applicability = "maybe-incorrect"
|
2023-11-09 16:37:27 +00:00
|
|
|
)]
|
|
|
|
AddrEq {
|
|
|
|
ne: &'a str,
|
|
|
|
deref_left: &'a str,
|
|
|
|
deref_right: &'a str,
|
2024-02-19 20:50:33 +00:00
|
|
|
l_modifiers: &'a str,
|
|
|
|
r_modifiers: &'a str,
|
2023-11-09 16:37:27 +00:00
|
|
|
#[suggestion_part(code = "{ne}std::ptr::addr_eq({deref_left}")]
|
|
|
|
left: Span,
|
2024-02-19 20:50:33 +00:00
|
|
|
#[suggestion_part(code = "{l_modifiers}, {deref_right}")]
|
2023-11-09 16:37:27 +00:00
|
|
|
middle: Span,
|
2024-02-19 20:50:33 +00:00
|
|
|
#[suggestion_part(code = "{r_modifiers})")]
|
2023-11-09 16:37:27 +00:00
|
|
|
right: Span,
|
|
|
|
},
|
|
|
|
#[multipart_suggestion(
|
|
|
|
lint_addr_suggestion,
|
|
|
|
style = "verbose",
|
2024-02-20 11:35:13 +00:00
|
|
|
// FIXME(#53934): make machine-applicable again
|
|
|
|
applicability = "maybe-incorrect"
|
2023-11-09 16:37:27 +00:00
|
|
|
)]
|
|
|
|
Cast {
|
|
|
|
deref_left: &'a str,
|
|
|
|
deref_right: &'a str,
|
2024-02-18 14:23:03 +00:00
|
|
|
paren_left: &'a str,
|
|
|
|
paren_right: &'a str,
|
2024-02-19 20:50:33 +00:00
|
|
|
l_modifiers: &'a str,
|
|
|
|
r_modifiers: &'a str,
|
2024-02-18 14:23:03 +00:00
|
|
|
#[suggestion_part(code = "({deref_left}")]
|
2023-11-09 16:37:27 +00:00
|
|
|
left_before: Option<Span>,
|
2024-02-19 20:50:33 +00:00
|
|
|
#[suggestion_part(code = "{l_modifiers}{paren_left}.cast::<()>()")]
|
2024-02-18 14:23:03 +00:00
|
|
|
left_after: Span,
|
|
|
|
#[suggestion_part(code = "({deref_right}")]
|
2023-11-09 16:37:27 +00:00
|
|
|
right_before: Option<Span>,
|
2024-02-19 20:50:33 +00:00
|
|
|
#[suggestion_part(code = "{r_modifiers}{paren_right}.cast::<()>()")]
|
2024-02-18 14:23:03 +00:00
|
|
|
right_after: Span,
|
2023-11-09 16:37:27 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-10-07 10:38:20 +00:00
|
|
|
pub struct ImproperCTypes<'a> {
|
|
|
|
pub ty: Ty<'a>,
|
|
|
|
pub desc: &'a str,
|
|
|
|
pub label: Span,
|
2024-02-29 00:58:51 +00:00
|
|
|
pub help: Option<DiagMessage>,
|
|
|
|
pub note: DiagMessage,
|
2022-10-07 10:38:20 +00:00
|
|
|
pub span_note: Option<Span>,
|
|
|
|
}
|
|
|
|
|
2024-02-29 00:58:51 +00:00
|
|
|
// Used because of the complexity of Option<DiagMessage>, DiagMessage, and Option<Span>
|
2024-03-08 01:03:51 +00:00
|
|
|
impl<'a> LintDiagnostic<'a, ()> for ImproperCTypes<'_> {
|
2024-02-22 23:20:45 +00:00
|
|
|
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
|
2024-05-22 14:46:05 +00:00
|
|
|
diag.primary_message(fluent::lint_improper_ctypes);
|
2023-12-23 22:08:41 +00:00
|
|
|
diag.arg("ty", self.ty);
|
|
|
|
diag.arg("desc", self.desc);
|
2022-10-13 09:13:02 +00:00
|
|
|
diag.span_label(self.label, fluent::lint_label);
|
2022-10-07 10:38:20 +00:00
|
|
|
if let Some(help) = self.help {
|
|
|
|
diag.help(help);
|
|
|
|
}
|
|
|
|
diag.note(self.note);
|
|
|
|
if let Some(note) = self.span_note {
|
2022-10-13 09:13:02 +00:00
|
|
|
diag.span_note(note, fluent::lint_note);
|
2022-10-07 10:38:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-28 23:07:58 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_variant_size_differences)]
|
|
|
|
pub struct VariantSizeDifferencesDiag {
|
|
|
|
pub largest: u64,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_atomic_ordering_load)]
|
|
|
|
#[help]
|
|
|
|
pub struct AtomicOrderingLoad;
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_atomic_ordering_store)]
|
|
|
|
#[help]
|
|
|
|
pub struct AtomicOrderingStore;
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_atomic_ordering_fence)]
|
|
|
|
#[help]
|
|
|
|
pub struct AtomicOrderingFence;
|
2022-08-28 17:37:00 +00:00
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_atomic_ordering_invalid)]
|
|
|
|
#[help]
|
|
|
|
pub struct InvalidAtomicOrderingDiag {
|
|
|
|
pub method: Symbol,
|
|
|
|
#[label]
|
|
|
|
pub fail_order_arg_span: Span,
|
|
|
|
}
|
2022-09-04 19:46:35 +00:00
|
|
|
|
2022-10-04 23:39:02 +00:00
|
|
|
// unused.rs
|
2022-09-04 19:46:35 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unused_op)]
|
|
|
|
pub struct UnusedOp<'a> {
|
|
|
|
pub op: &'a str,
|
|
|
|
#[label]
|
|
|
|
pub label: Span,
|
2023-06-11 15:44:28 +00:00
|
|
|
#[subdiagnostic]
|
|
|
|
pub suggestion: UnusedOpSuggestion,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
pub enum UnusedOpSuggestion {
|
|
|
|
#[suggestion(
|
|
|
|
lint_suggestion,
|
|
|
|
style = "verbose",
|
|
|
|
code = "let _ = ",
|
|
|
|
applicability = "maybe-incorrect"
|
|
|
|
)]
|
|
|
|
NormalExpr {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
},
|
|
|
|
#[multipart_suggestion(lint_suggestion, style = "verbose", applicability = "maybe-incorrect")]
|
|
|
|
BlockTailExpr {
|
|
|
|
#[suggestion_part(code = "let _ = ")]
|
|
|
|
before_span: Span,
|
|
|
|
#[suggestion_part(code = ";")]
|
|
|
|
after_span: Span,
|
|
|
|
},
|
2022-09-04 19:46:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unused_result)]
|
|
|
|
pub struct UnusedResult<'a> {
|
|
|
|
pub ty: Ty<'a>,
|
|
|
|
}
|
|
|
|
|
2023-04-10 20:02:52 +00:00
|
|
|
// FIXME(davidtwco): this isn't properly translatable because of the
|
2022-09-04 19:46:35 +00:00
|
|
|
// pre/post strings
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unused_closure)]
|
|
|
|
#[note]
|
|
|
|
pub struct UnusedClosure<'a> {
|
|
|
|
pub count: usize,
|
|
|
|
pub pre: &'a str,
|
|
|
|
pub post: &'a str,
|
|
|
|
}
|
|
|
|
|
2023-04-10 20:02:52 +00:00
|
|
|
// FIXME(davidtwco): this isn't properly translatable because of the
|
2022-09-04 19:46:35 +00:00
|
|
|
// pre/post strings
|
|
|
|
#[derive(LintDiagnostic)]
|
2023-10-19 21:46:28 +00:00
|
|
|
#[diag(lint_unused_coroutine)]
|
2022-09-04 19:46:35 +00:00
|
|
|
#[note]
|
2023-10-19 16:06:43 +00:00
|
|
|
pub struct UnusedCoroutine<'a> {
|
2022-09-04 19:46:35 +00:00
|
|
|
pub count: usize,
|
|
|
|
pub pre: &'a str,
|
|
|
|
pub post: &'a str,
|
|
|
|
}
|
|
|
|
|
2023-04-10 20:02:52 +00:00
|
|
|
// FIXME(davidtwco): this isn't properly translatable because of the pre/post
|
2022-09-04 19:46:35 +00:00
|
|
|
// strings
|
|
|
|
pub struct UnusedDef<'a, 'b> {
|
|
|
|
pub pre: &'a str,
|
|
|
|
pub post: &'a str,
|
|
|
|
pub cx: &'a LateContext<'b>,
|
|
|
|
pub def_id: DefId,
|
|
|
|
pub note: Option<Symbol>,
|
2022-10-29 13:14:02 +00:00
|
|
|
pub suggestion: Option<UnusedDefSuggestion>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
2023-06-11 15:44:28 +00:00
|
|
|
|
|
|
|
pub enum UnusedDefSuggestion {
|
|
|
|
#[suggestion(
|
|
|
|
lint_suggestion,
|
|
|
|
style = "verbose",
|
|
|
|
code = "let _ = ",
|
|
|
|
applicability = "maybe-incorrect"
|
|
|
|
)]
|
|
|
|
NormalExpr {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
},
|
|
|
|
#[multipart_suggestion(lint_suggestion, style = "verbose", applicability = "maybe-incorrect")]
|
|
|
|
BlockTailExpr {
|
|
|
|
#[suggestion_part(code = "let _ = ")]
|
|
|
|
before_span: Span,
|
|
|
|
#[suggestion_part(code = ";")]
|
|
|
|
after_span: Span,
|
|
|
|
},
|
2022-09-04 19:46:35 +00:00
|
|
|
}
|
|
|
|
|
2022-11-11 00:32:30 +00:00
|
|
|
// Needed because of def_path_str
|
2024-03-08 01:03:51 +00:00
|
|
|
impl<'a> LintDiagnostic<'a, ()> for UnusedDef<'_, '_> {
|
2024-02-22 23:20:45 +00:00
|
|
|
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
|
2024-05-22 14:46:05 +00:00
|
|
|
diag.primary_message(fluent::lint_unused_def);
|
2023-12-23 22:08:41 +00:00
|
|
|
diag.arg("pre", self.pre);
|
|
|
|
diag.arg("post", self.post);
|
|
|
|
diag.arg("def", self.cx.tcx.def_path_str(self.def_id));
|
2022-09-04 19:46:35 +00:00
|
|
|
// check for #[must_use = "..."]
|
|
|
|
if let Some(note) = self.note {
|
Use `Cow` in `{D,Subd}iagnosticMessage`.
Each of `{D,Subd}iagnosticMessage::{Str,Eager}` has a comment:
```
// FIXME(davidtwco): can a `Cow<'static, str>` be used here?
```
This commit answers that question in the affirmative. It's not the most
compelling change ever, but it might be worth merging.
This requires changing the `impl<'a> From<&'a str>` impls to `impl
From<&'static str>`, which involves a bunch of knock-on changes that
require/result in call sites being a little more precise about exactly
what kind of string they use to create errors, and not just `&str`. This
will result in fewer unnecessary allocations, though this will not have
any notable perf effects given that these are error paths.
Note that I was lazy within Clippy, using `to_string` in a few places to
preserve the existing string imprecision. I could have used `impl
Into<{D,Subd}iagnosticMessage>` in various places as is done in the
compiler, but that would have required changes to *many* call sites
(mostly changing `&format("...")` to `format!("...")`) which didn't seem
worthwhile.
2023-05-04 00:55:21 +00:00
|
|
|
diag.note(note.to_string());
|
2022-09-04 19:46:35 +00:00
|
|
|
}
|
2022-10-29 13:14:02 +00:00
|
|
|
if let Some(sugg) = self.suggestion {
|
2024-02-14 14:17:27 +00:00
|
|
|
diag.subdiagnostic(diag.dcx, sugg);
|
2022-10-29 13:14:02 +00:00
|
|
|
}
|
2022-10-04 21:54:47 +00:00
|
|
|
}
|
2022-09-04 19:46:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_path_statement_drop)]
|
|
|
|
pub struct PathStatementDrop {
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub sub: PathStatementDropSub,
|
|
|
|
}
|
|
|
|
|
2022-09-22 00:47:24 +00:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-09-04 19:46:35 +00:00
|
|
|
pub enum PathStatementDropSub {
|
2022-10-13 09:13:02 +00:00
|
|
|
#[suggestion(lint_suggestion, code = "drop({snippet});", applicability = "machine-applicable")]
|
2022-09-04 19:46:35 +00:00
|
|
|
Suggestion {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
snippet: String,
|
|
|
|
},
|
2022-10-13 09:13:02 +00:00
|
|
|
#[help(lint_help)]
|
2022-09-04 19:46:35 +00:00
|
|
|
Help {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_path_statement_no_effect)]
|
|
|
|
pub struct PathStatementNoEffect;
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unused_delim)]
|
|
|
|
pub struct UnusedDelim<'a> {
|
|
|
|
pub delim: &'static str,
|
|
|
|
pub item: &'a str,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub suggestion: Option<UnusedDelimSuggestion>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
2022-10-13 09:13:02 +00:00
|
|
|
#[multipart_suggestion(lint_suggestion, applicability = "machine-applicable")]
|
2022-09-04 19:46:35 +00:00
|
|
|
pub struct UnusedDelimSuggestion {
|
|
|
|
#[suggestion_part(code = "{start_replace}")]
|
|
|
|
pub start_span: Span,
|
|
|
|
pub start_replace: &'static str,
|
|
|
|
#[suggestion_part(code = "{end_replace}")]
|
|
|
|
pub end_span: Span,
|
|
|
|
pub end_replace: &'static str,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unused_import_braces)]
|
|
|
|
pub struct UnusedImportBracesDiag {
|
|
|
|
pub node: Symbol,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unused_allocation)]
|
|
|
|
pub struct UnusedAllocationDiag;
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unused_allocation_mut)]
|
|
|
|
pub struct UnusedAllocationMutDiag;
|
2023-09-26 20:20:21 +00:00
|
|
|
|
|
|
|
pub struct AsyncFnInTraitDiag {
|
|
|
|
pub sugg: Option<Vec<(Span, String)>>,
|
|
|
|
}
|
|
|
|
|
2024-03-08 01:03:51 +00:00
|
|
|
impl<'a> LintDiagnostic<'a, ()> for AsyncFnInTraitDiag {
|
2024-02-22 23:20:45 +00:00
|
|
|
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
|
2024-05-22 14:46:05 +00:00
|
|
|
diag.primary_message(fluent::lint_async_fn_in_trait);
|
2023-09-26 20:20:21 +00:00
|
|
|
diag.note(fluent::lint_note);
|
|
|
|
if let Some(sugg) = self.sugg {
|
|
|
|
diag.multipart_suggestion(fluent::lint_suggestion, sugg, Applicability::MaybeIncorrect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-06-13 16:19:09 +00:00
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unit_bindings)]
|
|
|
|
pub struct UnitBindingsDiag {
|
|
|
|
#[label]
|
|
|
|
pub label: Span,
|
|
|
|
}
|
2024-04-16 16:23:47 +00:00
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_builtin_asm_labels)]
|
|
|
|
#[help]
|
|
|
|
#[note]
|
|
|
|
pub struct BuiltinNamedAsmLabel;
|
2024-04-23 16:18:24 +00:00
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
2024-05-22 11:27:35 +00:00
|
|
|
pub enum UnexpectedCfgCargoHelp {
|
|
|
|
#[help(lint_unexpected_cfg_add_cargo_feature)]
|
|
|
|
#[help(lint_unexpected_cfg_add_cargo_toml_lint_cfg)]
|
|
|
|
LintCfg { cargo_toml_lint_cfg: String },
|
|
|
|
#[help(lint_unexpected_cfg_add_cargo_feature)]
|
|
|
|
#[help(lint_unexpected_cfg_add_cargo_toml_lint_cfg)]
|
|
|
|
#[help(lint_unexpected_cfg_add_build_rs_println)]
|
|
|
|
LintCfgAndBuildRs { cargo_toml_lint_cfg: String, build_rs_println: String },
|
2024-04-23 16:18:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl UnexpectedCfgCargoHelp {
|
2024-05-22 11:27:35 +00:00
|
|
|
fn cargo_toml_lint_cfg(unescaped: &str) -> String {
|
|
|
|
format!(
|
|
|
|
"\n [lints.rust]\n unexpected_cfgs = {{ level = \"warn\", check-cfg = ['{unescaped}'] }}"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn lint_cfg(unescaped: &str) -> Self {
|
|
|
|
UnexpectedCfgCargoHelp::LintCfg {
|
|
|
|
cargo_toml_lint_cfg: Self::cargo_toml_lint_cfg(unescaped),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn lint_cfg_and_build_rs(unescaped: &str, escaped: &str) -> Self {
|
|
|
|
UnexpectedCfgCargoHelp::LintCfgAndBuildRs {
|
|
|
|
cargo_toml_lint_cfg: Self::cargo_toml_lint_cfg(unescaped),
|
|
|
|
build_rs_println: format!("println!(\"cargo::rustc-check-cfg={escaped}\");"),
|
2024-04-23 16:18:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
#[help(lint_unexpected_cfg_add_cmdline_arg)]
|
|
|
|
pub struct UnexpectedCfgRustcHelp {
|
|
|
|
pub cmdline_arg: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl UnexpectedCfgRustcHelp {
|
|
|
|
pub fn new(unescaped: &str) -> Self {
|
|
|
|
Self { cmdline_arg: format!("--check-cfg={unescaped}") }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-15 18:07:22 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unexpected_cfg_name)]
|
|
|
|
pub struct UnexpectedCfgName {
|
2024-04-23 16:18:24 +00:00
|
|
|
#[subdiagnostic]
|
|
|
|
pub code_sugg: unexpected_cfg_name::CodeSuggestion,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub invocation_help: unexpected_cfg_name::InvocationHelp,
|
2024-04-15 18:07:22 +00:00
|
|
|
|
|
|
|
pub name: Symbol,
|
2024-04-23 16:18:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub mod unexpected_cfg_name {
|
|
|
|
use rustc_errors::DiagSymbolList;
|
|
|
|
use rustc_macros::Subdiagnostic;
|
|
|
|
use rustc_span::{Span, Symbol};
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
pub enum CodeSuggestion {
|
|
|
|
#[help(lint_unexpected_cfg_define_features)]
|
|
|
|
DefineFeatures,
|
|
|
|
#[suggestion(
|
|
|
|
lint_unexpected_cfg_name_similar_name_value,
|
|
|
|
applicability = "maybe-incorrect",
|
|
|
|
code = "{code}"
|
|
|
|
)]
|
|
|
|
SimilarNameAndValue {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
code: String,
|
|
|
|
},
|
|
|
|
#[suggestion(
|
|
|
|
lint_unexpected_cfg_name_similar_name_no_value,
|
|
|
|
applicability = "maybe-incorrect",
|
|
|
|
code = "{code}"
|
|
|
|
)]
|
|
|
|
SimilarNameNoValue {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
code: String,
|
|
|
|
},
|
|
|
|
#[suggestion(
|
|
|
|
lint_unexpected_cfg_name_similar_name_different_values,
|
|
|
|
applicability = "maybe-incorrect",
|
|
|
|
code = "{code}"
|
|
|
|
)]
|
|
|
|
SimilarNameDifferentValues {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
code: String,
|
|
|
|
#[subdiagnostic]
|
|
|
|
expected: Option<ExpectedValues>,
|
|
|
|
},
|
|
|
|
#[suggestion(
|
|
|
|
lint_unexpected_cfg_name_similar_name,
|
|
|
|
applicability = "maybe-incorrect",
|
|
|
|
code = "{code}"
|
|
|
|
)]
|
|
|
|
SimilarName {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
code: String,
|
|
|
|
#[subdiagnostic]
|
|
|
|
expected: Option<ExpectedValues>,
|
|
|
|
},
|
|
|
|
SimilarValues {
|
|
|
|
#[subdiagnostic]
|
|
|
|
with_similar_values: Vec<FoundWithSimilarValue>,
|
|
|
|
#[subdiagnostic]
|
|
|
|
expected_names: Option<ExpectedNames>,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
#[help(lint_unexpected_cfg_name_expected_values)]
|
|
|
|
pub struct ExpectedValues {
|
|
|
|
pub best_match: Symbol,
|
|
|
|
pub possibilities: DiagSymbolList,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
#[suggestion(
|
|
|
|
lint_unexpected_cfg_name_with_similar_value,
|
|
|
|
applicability = "maybe-incorrect",
|
|
|
|
code = "{code}"
|
|
|
|
)]
|
|
|
|
pub struct FoundWithSimilarValue {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub code: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
#[help_once(lint_unexpected_cfg_name_expected_names)]
|
|
|
|
pub struct ExpectedNames {
|
|
|
|
pub possibilities: DiagSymbolList,
|
|
|
|
pub and_more: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
pub enum InvocationHelp {
|
|
|
|
#[note(lint_unexpected_cfg_doc_cargo)]
|
|
|
|
Cargo {
|
|
|
|
#[subdiagnostic]
|
|
|
|
sub: Option<super::UnexpectedCfgCargoHelp>,
|
|
|
|
},
|
|
|
|
#[note(lint_unexpected_cfg_doc_rustc)]
|
|
|
|
Rustc(#[subdiagnostic] super::UnexpectedCfgRustcHelp),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-15 18:07:22 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unexpected_cfg_value)]
|
|
|
|
pub struct UnexpectedCfgValue {
|
2024-04-23 16:18:24 +00:00
|
|
|
#[subdiagnostic]
|
|
|
|
pub code_sugg: unexpected_cfg_value::CodeSuggestion,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub invocation_help: unexpected_cfg_value::InvocationHelp,
|
2024-04-15 18:07:22 +00:00
|
|
|
|
|
|
|
pub has_value: bool,
|
|
|
|
pub value: String,
|
2024-04-23 16:18:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub mod unexpected_cfg_value {
|
|
|
|
use rustc_errors::DiagSymbolList;
|
|
|
|
use rustc_macros::Subdiagnostic;
|
|
|
|
use rustc_span::{Span, Symbol};
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
pub enum CodeSuggestion {
|
|
|
|
ChangeValue {
|
|
|
|
#[subdiagnostic]
|
|
|
|
expected_values: ExpectedValues,
|
|
|
|
#[subdiagnostic]
|
|
|
|
suggestion: Option<ChangeValueSuggestion>,
|
|
|
|
},
|
|
|
|
#[note(lint_unexpected_cfg_value_no_expected_value)]
|
|
|
|
RemoveValue {
|
|
|
|
#[subdiagnostic]
|
|
|
|
suggestion: Option<RemoveValueSuggestion>,
|
|
|
|
|
|
|
|
name: Symbol,
|
|
|
|
},
|
|
|
|
#[note(lint_unexpected_cfg_value_no_expected_values)]
|
|
|
|
RemoveCondition {
|
|
|
|
#[subdiagnostic]
|
|
|
|
suggestion: RemoveConditionSuggestion,
|
|
|
|
|
|
|
|
name: Symbol,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
pub enum ChangeValueSuggestion {
|
|
|
|
#[suggestion(
|
|
|
|
lint_unexpected_cfg_value_similar_name,
|
|
|
|
code = r#""{best_match}""#,
|
|
|
|
applicability = "maybe-incorrect"
|
|
|
|
)]
|
|
|
|
SimilarName {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
best_match: Symbol,
|
|
|
|
},
|
|
|
|
#[suggestion(
|
|
|
|
lint_unexpected_cfg_value_specify_value,
|
|
|
|
code = r#" = "{first_possibility}""#,
|
|
|
|
applicability = "maybe-incorrect"
|
|
|
|
)]
|
|
|
|
SpecifyValue {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
first_possibility: Symbol,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
#[suggestion(
|
|
|
|
lint_unexpected_cfg_value_remove_value,
|
|
|
|
code = "",
|
|
|
|
applicability = "maybe-incorrect"
|
|
|
|
)]
|
|
|
|
pub struct RemoveValueSuggestion {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
#[suggestion(
|
|
|
|
lint_unexpected_cfg_value_remove_condition,
|
|
|
|
code = "",
|
|
|
|
applicability = "maybe-incorrect"
|
|
|
|
)]
|
|
|
|
pub struct RemoveConditionSuggestion {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
#[note(lint_unexpected_cfg_value_expected_values)]
|
|
|
|
pub struct ExpectedValues {
|
|
|
|
pub name: Symbol,
|
|
|
|
pub have_none_possibility: bool,
|
|
|
|
pub possibilities: DiagSymbolList,
|
|
|
|
pub and_more: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
pub enum InvocationHelp {
|
|
|
|
#[note(lint_unexpected_cfg_doc_cargo)]
|
|
|
|
Cargo(#[subdiagnostic] Option<CargoHelp>),
|
|
|
|
#[note(lint_unexpected_cfg_doc_rustc)]
|
|
|
|
Rustc(#[subdiagnostic] Option<super::UnexpectedCfgRustcHelp>),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
pub enum CargoHelp {
|
|
|
|
#[help(lint_unexpected_cfg_value_add_feature)]
|
|
|
|
AddFeature {
|
|
|
|
value: Symbol,
|
|
|
|
},
|
|
|
|
#[help(lint_unexpected_cfg_define_features)]
|
|
|
|
DefineFeatures,
|
|
|
|
Other(#[subdiagnostic] super::UnexpectedCfgCargoHelp),
|
|
|
|
}
|
|
|
|
}
|
2024-04-15 18:07:22 +00:00
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_macro_use_deprecated)]
|
2024-06-03 05:17:19 +00:00
|
|
|
#[help]
|
2024-04-15 18:07:22 +00:00
|
|
|
pub struct MacroUseDeprecated;
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unused_macro_use)]
|
|
|
|
pub struct UnusedMacroUse;
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
2024-05-17 12:43:59 +00:00
|
|
|
#[diag(lint_private_extern_crate_reexport, code = E0365)]
|
2024-04-15 18:07:22 +00:00
|
|
|
pub struct PrivateExternCrateReexport {
|
|
|
|
pub ident: Ident,
|
2024-06-03 05:17:19 +00:00
|
|
|
#[suggestion(code = "pub ", style = "verbose", applicability = "maybe-incorrect")]
|
|
|
|
pub sugg: Span,
|
2024-04-15 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unused_label)]
|
|
|
|
pub struct UnusedLabel;
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_macro_is_private)]
|
|
|
|
pub struct MacroIsPrivate {
|
|
|
|
pub ident: Ident,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unused_macro_definition)]
|
|
|
|
pub struct UnusedMacroDefinition {
|
|
|
|
pub name: Symbol,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_macro_rule_never_used)]
|
|
|
|
pub struct MacroRuleNeverUsed {
|
|
|
|
pub n: usize,
|
|
|
|
pub name: Symbol,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct UnstableFeature {
|
|
|
|
pub msg: DiagMessage,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> LintDiagnostic<'a, ()> for UnstableFeature {
|
2024-05-22 14:46:05 +00:00
|
|
|
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
|
|
|
|
diag.primary_message(self.msg);
|
2024-04-15 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_avoid_intel_syntax)]
|
|
|
|
pub struct AvoidIntelSyntax;
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_avoid_att_syntax)]
|
|
|
|
pub struct AvoidAttSyntax;
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_incomplete_include)]
|
|
|
|
pub struct IncompleteInclude;
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unnameable_test_items)]
|
|
|
|
pub struct UnnameableTestItems;
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_duplicate_macro_attribute)]
|
|
|
|
pub struct DuplicateMacroAttribute;
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_cfg_attr_no_attributes)]
|
|
|
|
pub struct CfgAttrNoAttributes;
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_crate_type_in_cfg_attr_deprecated)]
|
|
|
|
pub struct CrateTypeInCfgAttr;
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_crate_name_in_cfg_attr_deprecated)]
|
|
|
|
pub struct CrateNameInCfgAttr;
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_missing_fragment_specifier)]
|
|
|
|
pub struct MissingFragmentSpecifier;
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_metavariable_still_repeating)]
|
|
|
|
pub struct MetaVariableStillRepeating {
|
|
|
|
pub name: MacroRulesNormalizedIdent,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_metavariable_wrong_operator)]
|
|
|
|
pub struct MetaVariableWrongOperator;
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_duplicate_matcher_binding)]
|
|
|
|
pub struct DuplicateMatcherBinding;
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unknown_macro_variable)]
|
|
|
|
pub struct UnknownMacroVariable {
|
|
|
|
pub name: MacroRulesNormalizedIdent,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unused_crate_dependency)]
|
2024-06-03 05:17:19 +00:00
|
|
|
#[help]
|
2024-04-15 18:07:22 +00:00
|
|
|
pub struct UnusedCrateDependency {
|
|
|
|
pub extern_crate: Symbol,
|
|
|
|
pub local_crate: Symbol,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_wasm_c_abi)]
|
|
|
|
pub struct WasmCAbi;
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_ill_formed_attribute_input)]
|
|
|
|
pub struct IllFormedAttributeInput {
|
|
|
|
pub num_suggestions: usize,
|
|
|
|
pub suggestions: DiagArgValue,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
pub enum InnerAttributeUnstable {
|
|
|
|
#[diag(lint_inner_macro_attribute_unstable)]
|
|
|
|
InnerMacroAttribute,
|
|
|
|
#[diag(lint_custom_inner_attribute_unstable)]
|
|
|
|
CustomInnerAttribute,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unknown_diagnostic_attribute)]
|
|
|
|
pub 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 struct UnknownDiagnosticAttributeTypoSugg {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub typo_name: Symbol,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unicode_text_flow)]
|
|
|
|
#[note]
|
|
|
|
pub struct UnicodeTextFlow {
|
|
|
|
#[label]
|
|
|
|
pub comment_span: Span,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub characters: Vec<UnicodeCharNoteSub>,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub suggestions: Option<UnicodeTextFlowSuggestion>,
|
|
|
|
|
|
|
|
pub num_codepoints: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
#[label(lint_label_comment_char)]
|
|
|
|
pub struct UnicodeCharNoteSub {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub c_debug: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
#[multipart_suggestion(lint_suggestion, applicability = "machine-applicable", style = "hidden")]
|
|
|
|
pub struct UnicodeTextFlowSuggestion {
|
|
|
|
#[suggestion_part(code = "")]
|
|
|
|
pub spans: Vec<Span>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_abs_path_with_module)]
|
|
|
|
pub struct AbsPathWithModule {
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub sugg: AbsPathWithModuleSugg,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
#[suggestion(lint_suggestion, code = "{replacement}")]
|
|
|
|
pub struct AbsPathWithModuleSugg {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
#[applicability]
|
|
|
|
pub applicability: Applicability,
|
|
|
|
pub replacement: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_proc_macro_derive_resolution_fallback)]
|
|
|
|
pub struct ProcMacroDeriveResolutionFallback {
|
|
|
|
#[label]
|
|
|
|
pub span: Span,
|
|
|
|
pub ns: Namespace,
|
|
|
|
pub ident: Ident,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_macro_expanded_macro_exports_accessed_by_absolute_paths)]
|
|
|
|
pub struct MacroExpandedMacroExportsAccessedByAbsolutePaths {
|
|
|
|
#[note]
|
|
|
|
pub definition: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_hidden_lifetime_parameters)]
|
|
|
|
pub struct ElidedLifetimesInPaths {
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub subdiag: ElidedLifetimeInPathSubdiag,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_invalid_crate_type_value)]
|
|
|
|
pub struct UnknownCrateTypes {
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub sugg: Option<UnknownCrateTypesSub>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
#[suggestion(lint_suggestion, code = r#""{candidate}""#, applicability = "maybe-incorrect")]
|
|
|
|
pub struct UnknownCrateTypesSub {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub candidate: Symbol,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unused_imports)]
|
|
|
|
pub struct UnusedImports {
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub sugg: UnusedImportsSugg,
|
|
|
|
#[help]
|
|
|
|
pub test_module_span: Option<Span>,
|
|
|
|
|
|
|
|
pub span_snippets: DiagArgValue,
|
|
|
|
pub num_snippets: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
pub enum UnusedImportsSugg {
|
|
|
|
#[suggestion(
|
|
|
|
lint_suggestion_remove_whole_use,
|
|
|
|
applicability = "machine-applicable",
|
|
|
|
code = "",
|
|
|
|
style = "tool-only"
|
|
|
|
)]
|
|
|
|
RemoveWholeUse {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
},
|
|
|
|
#[multipart_suggestion(
|
|
|
|
lint_suggestion_remove_imports,
|
|
|
|
applicability = "machine-applicable",
|
|
|
|
style = "tool-only"
|
|
|
|
)]
|
|
|
|
RemoveImports {
|
|
|
|
#[suggestion_part(code = "")]
|
|
|
|
remove_spans: Vec<Span>,
|
|
|
|
num_to_remove: usize,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_redundant_import)]
|
|
|
|
pub struct RedundantImport {
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub subs: Vec<RedundantImportSub>,
|
|
|
|
|
|
|
|
pub ident: Ident,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
pub enum RedundantImportSub {
|
|
|
|
#[label(lint_label_imported_here)]
|
|
|
|
ImportedHere(#[primary_span] Span),
|
|
|
|
#[label(lint_label_defined_here)]
|
|
|
|
DefinedHere(#[primary_span] Span),
|
|
|
|
#[label(lint_label_imported_prelude)]
|
|
|
|
ImportedPrelude(#[primary_span] Span),
|
|
|
|
#[label(lint_label_defined_prelude)]
|
|
|
|
DefinedPrelude(#[primary_span] Span),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unused_doc_comment)]
|
|
|
|
#[help]
|
|
|
|
pub struct UnusedDocComment {
|
|
|
|
#[label]
|
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
pub enum PatternsInFnsWithoutBody {
|
|
|
|
#[diag(lint_pattern_in_foreign)]
|
|
|
|
Foreign {
|
|
|
|
#[subdiagnostic]
|
|
|
|
sub: PatternsInFnsWithoutBodySub,
|
|
|
|
},
|
|
|
|
#[diag(lint_pattern_in_bodiless)]
|
|
|
|
Bodiless {
|
|
|
|
#[subdiagnostic]
|
|
|
|
sub: PatternsInFnsWithoutBodySub,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
#[suggestion(lint_remove_mut_from_pattern, code = "{ident}", applicability = "machine-applicable")]
|
|
|
|
pub struct PatternsInFnsWithoutBodySub {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
|
|
|
|
pub ident: Ident,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_extern_without_abi)]
|
|
|
|
#[help]
|
|
|
|
pub struct MissingAbi {
|
|
|
|
#[label]
|
|
|
|
pub span: Span,
|
|
|
|
|
|
|
|
pub default_abi: &'static str,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_legacy_derive_helpers)]
|
|
|
|
pub struct LegacyDeriveHelpers {
|
|
|
|
#[label]
|
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_or_patterns_back_compat)]
|
|
|
|
pub struct OrPatternsBackCompat {
|
|
|
|
#[suggestion(code = "{suggestion}", applicability = "machine-applicable")]
|
|
|
|
pub span: Span,
|
|
|
|
pub suggestion: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_reserved_prefix)]
|
|
|
|
pub struct ReservedPrefix {
|
|
|
|
#[label]
|
|
|
|
pub label: Span,
|
|
|
|
#[suggestion(code = " ", applicability = "machine-applicable")]
|
|
|
|
pub suggestion: Span,
|
|
|
|
|
|
|
|
pub prefix: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unused_builtin_attribute)]
|
|
|
|
pub struct UnusedBuiltinAttribute {
|
|
|
|
#[note]
|
|
|
|
pub invoc_span: Span,
|
|
|
|
|
|
|
|
pub attr_name: Symbol,
|
|
|
|
pub macro_name: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_trailing_semi_macro)]
|
|
|
|
pub struct TrailingMacro {
|
|
|
|
#[note(lint_note1)]
|
|
|
|
#[note(lint_note2)]
|
|
|
|
pub is_trailing: bool,
|
|
|
|
|
|
|
|
pub name: Ident,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_break_with_label_and_loop)]
|
|
|
|
pub struct BreakWithLabelAndLoop {
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub sub: BreakWithLabelAndLoopSub,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
#[multipart_suggestion(lint_suggestion, applicability = "machine-applicable")]
|
|
|
|
pub struct BreakWithLabelAndLoopSub {
|
|
|
|
#[suggestion_part(code = "(")]
|
|
|
|
pub left: Span,
|
|
|
|
#[suggestion_part(code = ")")]
|
|
|
|
pub right: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_deprecated_where_clause_location)]
|
|
|
|
#[note]
|
|
|
|
pub struct DeprecatedWhereClauseLocation {
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub suggestion: DeprecatedWhereClauseLocationSugg,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
pub enum DeprecatedWhereClauseLocationSugg {
|
|
|
|
#[multipart_suggestion(lint_suggestion_move_to_end, applicability = "machine-applicable")]
|
|
|
|
MoveToEnd {
|
|
|
|
#[suggestion_part(code = "")]
|
|
|
|
left: Span,
|
|
|
|
#[suggestion_part(code = "{sugg}")]
|
|
|
|
right: Span,
|
|
|
|
|
|
|
|
sugg: String,
|
|
|
|
},
|
|
|
|
#[suggestion(lint_suggestion_remove_where, code = "", applicability = "machine-applicable")]
|
|
|
|
RemoveWhere {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-05-21 15:27:21 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_missing_unsafe_on_extern)]
|
2024-06-04 01:27:57 +00:00
|
|
|
pub struct MissingUnsafeOnExtern {
|
|
|
|
#[suggestion(code = "unsafe ", applicability = "machine-applicable")]
|
|
|
|
pub suggestion: Span,
|
|
|
|
}
|
2024-05-21 15:27:21 +00:00
|
|
|
|
2024-04-15 18:07:22 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_single_use_lifetime)]
|
|
|
|
pub struct SingleUseLifetime {
|
|
|
|
#[label(lint_label_param)]
|
|
|
|
pub param_span: Span,
|
|
|
|
#[label(lint_label_use)]
|
|
|
|
pub use_span: Span,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub suggestion: Option<SingleUseLifetimeSugg>,
|
|
|
|
|
|
|
|
pub ident: Ident,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
#[multipart_suggestion(lint_suggestion, applicability = "machine-applicable")]
|
|
|
|
pub struct SingleUseLifetimeSugg {
|
|
|
|
#[suggestion_part(code = "")]
|
|
|
|
pub deletion_span: Option<Span>,
|
|
|
|
#[suggestion_part(code = "{replace_lt}")]
|
|
|
|
pub use_span: Span,
|
|
|
|
|
|
|
|
pub replace_lt: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unused_lifetime)]
|
|
|
|
pub struct UnusedLifetime {
|
|
|
|
#[suggestion(code = "", applicability = "machine-applicable")]
|
|
|
|
pub deletion_span: Option<Span>,
|
|
|
|
|
|
|
|
pub ident: Ident,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_named_argument_used_positionally)]
|
|
|
|
pub struct NamedArgumentUsedPositionally {
|
|
|
|
#[label(lint_label_named_arg)]
|
|
|
|
pub named_arg_sp: Span,
|
|
|
|
#[label(lint_label_position_arg)]
|
|
|
|
pub position_label_sp: Option<Span>,
|
|
|
|
#[suggestion(style = "verbose", code = "{name}", applicability = "maybe-incorrect")]
|
|
|
|
pub suggestion: Option<Span>,
|
|
|
|
|
|
|
|
pub name: String,
|
|
|
|
pub named_arg_name: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_byte_slice_in_packed_struct_with_derive)]
|
|
|
|
#[help]
|
|
|
|
pub struct ByteSliceInPackedStructWithDerive {
|
|
|
|
// FIXME: make this translatable
|
|
|
|
pub ty: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unused_extern_crate)]
|
|
|
|
pub struct UnusedExternCrate {
|
|
|
|
#[suggestion(code = "", applicability = "machine-applicable")]
|
|
|
|
pub removal_span: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_extern_crate_not_idiomatic)]
|
|
|
|
pub struct ExternCrateNotIdiomatic {
|
|
|
|
#[suggestion(style = "verbose", code = "{code}", applicability = "machine-applicable")]
|
|
|
|
pub span: Span,
|
|
|
|
|
|
|
|
pub code: &'static str,
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: make this translatable
|
|
|
|
pub struct AmbiguousGlobImports {
|
|
|
|
pub ambiguity: AmbiguityErrorDiag,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, G: EmissionGuarantee> LintDiagnostic<'a, G> for AmbiguousGlobImports {
|
|
|
|
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, G>) {
|
2024-05-22 14:46:05 +00:00
|
|
|
diag.primary_message(self.ambiguity.msg.clone());
|
2024-04-15 18:07:22 +00:00
|
|
|
rustc_errors::report_ambiguity_error(diag, self.ambiguity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_ambiguous_glob_reexport)]
|
|
|
|
pub struct AmbiguousGlobReexports {
|
|
|
|
#[label(lint_label_first_reexport)]
|
|
|
|
pub first_reexport: Span,
|
|
|
|
#[label(lint_label_duplicate_reexport)]
|
|
|
|
pub duplicate_reexport: Span,
|
|
|
|
|
|
|
|
pub name: String,
|
|
|
|
// FIXME: make this translatable
|
|
|
|
pub namespace: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_hidden_glob_reexport)]
|
|
|
|
pub struct HiddenGlobReexports {
|
|
|
|
#[note(lint_note_glob_reexport)]
|
|
|
|
pub glob_reexport: Span,
|
|
|
|
#[note(lint_note_private_item)]
|
|
|
|
pub private_item: Span,
|
|
|
|
|
|
|
|
pub name: String,
|
|
|
|
// FIXME: make this translatable
|
|
|
|
pub namespace: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unnecessary_qualification)]
|
|
|
|
pub struct UnusedQualifications {
|
|
|
|
#[suggestion(style = "verbose", code = "", applicability = "machine-applicable")]
|
|
|
|
pub removal_span: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_associated_const_elided_lifetime)]
|
|
|
|
pub struct AssociatedConstElidedLifetime {
|
|
|
|
#[suggestion(style = "verbose", code = "{code}", applicability = "machine-applicable")]
|
|
|
|
pub span: Span,
|
|
|
|
|
|
|
|
pub code: &'static str,
|
|
|
|
pub elided: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_redundant_import_visibility)]
|
|
|
|
pub struct RedundantImportVisibility {
|
|
|
|
#[note]
|
|
|
|
pub span: Span,
|
|
|
|
#[help]
|
|
|
|
pub help: (),
|
|
|
|
|
|
|
|
pub import_vis: String,
|
|
|
|
pub max_vis: String,
|
|
|
|
}
|