diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:48 +0000 |
commit | ef24de24a82fe681581cc130f342363c47c0969a (patch) | |
tree | 0d494f7e1a38b95c92426f58fe6eaa877303a86c /compiler/rustc_lint/src/ptr_nulls.rs | |
parent | Releasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip |
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_lint/src/ptr_nulls.rs')
-rw-r--r-- | compiler/rustc_lint/src/ptr_nulls.rs | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/compiler/rustc_lint/src/ptr_nulls.rs b/compiler/rustc_lint/src/ptr_nulls.rs index 0de72d8d3..4ac8a5ceb 100644 --- a/compiler/rustc_lint/src/ptr_nulls.rs +++ b/compiler/rustc_lint/src/ptr_nulls.rs @@ -46,22 +46,26 @@ fn incorrect_check<'a, 'tcx: 'a>( if let ExprKind::MethodCall(_, _expr, [], _) = e.kind && let Some(def_id) = cx.typeck_results().type_dependent_def_id(e.hir_id) && cx.tcx.has_attr(def_id, sym::rustc_never_returns_null_ptr) - && let Some(fn_name) = cx.tcx.opt_item_ident(def_id) { + && let Some(fn_name) = cx.tcx.opt_item_ident(def_id) + { return Some(PtrNullChecksDiag::FnRet { fn_name }); } else if let ExprKind::Call(path, _args) = e.kind && let ExprKind::Path(ref qpath) = path.kind && let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id() && cx.tcx.has_attr(def_id, sym::rustc_never_returns_null_ptr) - && let Some(fn_name) = cx.tcx.opt_item_ident(def_id) { + && let Some(fn_name) = cx.tcx.opt_item_ident(def_id) + { return Some(PtrNullChecksDiag::FnRet { fn_name }); } e = if let ExprKind::Cast(expr, t) = e.kind - && let TyKind::Ptr(_) = t.kind { + && let TyKind::Ptr(_) = t.kind + { had_at_least_one_cast = true; expr } else if let ExprKind::MethodCall(_, expr, [], _) = e.kind && let Some(def_id) = cx.typeck_results().type_dependent_def_id(e.hir_id) - && matches!(cx.tcx.get_diagnostic_name(def_id), Some(sym::ptr_cast | sym::ptr_cast_mut)) { + && matches!(cx.tcx.get_diagnostic_name(def_id), Some(sym::ptr_cast | sym::ptr_cast_mut)) + { had_at_least_one_cast = true; expr } else if had_at_least_one_cast { @@ -127,10 +131,11 @@ impl<'tcx> LateLintPass<'tcx> for PtrNullChecks { // (fn_ptr as *<const/mut> <ty>) == (0 as <ty>) ExprKind::Cast(cast_expr, _) if let ExprKind::Lit(spanned) = cast_expr.kind - && let LitKind::Int(v, _) = spanned.node && v == 0 => + && let LitKind::Int(v, _) = spanned.node + && v == 0 => { cx.emit_spanned_lint(USELESS_PTR_NULL_CHECKS, expr.span, diag) - }, + } // Catching: // (fn_ptr as *<const/mut> <ty>) == std::ptr::null() @@ -141,9 +146,9 @@ impl<'tcx> LateLintPass<'tcx> for PtrNullChecks { && (diag_item == sym::ptr_null || diag_item == sym::ptr_null_mut) => { cx.emit_spanned_lint(USELESS_PTR_NULL_CHECKS, expr.span, diag) - }, + } - _ => {}, + _ => {} } } _ => {} |