@@ -14,7 +14,8 @@ use hir_def::{
1414} ;
1515
1616use crate :: {
17- db:: HirDatabase , utils:: is_fn_unsafe_to_call, InferenceResult , Interner , TyExt , TyKind ,
17+ db:: HirDatabase , utils:: is_fn_unsafe_to_call, InferenceResult , Interner , TargetFeatures , TyExt ,
18+ TyKind ,
1819} ;
1920
2021/// Returns `(unsafe_exprs, fn_is_unsafe)`.
@@ -96,6 +97,7 @@ struct UnsafeVisitor<'a> {
9697 inside_assignment : bool ,
9798 inside_union_destructure : bool ,
9899 unsafe_expr_cb : & ' a mut dyn FnMut ( ExprOrPatId , InsideUnsafeBlock , UnsafetyReason ) ,
100+ def_target_features : TargetFeatures ,
99101}
100102
101103impl < ' a > UnsafeVisitor < ' a > {
@@ -107,6 +109,10 @@ impl<'a> UnsafeVisitor<'a> {
107109 unsafe_expr_cb : & ' a mut dyn FnMut ( ExprOrPatId , InsideUnsafeBlock , UnsafetyReason ) ,
108110 ) -> Self {
109111 let resolver = def. resolver ( db. upcast ( ) ) ;
112+ let def_target_features = match def {
113+ DefWithBodyId :: FunctionId ( func) => TargetFeatures :: from_attrs ( & db. attrs ( func. into ( ) ) ) ,
114+ _ => TargetFeatures :: default ( ) ,
115+ } ;
110116 Self {
111117 db,
112118 infer,
@@ -117,6 +123,7 @@ impl<'a> UnsafeVisitor<'a> {
117123 inside_assignment : false ,
118124 inside_union_destructure : false ,
119125 unsafe_expr_cb,
126+ def_target_features,
120127 }
121128 }
122129
@@ -181,7 +188,7 @@ impl<'a> UnsafeVisitor<'a> {
181188 match expr {
182189 & Expr :: Call { callee, .. } => {
183190 if let Some ( func) = self . infer [ callee] . as_fn_def ( self . db ) {
184- if is_fn_unsafe_to_call ( self . db , func) {
191+ if is_fn_unsafe_to_call ( self . db , func, & self . def_target_features ) {
185192 self . call_cb ( current. into ( ) , UnsafetyReason :: UnsafeFnCall ) ;
186193 }
187194 }
@@ -212,7 +219,7 @@ impl<'a> UnsafeVisitor<'a> {
212219 if self
213220 . infer
214221 . method_resolution ( current)
215- . map ( |( func, _) | is_fn_unsafe_to_call ( self . db , func) )
222+ . map ( |( func, _) | is_fn_unsafe_to_call ( self . db , func, & self . def_target_features ) )
216223 . unwrap_or ( false )
217224 {
218225 self . call_cb ( current. into ( ) , UnsafetyReason :: UnsafeFnCall ) ;
0 commit comments