Skip to content

Commit cc98574

Browse files
committed
Fix comments, use constant instead of raw constant_context
1 parent 20f501a commit cc98574

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

clippy_lints/src/fn_null_check.rs

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ fn is_fn_ptr_cast(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
5656
impl<'tcx> LateLintPass<'tcx> for FnNullCheck {
5757
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
5858
match expr.kind {
59+
// Catching:
60+
// (fn_ptr as *<const/mut> <ty>).is_null()
5961
ExprKind::MethodCall(method_name, receiver, _, _)
6062
if method_name.ident.as_str() == "is_null" && is_fn_ptr_cast(cx, receiver) =>
6163
{

clippy_lints/src/transmute/transmute_null_to_fn.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clippy_utils::consts::{constant_context, Constant};
1+
use clippy_utils::consts::{constant, Constant};
22
use clippy_utils::diagnostics::span_lint_and_then;
33
use clippy_utils::{is_integer_literal, is_path_diagnostic_item};
44
use rustc_hir::{Expr, ExprKind};
@@ -25,12 +25,12 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, arg: &'t
2525
return false;
2626
}
2727

28-
// Catching:
29-
// transmute over constants that resolve to `null`.
30-
let mut const_eval_context = constant_context(cx, cx.typeck_results());
31-
3228
match arg.kind {
33-
ExprKind::Path(ref _qpath) if matches!(const_eval_context.expr(arg), Some(Constant::RawPtr(0))) => {
29+
// Catching:
30+
// transmute over constants that resolve to `null`.
31+
ExprKind::Path(ref _qpath)
32+
if matches!(constant(cx, cx.typeck_results(), arg), Some((Constant::RawPtr(0), _))) =>
33+
{
3434
lint_expr(cx, expr);
3535
true
3636
},

0 commit comments

Comments
 (0)