11use clippy_utils:: diagnostics:: span_lint_and_sugg;
22use clippy_utils:: source:: snippet_with_context;
3- use clippy_utils:: std_or_core;
3+ use clippy_utils:: { is_lint_allowed , std_or_core} ;
44use rustc_errors:: Applicability ;
55use rustc_hir:: { BorrowKind , Expr , ExprKind , Mutability , Ty , TyKind } ;
66use rustc_lint:: LateContext ;
@@ -13,10 +13,11 @@ pub(super) fn check<'tcx>(
1313 expr : & ' tcx Expr < ' _ > ,
1414 cast_expr : & ' tcx Expr < ' _ > ,
1515 cast_to : & ' tcx Ty < ' _ > ,
16- ) {
16+ ) -> bool {
1717 if matches ! ( cast_to. kind, TyKind :: Ptr ( _) )
1818 && let ExprKind :: AddrOf ( BorrowKind :: Ref , mutability, e) = cast_expr. kind
1919 && let Some ( std_or_core) = std_or_core ( cx)
20+ && !is_lint_allowed ( cx, BORROW_AS_PTR , expr. hir_id )
2021 {
2122 let macro_name = match mutability {
2223 Mutability :: Not => "addr_of" ,
@@ -31,7 +32,7 @@ pub(super) fn check<'tcx>(
3132 . get ( base. hir_id )
3233 . is_some_and ( |x| x. iter ( ) . any ( |adj| matches ! ( adj. kind, Adjust :: Deref ( _) ) ) )
3334 } ) {
34- return ;
35+ return false ;
3536 }
3637
3738 span_lint_and_sugg (
@@ -43,5 +44,7 @@ pub(super) fn check<'tcx>(
4344 format ! ( "{std_or_core}::ptr::{macro_name}!({snip})" ) ,
4445 Applicability :: MachineApplicable ,
4546 ) ;
47+ return true ;
4648 }
49+ false
4750}
0 commit comments