1
Fork 0

Rename incorrect_fn_null_checks to useless_ptr_null_checks

This commit is contained in:
Urgau 2023-07-13 12:01:13 +02:00
parent 743ae5a2eb
commit d2b7c8028f
6 changed files with 47 additions and 47 deletions

View file

@ -57,7 +57,6 @@ mod early;
mod enum_intrinsics_non_enums;
mod errors;
mod expect;
mod fn_null_check;
mod for_loops_over_fallibles;
pub mod hidden_unicode_codepoints;
mod internal;
@ -76,6 +75,7 @@ mod noop_method_call;
mod opaque_hidden_inferred_bound;
mod pass_by_value;
mod passes;
mod ptr_nulls;
mod redundant_semicolon;
mod reference_casting;
mod traits;
@ -102,7 +102,6 @@ use builtin::*;
use deref_into_dyn_supertrait::*;
use drop_forget_useless::*;
use enum_intrinsics_non_enums::EnumIntrinsicsNonEnums;
use fn_null_check::*;
use for_loops_over_fallibles::*;
use hidden_unicode_codepoints::*;
use internal::*;
@ -117,6 +116,7 @@ use nonstandard_style::*;
use noop_method_call::*;
use opaque_hidden_inferred_bound::*;
use pass_by_value::*;
use ptr_nulls::*;
use redundant_semicolon::*;
use reference_casting::*;
use traits::*;
@ -227,7 +227,7 @@ late_lint_methods!(
// Depends on types used in type definitions
MissingCopyImplementations: MissingCopyImplementations,
// Depends on referenced function signatures in expressions
IncorrectFnNullChecks: IncorrectFnNullChecks,
PtrNullChecks: PtrNullChecks,
MutableTransmutes: MutableTransmutes,
TypeAliasBounds: TypeAliasBounds,
TrivialConstraints: TrivialConstraints,

View file

@ -613,13 +613,13 @@ pub struct ExpectationNote {
pub rationale: Symbol,
}
// fn_null_check.rs
// ptr_nulls.rs
#[derive(LintDiagnostic)]
pub enum FnNullCheckDiag<'a> {
#[diag(lint_fn_null_check_fn_ptr)]
pub enum PtrNullChecksDiag<'a> {
#[diag(lint_ptr_null_checks_fn_ptr)]
#[help(lint_help)]
FnPtr,
#[diag(lint_fn_null_check_ref)]
#[diag(lint_ptr_null_checks_ref)]
Ref {
orig_ty: Ty<'a>,
#[label]

View file

@ -1,12 +1,12 @@
use crate::{lints::FnNullCheckDiag, LateContext, LateLintPass, LintContext};
use crate::{lints::PtrNullChecksDiag, LateContext, LateLintPass, LintContext};
use rustc_ast::LitKind;
use rustc_hir::{BinOpKind, Expr, ExprKind, TyKind};
use rustc_session::{declare_lint, declare_lint_pass};
use rustc_span::sym;
declare_lint! {
/// The `incorrect_fn_null_checks` lint checks for expression that checks if a
/// function pointer is null.
/// The `useless_ptr_null_checks` lint checks for useless null checks against pointers
/// obtained from non-null types.
///
/// ### Example
///
@ -22,16 +22,16 @@ declare_lint! {
///
/// ### Explanation
///
/// Function pointers are assumed to be non-null, checking them for null will always
/// return false.
INCORRECT_FN_NULL_CHECKS,
/// Function pointers and references are assumed to be non-null, checking them for null
/// will always return false.
USELESS_PTR_NULL_CHECKS,
Warn,
"incorrect checking of null function pointer"
"useless checking of non-null-typed pointer"
}
declare_lint_pass!(IncorrectFnNullChecks => [INCORRECT_FN_NULL_CHECKS]);
declare_lint_pass!(PtrNullChecks => [USELESS_PTR_NULL_CHECKS]);
fn incorrect_check<'a>(cx: &LateContext<'a>, expr: &Expr<'_>) -> Option<FnNullCheckDiag<'a>> {
fn incorrect_check<'a>(cx: &LateContext<'a>, expr: &Expr<'_>) -> Option<PtrNullChecksDiag<'a>> {
let mut expr = expr.peel_blocks();
let mut had_at_least_one_cast = false;
while let ExprKind::Cast(cast_expr, cast_ty) = expr.kind
@ -44,16 +44,16 @@ fn incorrect_check<'a>(cx: &LateContext<'a>, expr: &Expr<'_>) -> Option<FnNullCh
} else {
let orig_ty = cx.typeck_results().expr_ty(expr);
if orig_ty.is_fn() {
Some(FnNullCheckDiag::FnPtr)
Some(PtrNullChecksDiag::FnPtr)
} else if orig_ty.is_ref() {
Some(FnNullCheckDiag::Ref { orig_ty, label: expr.span })
Some(PtrNullChecksDiag::Ref { orig_ty, label: expr.span })
} else {
None
}
}
}
impl<'tcx> LateLintPass<'tcx> for IncorrectFnNullChecks {
impl<'tcx> LateLintPass<'tcx> for PtrNullChecks {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
match expr.kind {
// Catching:
@ -67,7 +67,7 @@ impl<'tcx> LateLintPass<'tcx> for IncorrectFnNullChecks {
)
&& let Some(diag) = incorrect_check(cx, arg) =>
{
cx.emit_spanned_lint(INCORRECT_FN_NULL_CHECKS, expr.span, diag)
cx.emit_spanned_lint(USELESS_PTR_NULL_CHECKS, expr.span, diag)
}
// Catching:
@ -80,12 +80,12 @@ impl<'tcx> LateLintPass<'tcx> for IncorrectFnNullChecks {
)
&& let Some(diag) = incorrect_check(cx, receiver) =>
{
cx.emit_spanned_lint(INCORRECT_FN_NULL_CHECKS, expr.span, diag)
cx.emit_spanned_lint(USELESS_PTR_NULL_CHECKS, expr.span, diag)
}
ExprKind::Binary(op, left, right) if matches!(op.node, BinOpKind::Eq) => {
let to_check: &Expr<'_>;
let diag: FnNullCheckDiag<'_>;
let diag: PtrNullChecksDiag<'_>;
if let Some(ddiag) = incorrect_check(cx, left) {
to_check = right;
diag = ddiag;
@ -103,7 +103,7 @@ impl<'tcx> LateLintPass<'tcx> for IncorrectFnNullChecks {
if let ExprKind::Lit(spanned) = cast_expr.kind
&& let LitKind::Int(v, _) = spanned.node && v == 0 =>
{
cx.emit_spanned_lint(INCORRECT_FN_NULL_CHECKS, expr.span, diag)
cx.emit_spanned_lint(USELESS_PTR_NULL_CHECKS, expr.span, diag)
},
// Catching:
@ -114,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for IncorrectFnNullChecks {
&& let Some(diag_item) = cx.tcx.get_diagnostic_name(def_id)
&& (diag_item == sym::ptr_null || diag_item == sym::ptr_null_mut) =>
{
cx.emit_spanned_lint(INCORRECT_FN_NULL_CHECKS, expr.span, diag)
cx.emit_spanned_lint(USELESS_PTR_NULL_CHECKS, expr.span, diag)
},
_ => {},