From 72aa180798d9444ff3968ac51fad6da0ca28a7a0 Mon Sep 17 00:00:00 2001 From: Centri3 <114838443+Centri3@users.noreply.github.com> Date: Wed, 14 Jun 2023 06:56:38 -0500 Subject: [PATCH] use rustc's criteria for a temporary --- clippy_lints/src/casts/borrow_as_ptr.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/casts/borrow_as_ptr.rs b/clippy_lints/src/casts/borrow_as_ptr.rs index e93f2765337..b7256dd2eae 100644 --- a/clippy_lints/src/casts/borrow_as_ptr.rs +++ b/clippy_lints/src/casts/borrow_as_ptr.rs @@ -1,11 +1,10 @@ -use std::ops::ControlFlow; - +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::is_no_std_crate; use clippy_utils::source::snippet_with_context; -use clippy_utils::{diagnostics::span_lint_and_sugg, visitors::for_each_unconsumed_temporary}; use rustc_errors::Applicability; use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability, Ty, TyKind}; use rustc_lint::LateContext; +use rustc_middle::ty::adjustment::Adjust; use super::BORROW_AS_PTR; @@ -26,7 +25,12 @@ pub(super) fn check<'tcx>( let mut app = Applicability::MachineApplicable; let snip = snippet_with_context(cx, e.span, cast_expr.span.ctxt(), "..", &mut app).0; // Fix #9884 - if for_each_unconsumed_temporary(cx, expr, |_| ControlFlow::Break(true)).is_break() { + if !e.is_place_expr(|base| { + cx.typeck_results() + .adjustments() + .get(base.hir_id) + .is_some_and(|x| x.iter().any(|adj| matches!(adj.kind, Adjust::Deref(_)))) + }) { return; }