migrate: early.rs
and enum_intrinsics_non_enums.rs
This commit is contained in:
parent
c63ba52562
commit
8b897bbce6
4 changed files with 30 additions and 8 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
#![deny(rustc::untranslatable_diagnostic)]
|
||||||
|
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||||
//! Implementation of lint checking.
|
//! Implementation of lint checking.
|
||||||
//!
|
//!
|
||||||
//! The lint checking is mostly consolidated into one pass which runs
|
//! The lint checking is mostly consolidated into one pass which runs
|
||||||
|
@ -39,6 +41,7 @@ pub struct EarlyContextAndPass<'a, T: EarlyLintPass> {
|
||||||
impl<'a, T: EarlyLintPass> EarlyContextAndPass<'a, T> {
|
impl<'a, T: EarlyLintPass> EarlyContextAndPass<'a, T> {
|
||||||
// This always-inlined function is for the hot call site.
|
// This always-inlined function is for the hot call site.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[allow(rustc::diagnostic_outside_of_impl)]
|
||||||
fn inlined_check_id(&mut self, id: ast::NodeId) {
|
fn inlined_check_id(&mut self, id: ast::NodeId) {
|
||||||
for early_lint in self.context.buffered.take(id) {
|
for early_lint in self.context.buffered.take(id) {
|
||||||
let BufferedEarlyLint { span, msg, node_id: _, lint_id, diagnostic } = early_lint;
|
let BufferedEarlyLint { span, msg, node_id: _, lint_id, diagnostic } = early_lint;
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
use crate::{context::LintContext, LateContext, LateLintPass};
|
#![deny(rustc::untranslatable_diagnostic)]
|
||||||
use rustc_errors::fluent;
|
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||||
|
use crate::{
|
||||||
|
context::LintContext,
|
||||||
|
lints::{EnumIntrinsicsMemDiscriminate, EnumIntrinsicsMemVariant},
|
||||||
|
LateContext, LateLintPass,
|
||||||
|
};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_middle::ty::{visit::TypeVisitable, Ty};
|
use rustc_middle::ty::{visit::TypeVisitable, Ty};
|
||||||
use rustc_span::{symbol::sym, Span};
|
use rustc_span::{symbol::sym, Span};
|
||||||
|
@ -50,11 +55,10 @@ fn enforce_mem_discriminant(
|
||||||
) {
|
) {
|
||||||
let ty_param = cx.typeck_results().node_substs(func_expr.hir_id).type_at(0);
|
let ty_param = cx.typeck_results().node_substs(func_expr.hir_id).type_at(0);
|
||||||
if is_non_enum(ty_param) {
|
if is_non_enum(ty_param) {
|
||||||
cx.struct_span_lint(
|
cx.emit_spanned_lint(
|
||||||
ENUM_INTRINSICS_NON_ENUMS,
|
ENUM_INTRINSICS_NON_ENUMS,
|
||||||
expr_span,
|
expr_span,
|
||||||
fluent::lint_enum_intrinsics_mem_discriminant,
|
EnumIntrinsicsMemDiscriminate { ty_param, note: args_span },
|
||||||
|lint| lint.set_arg("ty_param", ty_param).span_note(args_span, fluent::note),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,11 +66,10 @@ fn enforce_mem_discriminant(
|
||||||
fn enforce_mem_variant_count(cx: &LateContext<'_>, func_expr: &hir::Expr<'_>, span: Span) {
|
fn enforce_mem_variant_count(cx: &LateContext<'_>, func_expr: &hir::Expr<'_>, span: Span) {
|
||||||
let ty_param = cx.typeck_results().node_substs(func_expr.hir_id).type_at(0);
|
let ty_param = cx.typeck_results().node_substs(func_expr.hir_id).type_at(0);
|
||||||
if is_non_enum(ty_param) {
|
if is_non_enum(ty_param) {
|
||||||
cx.struct_span_lint(
|
cx.emit_spanned_lint(
|
||||||
ENUM_INTRINSICS_NON_ENUMS,
|
ENUM_INTRINSICS_NON_ENUMS,
|
||||||
span,
|
span,
|
||||||
fluent::lint_enum_intrinsics_mem_variant,
|
EnumIntrinsicsMemVariant { ty_param },
|
||||||
|lint| lint.set_arg("ty_param", ty_param).note(fluent::note),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ impl AddToDiagnostic for OverruledAttributeSub {
|
||||||
OverruledAttributeSub::NodeSource { span, reason } => {
|
OverruledAttributeSub::NodeSource { span, reason } => {
|
||||||
diag.span_label(span, fluent::lint_node_source);
|
diag.span_label(span, fluent::lint_node_source);
|
||||||
if let Some(rationale) = reason {
|
if let Some(rationale) = reason {
|
||||||
|
#[allow(rustc::diagnostic_outside_of_impl)]
|
||||||
diag.note(rationale.as_str());
|
diag.note(rationale.as_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,21 @@ pub enum ArrayIntoIterDiagSub {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(LintDiagnostic)]
|
#[derive(LintDiagnostic)]
|
||||||
#[diag(lint_cstring_ptr)]
|
#[diag(lint_cstring_ptr)]
|
||||||
#[note]
|
#[note]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue