1
1
use clippy_utils:: diagnostics:: span_lint_and_sugg;
2
2
use clippy_utils:: source:: snippet_with_context;
3
- use clippy_utils:: std_or_core;
3
+ use clippy_utils:: { is_lint_allowed , std_or_core} ;
4
4
use rustc_errors:: Applicability ;
5
5
use rustc_hir:: { BorrowKind , Expr , ExprKind , Mutability , Ty , TyKind } ;
6
6
use rustc_lint:: LateContext ;
@@ -13,10 +13,11 @@ pub(super) fn check<'tcx>(
13
13
expr : & ' tcx Expr < ' _ > ,
14
14
cast_expr : & ' tcx Expr < ' _ > ,
15
15
cast_to : & ' tcx Ty < ' _ > ,
16
- ) {
16
+ ) -> bool {
17
17
if matches ! ( cast_to. kind, TyKind :: Ptr ( _) )
18
18
&& let ExprKind :: AddrOf ( BorrowKind :: Ref , mutability, e) = cast_expr. kind
19
19
&& let Some ( std_or_core) = std_or_core ( cx)
20
+ && !is_lint_allowed ( cx, BORROW_AS_PTR , expr. hir_id )
20
21
{
21
22
let macro_name = match mutability {
22
23
Mutability :: Not => "addr_of" ,
@@ -31,7 +32,7 @@ pub(super) fn check<'tcx>(
31
32
. get ( base. hir_id )
32
33
. is_some_and ( |x| x. iter ( ) . any ( |adj| matches ! ( adj. kind, Adjust :: Deref ( _) ) ) )
33
34
} ) {
34
- return ;
35
+ return false ;
35
36
}
36
37
37
38
span_lint_and_sugg (
@@ -43,5 +44,7 @@ pub(super) fn check<'tcx>(
43
44
format ! ( "{std_or_core}::ptr::{macro_name}!({snip})" ) ,
44
45
Applicability :: MachineApplicable ,
45
46
) ;
47
+ return true ;
46
48
}
49
+ false
47
50
}
0 commit comments