migrate: ImproperCTypes
This commit is contained in:
parent
e610047940
commit
5ffaae758e
@ -1,4 +1,4 @@
|
|||||||
use rustc_errors::{fluent, AddToDiagnostic, Applicability, DecorateLint};
|
use rustc_errors::{fluent, AddToDiagnostic, Applicability, DecorateLint, DiagnosticMessage};
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_macros::{LintDiagnostic, Subdiagnostic};
|
use rustc_macros::{LintDiagnostic, Subdiagnostic};
|
||||||
use rustc_middle::ty::{Predicate, Ty, TyCtxt};
|
use rustc_middle::ty::{Predicate, Ty, TyCtxt};
|
||||||
@ -52,12 +52,12 @@ pub struct EnumIntrinsicsMemVariant<'a> {
|
|||||||
// let_underscore.rs
|
// let_underscore.rs
|
||||||
#[derive(LintDiagnostic)]
|
#[derive(LintDiagnostic)]
|
||||||
pub enum NonBindingLet {
|
pub enum NonBindingLet {
|
||||||
#[diag(lint::non_binding_let_on_sync_lock)]
|
#[diag(lint_non_binding_let_on_sync_lock)]
|
||||||
SyncLock {
|
SyncLock {
|
||||||
#[subdiagnostic]
|
#[subdiagnostic]
|
||||||
sub: NonBindingLetSub,
|
sub: NonBindingLetSub,
|
||||||
},
|
},
|
||||||
#[diag(lint::non_binding_let_on_drop_type)]
|
#[diag(lint_non_binding_let_on_drop_type)]
|
||||||
DropType {
|
DropType {
|
||||||
#[subdiagnostic]
|
#[subdiagnostic]
|
||||||
sub: NonBindingLetSub,
|
sub: NonBindingLetSub,
|
||||||
@ -80,12 +80,12 @@ impl AddToDiagnostic for NonBindingLetSub {
|
|||||||
{
|
{
|
||||||
diag.span_suggestion_verbose(
|
diag.span_suggestion_verbose(
|
||||||
self.suggestion,
|
self.suggestion,
|
||||||
fluent::lint::non_binding_let_suggestion,
|
fluent::lint_non_binding_let_suggestion,
|
||||||
"_unused",
|
"_unused",
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
diag.multipart_suggestion(
|
diag.multipart_suggestion(
|
||||||
fluent::lint::non_binding_let_multi_suggestion,
|
fluent::lint_non_binding_let_multi_suggestion,
|
||||||
vec![
|
vec![
|
||||||
(self.multi_suggestion_start, "drop(".to_string()),
|
(self.multi_suggestion_start, "drop(".to_string()),
|
||||||
(self.multi_suggestion_end, ")".to_string()),
|
(self.multi_suggestion_end, ")".to_string()),
|
||||||
@ -568,6 +568,38 @@ pub struct OverflowingLiteral<'a> {
|
|||||||
#[diag(lint_unused_comparisons)]
|
#[diag(lint_unused_comparisons)]
|
||||||
pub struct UnusedComparisons;
|
pub struct UnusedComparisons;
|
||||||
|
|
||||||
|
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>,
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
diag.span_label(self.label, fluent::label);
|
||||||
|
if let Some(help) = self.help {
|
||||||
|
diag.help(help);
|
||||||
|
}
|
||||||
|
diag.note(self.note);
|
||||||
|
if let Some(note) = self.span_note {
|
||||||
|
diag.span_note(note, fluent::note);
|
||||||
|
}
|
||||||
|
diag
|
||||||
|
}
|
||||||
|
|
||||||
|
fn msg(&self) -> rustc_errors::DiagnosticMessage {
|
||||||
|
fluent::lint_improper_ctypes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(LintDiagnostic)]
|
#[derive(LintDiagnostic)]
|
||||||
#[diag(lint_variant_size_differences)]
|
#[diag(lint_variant_size_differences)]
|
||||||
pub struct VariantSizeDifferencesDiag {
|
pub struct VariantSizeDifferencesDiag {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
#![deny(rustc::untranslatable_diagnostic)]
|
#![deny(rustc::untranslatable_diagnostic)]
|
||||||
#![deny(rustc::diagnostic_outside_of_impl)]
|
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||||
use crate::lints::{
|
use crate::lints::{
|
||||||
AtomicOrderingFence, AtomicOrderingLoad, AtomicOrderingStore, InvalidAtomicOrderingDiag,
|
AtomicOrderingFence, AtomicOrderingLoad, AtomicOrderingStore, ImproperCTypes,
|
||||||
OnlyCastu8ToChar, OverflowingBinHex, OverflowingBinHexSign, OverflowingBinHexSub,
|
InvalidAtomicOrderingDiag, OnlyCastu8ToChar, OverflowingBinHex, OverflowingBinHexSign,
|
||||||
OverflowingInt, OverflowingLiteral, OverflowingUInt, RangeEndpointOutOfRange,
|
OverflowingBinHexSub, OverflowingInt, OverflowingLiteral, OverflowingUInt,
|
||||||
UnusedComparisons, VariantSizeDifferencesDiag,
|
RangeEndpointOutOfRange, UnusedComparisons, VariantSizeDifferencesDiag,
|
||||||
};
|
};
|
||||||
use crate::{LateContext, LateLintPass, LintContext};
|
use crate::{LateContext, LateLintPass, LintContext};
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
@ -1131,27 +1131,21 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
|||||||
CItemKind::Declaration => IMPROPER_CTYPES,
|
CItemKind::Declaration => IMPROPER_CTYPES,
|
||||||
CItemKind::Definition => IMPROPER_CTYPES_DEFINITIONS,
|
CItemKind::Definition => IMPROPER_CTYPES_DEFINITIONS,
|
||||||
};
|
};
|
||||||
|
let desc = match self.mode {
|
||||||
self.cx.struct_span_lint(lint, sp, fluent::lint_improper_ctypes, |lint| {
|
|
||||||
let item_description = match self.mode {
|
|
||||||
CItemKind::Declaration => "block",
|
CItemKind::Declaration => "block",
|
||||||
CItemKind::Definition => "fn",
|
CItemKind::Definition => "fn",
|
||||||
};
|
};
|
||||||
#[allow(rustc::diagnostic_outside_of_impl)]
|
let span_note = if let ty::Adt(def, _) = ty.kind()
|
||||||
lint.set_arg("ty", ty);
|
&& let Some(sp) = self.cx.tcx.hir().span_if_local(def.did()) {
|
||||||
lint.set_arg("desc", item_description);
|
Some(sp)
|
||||||
lint.span_label(sp, fluent::label);
|
} else {
|
||||||
if let Some(help) = help {
|
None
|
||||||
lint.help(help);
|
};
|
||||||
}
|
self.cx.emit_spanned_lint(
|
||||||
lint.note(note);
|
lint,
|
||||||
if let ty::Adt(def, _) = ty.kind() {
|
sp,
|
||||||
if let Some(sp) = self.cx.tcx.hir().span_if_local(def.did()) {
|
ImproperCTypes { ty, desc, label: sp, help, note, span_note },
|
||||||
lint.span_note(sp, fluent::note);
|
);
|
||||||
}
|
|
||||||
}
|
|
||||||
lint
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_for_opaque_ty(&mut self, sp: Span, ty: Ty<'tcx>) -> bool {
|
fn check_for_opaque_ty(&mut self, sp: Span, ty: Ty<'tcx>) -> bool {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user