@@ -14,7 +14,8 @@ use hir_def::{
14
14
} ;
15
15
16
16
use 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 ,
18
19
} ;
19
20
20
21
/// Returns `(unsafe_exprs, fn_is_unsafe)`.
@@ -96,6 +97,7 @@ struct UnsafeVisitor<'a> {
96
97
inside_assignment : bool ,
97
98
inside_union_destructure : bool ,
98
99
unsafe_expr_cb : & ' a mut dyn FnMut ( ExprOrPatId , InsideUnsafeBlock , UnsafetyReason ) ,
100
+ def_target_features : TargetFeatures ,
99
101
}
100
102
101
103
impl < ' a > UnsafeVisitor < ' a > {
@@ -107,6 +109,10 @@ impl<'a> UnsafeVisitor<'a> {
107
109
unsafe_expr_cb : & ' a mut dyn FnMut ( ExprOrPatId , InsideUnsafeBlock , UnsafetyReason ) ,
108
110
) -> Self {
109
111
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
+ } ;
110
116
Self {
111
117
db,
112
118
infer,
@@ -117,6 +123,7 @@ impl<'a> UnsafeVisitor<'a> {
117
123
inside_assignment : false ,
118
124
inside_union_destructure : false ,
119
125
unsafe_expr_cb,
126
+ def_target_features,
120
127
}
121
128
}
122
129
@@ -181,7 +188,7 @@ impl<'a> UnsafeVisitor<'a> {
181
188
match expr {
182
189
& Expr :: Call { callee, .. } => {
183
190
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 ) {
185
192
self . call_cb ( current. into ( ) , UnsafetyReason :: UnsafeFnCall ) ;
186
193
}
187
194
}
@@ -212,7 +219,7 @@ impl<'a> UnsafeVisitor<'a> {
212
219
if self
213
220
. infer
214
221
. 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 ) )
216
223
. unwrap_or ( false )
217
224
{
218
225
self . call_cb ( current. into ( ) , UnsafetyReason :: UnsafeFnCall ) ;
0 commit comments