2022-11-13 10:42:49 -05:00
|
|
|
#![allow(rustc::untranslatable_diagnostic)]
|
|
|
|
#![allow(rustc::diagnostic_outside_of_impl)]
|
2022-10-22 21:50:44 -04:00
|
|
|
use std::num::NonZeroU32;
|
|
|
|
|
2022-10-13 10:13:02 +01:00
|
|
|
use crate::fluent_generated as fluent;
|
2022-11-11 22:39:37 -05:00
|
|
|
use rustc_errors::{
|
2022-10-13 10:13:02 +01:00
|
|
|
AddToDiagnostic, Applicability, DecorateLint, DiagnosticMessage, DiagnosticStyledString,
|
|
|
|
SuggestionStyle,
|
2022-11-11 22:39:37 -05:00
|
|
|
};
|
2022-09-04 15:46:35 -04:00
|
|
|
use rustc_hir::def_id::DefId;
|
2022-09-21 20:47:24 -04:00
|
|
|
use rustc_macros::{LintDiagnostic, Subdiagnostic};
|
2023-02-13 15:38:23 +01:00
|
|
|
use rustc_middle::ty::{
|
|
|
|
inhabitedness::InhabitedPredicate, PolyExistentialTraitRef, Predicate, Ty, TyCtxt,
|
|
|
|
};
|
2022-11-13 09:46:31 -05:00
|
|
|
use rustc_session::parse::ParseSess;
|
|
|
|
use rustc_span::{edition::Edition, sym, symbol::Ident, Span, Symbol};
|
2022-08-28 19:07:58 -04:00
|
|
|
|
2022-11-13 09:46:31 -05:00
|
|
|
use crate::{
|
|
|
|
builtin::InitError, builtin::TypeAliasBounds, errors::OverruledAttributeSub, LateContext,
|
|
|
|
};
|
2022-09-04 15:46:35 -04:00
|
|
|
|
2022-10-04 19:39:02 -04:00
|
|
|
// array_into_iter.rs
|
2022-09-18 10:03:35 -04:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_array_into_iter)]
|
|
|
|
pub struct ArrayIntoIterDiag<'a> {
|
|
|
|
pub target: &'a str,
|
2022-10-13 10:13:02 +01:00
|
|
|
#[suggestion(lint_use_iter_suggestion, code = "iter", applicability = "machine-applicable")]
|
2022-09-18 10:03:35 -04:00
|
|
|
pub suggestion: Span,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub sub: Option<ArrayIntoIterDiagSub>,
|
|
|
|
}
|
|
|
|
|
2022-09-21 20:47:24 -04:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-09-18 10:03:35 -04:00
|
|
|
pub enum ArrayIntoIterDiagSub {
|
2022-10-13 10:13:02 +01:00
|
|
|
#[suggestion(lint_remove_into_iter_suggestion, code = "", applicability = "maybe-incorrect")]
|
2022-09-18 10:03:35 -04:00
|
|
|
RemoveIntoIter {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
},
|
2022-10-13 10:13:02 +01:00
|
|
|
#[multipart_suggestion(
|
|
|
|
lint_use_explicit_into_iter_suggestion,
|
|
|
|
applicability = "maybe-incorrect"
|
|
|
|
)]
|
2022-09-18 10:03:35 -04:00
|
|
|
UseExplicitIntoIter {
|
|
|
|
#[suggestion_part(code = "IntoIterator::into_iter(")]
|
|
|
|
start_span: Span,
|
|
|
|
#[suggestion_part(code = ")")]
|
|
|
|
end_span: Span,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-10-22 21:50:44 -04: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-12 20:18:55 -05: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,
|
|
|
|
}
|
2022-10-22 21:50:44 -04: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-10 19:32:30 -05:00
|
|
|
// Needed for def_path_str
|
2022-10-22 21:50:44 -04:00
|
|
|
impl<'a> DecorateLint<'a, ()> for BuiltinMissingDebugImpl<'_> {
|
|
|
|
fn decorate_lint<'b>(
|
|
|
|
self,
|
|
|
|
diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
|
|
|
|
) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
|
|
|
|
diag.set_arg("debug", self.tcx.def_path_str(self.def_id));
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
|
|
|
|
fn msg(&self) -> DiagnosticMessage {
|
|
|
|
fluent::lint_builtin_missing_debug_impl
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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 09:46:31 -05: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 10:13:02 +01:00
|
|
|
#[suggestion(lint_msg_suggestion, code = "", applicability = "machine-applicable")]
|
2022-11-13 09:46:31 -05:00
|
|
|
Msg {
|
|
|
|
#[primary_span]
|
|
|
|
suggestion: Span,
|
|
|
|
msg: &'a str,
|
|
|
|
},
|
2022-10-13 10:13:02 +01:00
|
|
|
#[suggestion(lint_default_suggestion, code = "", applicability = "machine-applicable")]
|
2022-11-13 09:46:31 -05:00
|
|
|
Default {
|
|
|
|
#[primary_span]
|
|
|
|
suggestion: Span,
|
|
|
|
},
|
|
|
|
}
|
2022-10-22 21:50:44 -04: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 10:13:02 +01:00
|
|
|
#[help(lint_plain_help)]
|
2022-10-22 21:50:44 -04:00
|
|
|
PlainHelp,
|
2022-10-13 10:13:02 +01:00
|
|
|
#[help(lint_block_help)]
|
2022-10-22 21:50:44 -04: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 09:46:31 -05:00
|
|
|
// lint_ungated_async_fn_track_caller
|
|
|
|
pub struct BuiltinUngatedAsyncFnTrackCaller<'a> {
|
|
|
|
pub label: Span,
|
|
|
|
pub parse_sess: &'a ParseSess,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> DecorateLint<'a, ()> for BuiltinUngatedAsyncFnTrackCaller<'_> {
|
|
|
|
fn decorate_lint<'b>(
|
|
|
|
self,
|
|
|
|
diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
|
|
|
|
) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
|
2022-10-13 10:13:02 +01:00
|
|
|
diag.span_label(self.label, fluent::lint_label);
|
2022-11-13 09:46:31 -05:00
|
|
|
rustc_session::parse::add_feature_diagnostics(
|
|
|
|
diag,
|
|
|
|
&self.parse_sess,
|
|
|
|
sym::closure_track_caller,
|
|
|
|
);
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
|
|
|
|
fn msg(&self) -> DiagnosticMessage {
|
|
|
|
fluent::lint_ungated_async_fn_track_caller
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-22 21:50:44 -04: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 09:46:31 -05:00
|
|
|
pub struct SuggestChangingAssocTypes<'a, 'b> {
|
|
|
|
pub ty: &'a rustc_hir::Ty<'b>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AddToDiagnostic for SuggestChangingAssocTypes<'_, '_> {
|
|
|
|
fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
|
|
|
|
where
|
|
|
|
F: Fn(
|
|
|
|
&mut rustc_errors::Diagnostic,
|
|
|
|
rustc_errors::SubdiagnosticMessage,
|
|
|
|
) -> rustc_errors::SubdiagnosticMessage,
|
|
|
|
{
|
|
|
|
// 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 09:46:31 -05:00
|
|
|
|
|
|
|
// We use a HIR visitor to walk the type.
|
|
|
|
use rustc_hir::intravisit::{self, Visitor};
|
|
|
|
struct WalkAssocTypes<'a> {
|
|
|
|
err: &'a mut rustc_errors::Diagnostic,
|
|
|
|
}
|
|
|
|
impl Visitor<'_> for WalkAssocTypes<'_> {
|
|
|
|
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-22 21:50:44 -04:00
|
|
|
|
2022-11-13 09:46:31 -05:00
|
|
|
impl AddToDiagnostic for BuiltinTypeAliasGenericBoundsSuggestion {
|
|
|
|
fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
|
|
|
|
where
|
|
|
|
F: Fn(
|
|
|
|
&mut rustc_errors::Diagnostic,
|
|
|
|
rustc_errors::SubdiagnosticMessage,
|
|
|
|
) -> rustc_errors::SubdiagnosticMessage,
|
|
|
|
{
|
|
|
|
diag.multipart_suggestion(
|
2022-10-13 10:13:02 +01:00
|
|
|
fluent::lint_suggestion,
|
2022-11-13 09:46:31 -05:00
|
|
|
self.suggestions,
|
|
|
|
Applicability::MachineApplicable,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2022-10-22 21:50:44 -04:00
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_builtin_trivial_bounds)]
|
|
|
|
pub struct BuiltinTrivialBounds<'a> {
|
|
|
|
pub predicate_kind_name: &'a str,
|
|
|
|
pub predicate: Predicate<'a>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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_unnameable_test_items)]
|
|
|
|
pub struct BuiltinUnnameableTestItems;
|
|
|
|
|
|
|
|
#[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 10:13:02 +01:00
|
|
|
#[multipart_suggestion(lint_suggestion)]
|
2022-10-22 21:50:44 -04:00
|
|
|
pub struct BuiltinExplicitOutlivesSuggestion {
|
|
|
|
#[suggestion_part(code = "")]
|
|
|
|
pub spans: Vec<Span>,
|
|
|
|
#[applicability]
|
|
|
|
pub applicability: Applicability,
|
|
|
|
}
|
|
|
|
|
2022-11-10 19:32:30 -05:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_builtin_incomplete_features)]
|
2022-10-22 21:50:44 -04:00
|
|
|
pub struct BuiltinIncompleteFeatures {
|
|
|
|
pub name: Symbol,
|
2022-11-10 19:32:30 -05:00
|
|
|
#[subdiagnostic]
|
|
|
|
pub note: Option<BuiltinIncompleteFeaturesNote>,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub help: Option<BuiltinIncompleteFeaturesHelp>,
|
2022-10-22 21:50:44 -04:00
|
|
|
}
|
|
|
|
|
2022-11-10 19:32:30 -05:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-10-13 10:13:02 +01:00
|
|
|
#[help(lint_help)]
|
2022-11-10 19:32:30 -05:00
|
|
|
pub struct BuiltinIncompleteFeaturesHelp;
|
2022-10-22 21:50:44 -04:00
|
|
|
|
2022-11-10 19:32:30 -05:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-10-13 10:13:02 +01:00
|
|
|
#[note(lint_note)]
|
2022-11-10 19:32:30 -05:00
|
|
|
pub struct BuiltinIncompleteFeaturesNote {
|
|
|
|
pub n: NonZeroU32,
|
2022-10-22 21:50:44 -04:00
|
|
|
}
|
|
|
|
|
2022-11-13 09:46:31 -05:00
|
|
|
pub struct BuiltinUnpermittedTypeInit<'a> {
|
|
|
|
pub msg: DiagnosticMessage,
|
|
|
|
pub ty: Ty<'a>,
|
|
|
|
pub label: Span,
|
|
|
|
pub sub: BuiltinUnpermittedTypeInitSub,
|
2023-02-13 15:38:23 +01:00
|
|
|
pub tcx: TyCtxt<'a>,
|
2022-11-13 09:46:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> DecorateLint<'a, ()> for BuiltinUnpermittedTypeInit<'_> {
|
|
|
|
fn decorate_lint<'b>(
|
|
|
|
self,
|
|
|
|
diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
|
|
|
|
) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
|
|
|
|
diag.set_arg("ty", self.ty);
|
|
|
|
diag.span_label(self.label, fluent::lint_builtin_unpermitted_type_init_label);
|
2023-02-13 15:38:23 +01: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,
|
|
|
|
);
|
|
|
|
}
|
2022-11-13 09:46:31 -05:00
|
|
|
self.sub.add_to_diagnostic(diag);
|
|
|
|
diag
|
|
|
|
}
|
2022-10-22 21:50:44 -04:00
|
|
|
|
2022-11-13 09:46:31 -05:00
|
|
|
fn msg(&self) -> rustc_errors::DiagnosticMessage {
|
|
|
|
self.msg.clone()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME(davidtwco): make translatable
|
|
|
|
pub struct BuiltinUnpermittedTypeInitSub {
|
|
|
|
pub err: InitError,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AddToDiagnostic for BuiltinUnpermittedTypeInitSub {
|
|
|
|
fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
|
|
|
|
where
|
|
|
|
F: Fn(
|
|
|
|
&mut rustc_errors::Diagnostic,
|
|
|
|
rustc_errors::SubdiagnosticMessage,
|
|
|
|
) -> rustc_errors::SubdiagnosticMessage,
|
|
|
|
{
|
|
|
|
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 10:13:02 +01:00
|
|
|
#[label(lint_previous_decl_label)]
|
2022-11-13 09:46:31 -05:00
|
|
|
previous_decl_label: Span,
|
2022-10-13 10:13:02 +01:00
|
|
|
#[label(lint_mismatch_label)]
|
2022-11-13 09:46:31 -05:00
|
|
|
mismatch_label: Span,
|
|
|
|
#[subdiagnostic]
|
|
|
|
sub: BuiltinClashingExternSub<'a>,
|
|
|
|
},
|
|
|
|
#[diag(lint_builtin_clashing_extern_diff_name)]
|
|
|
|
DiffName {
|
|
|
|
this: Symbol,
|
|
|
|
orig: Symbol,
|
2022-10-13 10:13:02 +01:00
|
|
|
#[label(lint_previous_decl_label)]
|
2022-11-13 09:46:31 -05:00
|
|
|
previous_decl_label: Span,
|
2022-10-13 10:13:02 +01:00
|
|
|
#[label(lint_mismatch_label)]
|
2022-11-13 09:46:31 -05: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>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AddToDiagnostic for BuiltinClashingExternSub<'_> {
|
|
|
|
fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
|
|
|
|
where
|
|
|
|
F: Fn(
|
|
|
|
&mut rustc_errors::Diagnostic,
|
|
|
|
rustc_errors::SubdiagnosticMessage,
|
|
|
|
) -> rustc_errors::SubdiagnosticMessage,
|
|
|
|
{
|
|
|
|
let mut expected_str = DiagnosticStyledString::new();
|
|
|
|
expected_str.push(self.expected.fn_sig(self.tcx).to_string(), false);
|
|
|
|
let mut found_str = DiagnosticStyledString::new();
|
|
|
|
found_str.push(self.found.fn_sig(self.tcx).to_string(), true);
|
|
|
|
diag.note_expected_found(&"", expected_str, &"", found_str);
|
|
|
|
}
|
|
|
|
}
|
2022-10-22 21:50:44 -04: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,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_builtin_unexpected_cli_config_name)]
|
|
|
|
#[help]
|
|
|
|
pub struct BuiltinUnexpectedCliConfigName {
|
|
|
|
pub name: Symbol,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_builtin_unexpected_cli_config_value)]
|
|
|
|
#[help]
|
|
|
|
pub struct BuiltinUnexpectedCliConfigValue {
|
|
|
|
pub name: Symbol,
|
|
|
|
pub value: Symbol,
|
|
|
|
}
|
|
|
|
|
2022-11-24 20:03:06 -05:00
|
|
|
// deref_into_dyn_supertrait.rs
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_supertrait_as_deref_target)]
|
|
|
|
pub struct SupertraitAsDerefTarget<'a> {
|
|
|
|
pub t: Ty<'a>,
|
2023-02-17 14:32:08 +00:00
|
|
|
pub target_principal: PolyExistentialTraitRef<'a>,
|
2022-11-24 20:03:06 -05:00
|
|
|
#[subdiagnostic]
|
|
|
|
pub label: Option<SupertraitAsDerefTargetLabel>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
2022-10-13 10:13:02 +01:00
|
|
|
#[label(lint_label)]
|
2022-11-24 20:03:06 -05:00
|
|
|
pub struct SupertraitAsDerefTargetLabel {
|
|
|
|
#[primary_span]
|
|
|
|
pub label: Span,
|
|
|
|
}
|
|
|
|
|
2022-10-04 19:39:02 -04:00
|
|
|
// enum_intrinsics_non_enums.rs
|
2022-09-18 10:31:35 -04: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 18:22:48 -05:00
|
|
|
// expect.rs
|
2022-11-10 19:32:30 -05:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_expectation)]
|
|
|
|
pub struct Expectation {
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub rationale: Option<ExpectationNote>,
|
|
|
|
#[note]
|
|
|
|
pub note: Option<()>,
|
2022-11-09 18:22:48 -05:00
|
|
|
}
|
|
|
|
|
2022-11-10 19:32:30 -05:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-10-13 10:13:02 +01:00
|
|
|
#[note(lint_rationale)]
|
2022-11-10 19:32:30 -05:00
|
|
|
pub struct ExpectationNote {
|
|
|
|
pub rationale: Symbol,
|
2022-11-09 18:22:48 -05:00
|
|
|
}
|
|
|
|
|
2022-11-09 19:34:49 -05:00
|
|
|
// for_loops_over_fallibles.rs
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_for_loops_over_fallibles)]
|
|
|
|
pub struct ForLoopsOverFalliblesDiag<'a> {
|
|
|
|
pub article: &'static str,
|
|
|
|
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 10:13:02 +01:00
|
|
|
#[suggestion(lint_remove_next, code = ".by_ref()", applicability = "maybe-incorrect")]
|
2022-11-09 19:34:49 -05:00
|
|
|
RemoveNext {
|
|
|
|
#[primary_span]
|
|
|
|
suggestion: Span,
|
|
|
|
recv_snip: String,
|
|
|
|
},
|
2022-10-13 10:13:02 +01:00
|
|
|
#[multipart_suggestion(lint_use_while_let, applicability = "maybe-incorrect")]
|
2022-11-09 19:34:49 -05: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 10:13:02 +01:00
|
|
|
#[suggestion(lint_use_question_mark, code = "?", applicability = "maybe-incorrect")]
|
2022-11-09 19:34:49 -05:00
|
|
|
pub struct ForLoopsOverFalliblesQuestionMark {
|
|
|
|
#[primary_span]
|
|
|
|
pub suggestion: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
2022-10-13 10:13:02 +01:00
|
|
|
#[multipart_suggestion(lint_suggestion, applicability = "maybe-incorrect")]
|
2022-11-09 19:34:49 -05: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,
|
|
|
|
}
|
|
|
|
|
2022-11-11 22:39:37 -05: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)>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AddToDiagnostic for HiddenUnicodeCodepointsDiagLabels {
|
|
|
|
fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
|
|
|
|
where
|
|
|
|
F: Fn(
|
|
|
|
&mut rustc_errors::Diagnostic,
|
|
|
|
rustc_errors::SubdiagnosticMessage,
|
|
|
|
) -> rustc_errors::SubdiagnosticMessage,
|
|
|
|
{
|
|
|
|
for (c, span) in self.spans {
|
|
|
|
diag.span_label(span, format!("{:?}", c));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum HiddenUnicodeCodepointsDiagSub {
|
|
|
|
Escape { spans: Vec<(char, Span)> },
|
|
|
|
NoEscape { spans: Vec<(char, Span)> },
|
|
|
|
}
|
|
|
|
|
|
|
|
// Used because of multiple multipart_suggestion and note
|
|
|
|
impl AddToDiagnostic for HiddenUnicodeCodepointsDiagSub {
|
|
|
|
fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
|
|
|
|
where
|
|
|
|
F: Fn(
|
|
|
|
&mut rustc_errors::Diagnostic,
|
|
|
|
rustc_errors::SubdiagnosticMessage,
|
|
|
|
) -> rustc_errors::SubdiagnosticMessage,
|
|
|
|
{
|
|
|
|
match self {
|
|
|
|
HiddenUnicodeCodepointsDiagSub::Escape { spans } => {
|
|
|
|
diag.multipart_suggestion_with_style(
|
2022-10-13 10:13:02 +01:00
|
|
|
fluent::lint_suggestion_remove,
|
2022-11-11 22:39:37 -05:00
|
|
|
spans.iter().map(|(_, span)| (*span, "".to_string())).collect(),
|
|
|
|
Applicability::MachineApplicable,
|
|
|
|
SuggestionStyle::HideCodeAlways,
|
|
|
|
);
|
|
|
|
diag.multipart_suggestion(
|
2022-10-13 10:13:02 +01:00
|
|
|
fluent::lint_suggestion_escape,
|
2022-11-11 22:39:37 -05:00
|
|
|
spans
|
|
|
|
.into_iter()
|
|
|
|
.map(|(c, span)| {
|
|
|
|
let c = format!("{:?}", c);
|
|
|
|
(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.
|
|
|
|
diag.set_arg(
|
|
|
|
"escaped",
|
|
|
|
spans
|
|
|
|
.into_iter()
|
|
|
|
.map(|(c, _)| format!("{:?}", c))
|
|
|
|
.collect::<Vec<String>>()
|
|
|
|
.join(", "),
|
|
|
|
);
|
2022-10-13 10:13:02 +01:00
|
|
|
diag.note(fluent::lint_suggestion_remove);
|
|
|
|
diag.note(fluent::lint_no_suggestion_note_escape);
|
2022-11-11 22:39:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-16 22:04:59 +03: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 16:32:54 -04: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,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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 22:02:52 +02:00
|
|
|
#[diag(lint_non_existent_doc_keyword)]
|
2022-10-22 16:32:54 -04:00
|
|
|
#[help]
|
2023-04-10 22:02:52 +02:00
|
|
|
pub struct NonExistentDocKeyword {
|
2022-10-22 16:32:54 -04: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 06:14:56 -04:00
|
|
|
// let_underscore.rs
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
pub enum NonBindingLet {
|
2022-10-07 06:38:20 -04:00
|
|
|
#[diag(lint_non_binding_let_on_sync_lock)]
|
2022-10-07 06:14:56 -04:00
|
|
|
SyncLock {
|
|
|
|
#[subdiagnostic]
|
|
|
|
sub: NonBindingLetSub,
|
|
|
|
},
|
2022-10-07 06:38:20 -04:00
|
|
|
#[diag(lint_non_binding_let_on_drop_type)]
|
2022-10-07 06:14:56 -04:00
|
|
|
DropType {
|
|
|
|
#[subdiagnostic]
|
|
|
|
sub: NonBindingLetSub,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct NonBindingLetSub {
|
|
|
|
pub suggestion: Span,
|
|
|
|
pub multi_suggestion_start: Span,
|
|
|
|
pub multi_suggestion_end: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AddToDiagnostic for NonBindingLetSub {
|
|
|
|
fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
|
|
|
|
where
|
|
|
|
F: Fn(
|
|
|
|
&mut rustc_errors::Diagnostic,
|
|
|
|
rustc_errors::SubdiagnosticMessage,
|
|
|
|
) -> rustc_errors::SubdiagnosticMessage,
|
|
|
|
{
|
|
|
|
diag.span_suggestion_verbose(
|
|
|
|
self.suggestion,
|
2022-10-07 06:38:20 -04:00
|
|
|
fluent::lint_non_binding_let_suggestion,
|
2022-10-07 06:14:56 -04:00
|
|
|
"_unused",
|
|
|
|
Applicability::MachineApplicable,
|
|
|
|
);
|
|
|
|
diag.multipart_suggestion(
|
2022-10-07 06:38:20 -04:00
|
|
|
fluent::lint_non_binding_let_multi_suggestion,
|
2022-10-07 06:14:56 -04:00
|
|
|
vec![
|
|
|
|
(self.multi_suggestion_start, "drop(".to_string()),
|
|
|
|
(self.multi_suggestion_end, ")".to_string()),
|
|
|
|
],
|
|
|
|
Applicability::MachineApplicable,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-05 08:23:00 -04:00
|
|
|
// levels.rs
|
|
|
|
#[derive(LintDiagnostic)]
|
2022-10-06 20:28:51 -04:00
|
|
|
#[diag(lint_overruled_attribute)]
|
2023-04-10 22:02:52 +02:00
|
|
|
pub struct OverruledAttributeLint<'a> {
|
2022-10-06 20:28:51 -04: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 08:23:00 -04:00
|
|
|
pub struct DeprecatedLintName<'a> {
|
|
|
|
pub name: String,
|
|
|
|
#[suggestion(code = "{replace}", applicability = "machine-applicable")]
|
|
|
|
pub suggestion: Span,
|
|
|
|
pub replace: &'a str,
|
|
|
|
}
|
|
|
|
|
2022-11-10 19:32:30 -05:00
|
|
|
// FIXME: Non-translatable msg
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_renamed_or_removed_lint)]
|
2022-10-06 20:28:51 -04:00
|
|
|
pub struct RenamedOrRemovedLint<'a> {
|
|
|
|
pub msg: &'a str,
|
2022-11-10 19:32:30 -05:00
|
|
|
#[subdiagnostic]
|
|
|
|
pub suggestion: Option<RenamedOrRemovedLintSuggestion<'a>>,
|
2022-10-06 20:28:51 -04:00
|
|
|
}
|
|
|
|
|
2022-11-10 19:32:30 -05:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-10-13 10:13:02 +01:00
|
|
|
#[suggestion(lint_suggestion, code = "{replace}", applicability = "machine-applicable")]
|
2022-11-10 19:32:30 -05:00
|
|
|
pub struct RenamedOrRemovedLintSuggestion<'a> {
|
|
|
|
#[primary_span]
|
|
|
|
pub suggestion: Span,
|
|
|
|
pub replace: &'a str,
|
2022-10-06 20:28:51 -04:00
|
|
|
}
|
|
|
|
|
2022-11-10 19:32:30 -05:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unknown_lint)]
|
|
|
|
pub struct UnknownLint {
|
2022-10-06 20:28:51 -04:00
|
|
|
pub name: String,
|
2022-11-10 19:32:30 -05:00
|
|
|
#[subdiagnostic]
|
|
|
|
pub suggestion: Option<UnknownLintSuggestion>,
|
2022-10-06 20:28:51 -04:00
|
|
|
}
|
|
|
|
|
2022-11-10 19:32:30 -05:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-10-13 10:13:02 +01:00
|
|
|
#[suggestion(lint_suggestion, code = "{replace}", applicability = "maybe-incorrect")]
|
2022-11-10 19:32:30 -05:00
|
|
|
pub struct UnknownLintSuggestion {
|
|
|
|
#[primary_span]
|
|
|
|
pub suggestion: Span,
|
|
|
|
pub replace: Symbol,
|
2022-10-06 20:28:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_ignored_unless_crate_specified)]
|
|
|
|
pub struct IgnoredUnlessCrateSpecified<'a> {
|
|
|
|
pub level: &'a str,
|
|
|
|
pub name: Symbol,
|
|
|
|
}
|
|
|
|
|
2022-10-04 19:39:02 -04:00
|
|
|
// methods.rs
|
2022-09-05 15:37:30 -04:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_cstring_ptr)]
|
|
|
|
#[note]
|
|
|
|
#[help]
|
|
|
|
pub struct CStringPtr {
|
2022-10-13 10:13:02 +01:00
|
|
|
#[label(lint_as_ptr_label)]
|
2022-09-05 15:37:30 -04:00
|
|
|
pub as_ptr: Span,
|
2022-10-13 10:13:02 +01:00
|
|
|
#[label(lint_unwrap_label)]
|
2022-09-05 15:37:30 -04:00
|
|
|
pub unwrap: Span,
|
|
|
|
}
|
2022-10-04 19:39:02 -04:00
|
|
|
|
2022-12-09 02:27:03 +00:00
|
|
|
// multiple_supertrait_upcastable.rs
|
|
|
|
#[derive(LintDiagnostic)]
|
2023-04-10 22:02:52 +02:00
|
|
|
#[diag(lint_multiple_supertrait_upcastable)]
|
2022-12-09 02:27:03 +00:00
|
|
|
pub struct MultipleSupertraitUpcastable {
|
|
|
|
pub ident: Ident,
|
|
|
|
}
|
|
|
|
|
2022-10-04 19:39:02 -04:00
|
|
|
// non_ascii_idents.rs
|
2022-09-05 15:05:19 -04:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_identifier_non_ascii_char)]
|
|
|
|
pub struct IdentifierNonAsciiChar;
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_identifier_uncommon_codepoints)]
|
|
|
|
pub struct IdentifierUncommonCodepoints;
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_confusable_identifier_pair)]
|
|
|
|
pub struct ConfusableIdentifierPair {
|
|
|
|
pub existing_sym: Symbol,
|
|
|
|
pub sym: Symbol,
|
|
|
|
#[label]
|
|
|
|
pub label: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_mixed_script_confusables)]
|
2022-10-13 10:13:02 +01:00
|
|
|
#[note(lint_includes_note)]
|
2022-09-05 15:05:19 -04:00
|
|
|
#[note]
|
|
|
|
pub struct MixedScriptConfusables {
|
|
|
|
pub set: String,
|
|
|
|
pub includes: String,
|
|
|
|
}
|
|
|
|
|
2022-10-04 19:39:02 -04:00
|
|
|
// non_fmt_panic.rs
|
2022-09-05 14:38:36 -04:00
|
|
|
pub struct NonFmtPanicUnused {
|
|
|
|
pub count: usize,
|
|
|
|
pub suggestion: Option<Span>,
|
|
|
|
}
|
|
|
|
|
2022-11-10 19:32:30 -05:00
|
|
|
// Used because of two suggestions based on one Option<Span>
|
2022-10-04 17:54:47 -04:00
|
|
|
impl<'a> DecorateLint<'a, ()> for NonFmtPanicUnused {
|
|
|
|
fn decorate_lint<'b>(
|
|
|
|
self,
|
|
|
|
diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
|
|
|
|
) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
|
2022-09-05 14:38:36 -04:00
|
|
|
diag.set_arg("count", self.count);
|
2022-10-13 10:13:02 +01:00
|
|
|
diag.note(fluent::lint_note);
|
2022-09-05 14:38:36 -04:00
|
|
|
if let Some(span) = self.suggestion {
|
|
|
|
diag.span_suggestion(
|
|
|
|
span.shrink_to_hi(),
|
2022-10-13 10:13:02 +01:00
|
|
|
fluent::lint_add_args_suggestion,
|
2022-09-05 14:38:36 -04:00
|
|
|
", ...",
|
|
|
|
Applicability::HasPlaceholders,
|
|
|
|
);
|
|
|
|
diag.span_suggestion(
|
|
|
|
span.shrink_to_lo(),
|
2022-10-13 10:13:02 +01:00
|
|
|
fluent::lint_add_fmt_suggestion,
|
2022-09-05 14:38:36 -04:00
|
|
|
"\"{}\", ",
|
|
|
|
Applicability::MachineApplicable,
|
|
|
|
);
|
|
|
|
}
|
2022-10-04 17:54:47 -04:00
|
|
|
diag
|
|
|
|
}
|
|
|
|
|
|
|
|
fn msg(&self) -> rustc_errors::DiagnosticMessage {
|
|
|
|
fluent::lint_non_fmt_panic_unused
|
2022-09-05 14:38:36 -04: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 19:39:02 -04:00
|
|
|
// nonstandard_style.rs
|
2022-09-05 13:37:57 -04: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-21 20:47:24 -04:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-09-05 13:37:57 -04:00
|
|
|
pub enum NonCamelCaseTypeSub {
|
2022-10-13 10:13:02 +01:00
|
|
|
#[label(lint_label)]
|
2022-09-05 13:37:57 -04:00
|
|
|
Label {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
},
|
2022-10-13 10:13:02 +01:00
|
|
|
#[suggestion(lint_suggestion, code = "{replace}", applicability = "maybe-incorrect")]
|
2022-09-05 13:37:57 -04: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 },
|
|
|
|
}
|
|
|
|
|
2022-09-21 20:47:24 -04:00
|
|
|
impl AddToDiagnostic for NonSnakeCaseDiagSub {
|
|
|
|
fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
|
|
|
|
where
|
|
|
|
F: Fn(
|
|
|
|
&mut rustc_errors::Diagnostic,
|
|
|
|
rustc_errors::SubdiagnosticMessage,
|
|
|
|
) -> rustc_errors::SubdiagnosticMessage,
|
|
|
|
{
|
2022-09-05 13:37:57 -04:00
|
|
|
match self {
|
|
|
|
NonSnakeCaseDiagSub::Label { span } => {
|
2022-10-13 10:13:02 +01:00
|
|
|
diag.span_label(span, fluent::lint_label);
|
2022-09-05 13:37:57 -04:00
|
|
|
}
|
|
|
|
NonSnakeCaseDiagSub::Help => {
|
2022-10-13 10:13:02 +01:00
|
|
|
diag.help(fluent::lint_help);
|
2022-09-05 13:37:57 -04:00
|
|
|
}
|
|
|
|
NonSnakeCaseDiagSub::ConvertSuggestion { span, suggestion } => {
|
|
|
|
diag.span_suggestion(
|
|
|
|
span,
|
2022-10-13 10:13:02 +01:00
|
|
|
fluent::lint_convert_suggestion,
|
2022-09-05 13:37:57 -04:00
|
|
|
suggestion,
|
|
|
|
Applicability::MaybeIncorrect,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
NonSnakeCaseDiagSub::RenameOrConvertSuggestion { span, suggestion } => {
|
|
|
|
diag.span_suggestion(
|
|
|
|
span,
|
2022-10-13 10:13:02 +01:00
|
|
|
fluent::lint_rename_or_convert_suggestion,
|
2022-09-05 13:37:57 -04:00
|
|
|
suggestion,
|
|
|
|
Applicability::MaybeIncorrect,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
NonSnakeCaseDiagSub::SuggestionAndNote { span } => {
|
2022-10-13 10:13:02 +01:00
|
|
|
diag.note(fluent::lint_cannot_convert_note);
|
2022-09-05 13:37:57 -04:00
|
|
|
diag.span_suggestion(
|
|
|
|
span,
|
2022-10-13 10:13:02 +01:00
|
|
|
fluent::lint_rename_suggestion,
|
2022-09-05 13:37:57 -04:00
|
|
|
"",
|
|
|
|
Applicability::MaybeIncorrect,
|
|
|
|
);
|
|
|
|
}
|
2022-10-04 17:54:47 -04:00
|
|
|
}
|
2022-09-05 13:37:57 -04: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-21 20:47:24 -04:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-09-05 13:37:57 -04:00
|
|
|
pub enum NonUpperCaseGlobalSub {
|
2022-10-13 10:13:02 +01:00
|
|
|
#[label(lint_label)]
|
2022-09-05 13:37:57 -04:00
|
|
|
Label {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
},
|
2022-10-13 10:13:02 +01:00
|
|
|
#[suggestion(lint_suggestion, code = "{replace}", applicability = "maybe-incorrect")]
|
2022-09-05 13:37:57 -04:00
|
|
|
Suggestion {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
replace: String,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-10-04 19:39:02 -04:00
|
|
|
// noop_method_call.rs
|
2022-09-05 12:42:58 -04:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_noop_method_call)]
|
|
|
|
#[note]
|
|
|
|
pub struct NoopMethodCallDiag<'a> {
|
|
|
|
pub method: Symbol,
|
|
|
|
pub receiver_ty: Ty<'a>,
|
|
|
|
#[label]
|
|
|
|
pub label: Span,
|
|
|
|
}
|
|
|
|
|
2022-10-04 19:39:02 -04:00
|
|
|
// pass_by_value.rs
|
2022-09-05 12:38:55 -04: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 19:39:02 -04:00
|
|
|
// redundant_semicolon.rs
|
2022-09-05 12:32:01 -04:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_redundant_semicolons)]
|
|
|
|
pub struct RedundantSemicolonsDiag {
|
|
|
|
pub multiple: bool,
|
|
|
|
#[suggestion(code = "", applicability = "maybe-incorrect")]
|
|
|
|
pub suggestion: Span,
|
|
|
|
}
|
|
|
|
|
2022-10-04 19:39:02 -04:00
|
|
|
// traits.rs
|
2022-09-05 11:52:08 -04:00
|
|
|
pub struct DropTraitConstraintsDiag<'a> {
|
|
|
|
pub predicate: Predicate<'a>,
|
|
|
|
pub tcx: TyCtxt<'a>,
|
|
|
|
pub def_id: DefId,
|
|
|
|
}
|
|
|
|
|
2022-11-10 19:32:30 -05:00
|
|
|
// Needed for def_path_str
|
2022-10-04 17:54:47 -04:00
|
|
|
impl<'a> DecorateLint<'a, ()> for DropTraitConstraintsDiag<'_> {
|
|
|
|
fn decorate_lint<'b>(
|
|
|
|
self,
|
|
|
|
diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
|
|
|
|
) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
|
2022-09-05 11:52:08 -04:00
|
|
|
diag.set_arg("predicate", self.predicate);
|
2022-10-04 17:54:47 -04:00
|
|
|
diag.set_arg("needs_drop", self.tcx.def_path_str(self.def_id))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn msg(&self) -> rustc_errors::DiagnosticMessage {
|
|
|
|
fluent::lint_drop_trait_constraints
|
2022-09-05 11:52:08 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct DropGlue<'a> {
|
|
|
|
pub tcx: TyCtxt<'a>,
|
|
|
|
pub def_id: DefId,
|
|
|
|
}
|
|
|
|
|
2022-11-10 19:32:30 -05:00
|
|
|
// Needed for def_path_str
|
2022-10-04 17:54:47 -04:00
|
|
|
impl<'a> DecorateLint<'a, ()> for DropGlue<'_> {
|
|
|
|
fn decorate_lint<'b>(
|
|
|
|
self,
|
|
|
|
diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
|
|
|
|
) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
|
|
|
|
diag.set_arg("needs_drop", self.tcx.def_path_str(self.def_id))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn msg(&self) -> rustc_errors::DiagnosticMessage {
|
|
|
|
fluent::lint_drop_glue
|
2022-09-05 11:52:08 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-04 19:39:02 -04:00
|
|
|
// types.rs
|
2022-08-28 19:07:58 -04:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_range_endpoint_out_of_range)]
|
|
|
|
pub struct RangeEndpointOutOfRange<'a> {
|
|
|
|
pub ty: &'a str,
|
2023-03-25 01:00:49 +08: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 19:07:58 -04: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>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum OverflowingBinHexSign {
|
|
|
|
Positive,
|
|
|
|
Negative,
|
|
|
|
}
|
|
|
|
|
2022-09-21 20:47:24 -04:00
|
|
|
impl AddToDiagnostic for OverflowingBinHexSign {
|
|
|
|
fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
|
|
|
|
where
|
|
|
|
F: Fn(
|
|
|
|
&mut rustc_errors::Diagnostic,
|
|
|
|
rustc_errors::SubdiagnosticMessage,
|
|
|
|
) -> rustc_errors::SubdiagnosticMessage,
|
|
|
|
{
|
2022-08-28 19:07:58 -04:00
|
|
|
match self {
|
|
|
|
OverflowingBinHexSign::Positive => {
|
2022-10-13 10:13:02 +01:00
|
|
|
diag.note(fluent::lint_positive_note);
|
2022-08-28 19:07:58 -04:00
|
|
|
}
|
|
|
|
OverflowingBinHexSign::Negative => {
|
2022-10-13 10:13:02 +01:00
|
|
|
diag.note(fluent::lint_negative_note);
|
|
|
|
diag.note(fluent::lint_negative_becomes_note);
|
2022-08-28 19:07:58 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-21 20:47:24 -04:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-08-28 19:07:58 -04:00
|
|
|
pub enum OverflowingBinHexSub<'a> {
|
|
|
|
#[suggestion(
|
2022-10-13 10:13:02 +01:00
|
|
|
lint_suggestion,
|
2022-08-28 19:07:58 -04: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 10:13:02 +01:00
|
|
|
#[help(lint_help)]
|
2022-08-28 19:07:58 -04:00
|
|
|
Help { suggestion_ty: &'a str },
|
|
|
|
}
|
|
|
|
|
2022-11-10 19:32:30 -05:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_overflowing_int)]
|
|
|
|
#[note]
|
2022-08-28 19:07:58 -04:00
|
|
|
pub struct OverflowingInt<'a> {
|
|
|
|
pub ty: &'a str,
|
|
|
|
pub lit: String,
|
|
|
|
pub min: i128,
|
|
|
|
pub max: u128,
|
2022-11-10 19:32:30 -05:00
|
|
|
#[subdiagnostic]
|
|
|
|
pub help: Option<OverflowingIntHelp<'a>>,
|
2022-08-28 19:07:58 -04:00
|
|
|
}
|
|
|
|
|
2022-11-10 19:32:30 -05:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-10-13 10:13:02 +01:00
|
|
|
#[help(lint_help)]
|
2022-11-10 19:32:30 -05:00
|
|
|
pub struct OverflowingIntHelp<'a> {
|
|
|
|
pub suggestion_ty: &'a str,
|
2022-08-28 19:07:58 -04: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;
|
|
|
|
|
2022-10-07 06:38:20 -04:00
|
|
|
pub struct ImproperCTypes<'a> {
|
|
|
|
pub ty: Ty<'a>,
|
|
|
|
pub desc: &'a str,
|
|
|
|
pub label: Span,
|
|
|
|
pub help: Option<DiagnosticMessage>,
|
|
|
|
pub note: DiagnosticMessage,
|
|
|
|
pub span_note: Option<Span>,
|
|
|
|
}
|
|
|
|
|
2022-11-10 19:32:30 -05:00
|
|
|
// Used because of the complexity of Option<DiagnosticMessage>, DiagnosticMessage, and Option<Span>
|
2022-10-07 06:38:20 -04:00
|
|
|
impl<'a> DecorateLint<'a, ()> for ImproperCTypes<'_> {
|
|
|
|
fn decorate_lint<'b>(
|
|
|
|
self,
|
|
|
|
diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
|
|
|
|
) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
|
|
|
|
diag.set_arg("ty", self.ty);
|
|
|
|
diag.set_arg("desc", self.desc);
|
2022-10-13 10:13:02 +01:00
|
|
|
diag.span_label(self.label, fluent::lint_label);
|
2022-10-07 06:38:20 -04:00
|
|
|
if let Some(help) = self.help {
|
|
|
|
diag.help(help);
|
|
|
|
}
|
|
|
|
diag.note(self.note);
|
|
|
|
if let Some(note) = self.span_note {
|
2022-10-13 10:13:02 +01:00
|
|
|
diag.span_note(note, fluent::lint_note);
|
2022-10-07 06:38:20 -04:00
|
|
|
}
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
|
|
|
|
fn msg(&self) -> rustc_errors::DiagnosticMessage {
|
|
|
|
fluent::lint_improper_ctypes
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-28 19:07:58 -04: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 13:37:00 -04: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 15:46:35 -04:00
|
|
|
|
2022-10-04 19:39:02 -04:00
|
|
|
// unused.rs
|
2022-09-04 15:46:35 -04:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unused_op)]
|
|
|
|
pub struct UnusedOp<'a> {
|
|
|
|
pub op: &'a str,
|
|
|
|
#[label]
|
|
|
|
pub label: Span,
|
2023-03-11 18:28:05 +13:00
|
|
|
#[suggestion(style = "verbose", code = "let _ = ", applicability = "maybe-incorrect")]
|
2022-09-04 15:46:35 -04:00
|
|
|
pub suggestion: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unused_result)]
|
|
|
|
pub struct UnusedResult<'a> {
|
|
|
|
pub ty: Ty<'a>,
|
|
|
|
}
|
|
|
|
|
2023-04-10 22:02:52 +02:00
|
|
|
// FIXME(davidtwco): this isn't properly translatable because of the
|
2022-09-04 15:46:35 -04: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 22:02:52 +02:00
|
|
|
// FIXME(davidtwco): this isn't properly translatable because of the
|
2022-09-04 15:46:35 -04:00
|
|
|
// pre/post strings
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_unused_generator)]
|
|
|
|
#[note]
|
|
|
|
pub struct UnusedGenerator<'a> {
|
|
|
|
pub count: usize,
|
|
|
|
pub pre: &'a str,
|
|
|
|
pub post: &'a str,
|
|
|
|
}
|
|
|
|
|
2023-04-10 22:02:52 +02:00
|
|
|
// FIXME(davidtwco): this isn't properly translatable because of the pre/post
|
2022-09-04 15:46:35 -04: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 21:14:02 +08:00
|
|
|
pub suggestion: Option<UnusedDefSuggestion>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
2023-03-11 18:28:05 +13:00
|
|
|
#[suggestion(
|
|
|
|
lint_suggestion,
|
|
|
|
style = "verbose",
|
|
|
|
code = "let _ = ",
|
|
|
|
applicability = "maybe-incorrect"
|
|
|
|
)]
|
|
|
|
pub struct UnusedDefSuggestion {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
2022-09-04 15:46:35 -04:00
|
|
|
}
|
|
|
|
|
2022-11-10 19:32:30 -05:00
|
|
|
// Needed because of def_path_str
|
2022-10-04 17:54:47 -04:00
|
|
|
impl<'a> DecorateLint<'a, ()> for UnusedDef<'_, '_> {
|
|
|
|
fn decorate_lint<'b>(
|
|
|
|
self,
|
|
|
|
diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
|
|
|
|
) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
|
2022-09-04 15:46:35 -04:00
|
|
|
diag.set_arg("pre", self.pre);
|
|
|
|
diag.set_arg("post", self.post);
|
|
|
|
diag.set_arg("def", self.cx.tcx.def_path_str(self.def_id));
|
|
|
|
// check for #[must_use = "..."]
|
|
|
|
if let Some(note) = self.note {
|
|
|
|
diag.note(note.as_str());
|
|
|
|
}
|
2022-10-29 21:14:02 +08:00
|
|
|
if let Some(sugg) = self.suggestion {
|
|
|
|
diag.subdiagnostic(sugg);
|
|
|
|
}
|
2022-10-04 17:54:47 -04:00
|
|
|
diag
|
|
|
|
}
|
|
|
|
|
|
|
|
fn msg(&self) -> rustc_errors::DiagnosticMessage {
|
|
|
|
fluent::lint_unused_def
|
2022-09-04 15:46:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(lint_path_statement_drop)]
|
|
|
|
pub struct PathStatementDrop {
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub sub: PathStatementDropSub,
|
|
|
|
}
|
|
|
|
|
2022-09-21 20:47:24 -04:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-09-04 15:46:35 -04:00
|
|
|
pub enum PathStatementDropSub {
|
2022-10-13 10:13:02 +01:00
|
|
|
#[suggestion(lint_suggestion, code = "drop({snippet});", applicability = "machine-applicable")]
|
2022-09-04 15:46:35 -04:00
|
|
|
Suggestion {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
snippet: String,
|
|
|
|
},
|
2022-10-13 10:13:02 +01:00
|
|
|
#[help(lint_help)]
|
2022-09-04 15:46:35 -04: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 10:13:02 +01:00
|
|
|
#[multipart_suggestion(lint_suggestion, applicability = "machine-applicable")]
|
2022-09-04 15:46:35 -04: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;
|