Add #[rustc_never_returns_null_ptr]

And look for it in the useless_ptr_null_checks lint
This commit is contained in:
est31 2023-08-05 04:54:23 +02:00
parent e173a8e663
commit 8cfa4fe6b2
4 changed files with 9 additions and 1 deletions

View file

@ -49,7 +49,7 @@ fn ptr_cast_chain<'a>(cx: &'a LateContext<'_>, mut e: &'a Expr<'a>) -> Option<&'
} else if let ExprKind::Call(path, [arg]) = e.kind
&& let ExprKind::Path(ref qpath) = path.kind
&& let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id()
&& matches!(cx.tcx.get_diagnostic_name(def_id), Some(sym::ptr_from_ref | sym::ptr_from_mut)) {
&& cx.tcx.has_attr(def_id, sym::rustc_never_returns_null_ptr) {
had_at_least_one_cast = true;
arg
} else if had_at_least_one_cast {