File tree 2 files changed +19
-1
lines changed
src/tools/rust-analyzer/crates
ide-diagnostics/src/handlers
2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -240,9 +240,15 @@ impl<'a> UnsafeVisitor<'a> {
240
240
let inside_assignment = mem:: replace ( & mut self . inside_assignment , false ) ;
241
241
match expr {
242
242
& Expr :: Call { callee, .. } => {
243
- if let Some ( func) = self . infer [ callee] . as_fn_def ( self . db ) {
243
+ let callee = & self . infer [ callee] ;
244
+ if let Some ( func) = callee. as_fn_def ( self . db ) {
244
245
self . check_call ( current, func) ;
245
246
}
247
+ if let TyKind :: Function ( fn_ptr) = callee. kind ( Interner ) {
248
+ if fn_ptr. sig . safety == chalk_ir:: Safety :: Unsafe {
249
+ self . on_unsafe_op ( current. into ( ) , UnsafetyReason :: UnsafeFnCall ) ;
250
+ }
251
+ }
246
252
}
247
253
Expr :: Path ( path) => {
248
254
let guard =
Original file line number Diff line number Diff line change @@ -862,6 +862,18 @@ fn bar() {
862
862
fn baz() {
863
863
foo();
864
864
// ^^^^^ 💡 error: call to unsafe function is unsafe and requires an unsafe function or block
865
+ }
866
+ "# ,
867
+ ) ;
868
+ }
869
+
870
+ #[ test]
871
+ fn unsafe_fn_ptr_call ( ) {
872
+ check_diagnostics (
873
+ r#"
874
+ fn f(it: unsafe fn()){
875
+ it();
876
+ // ^^^^ 💡 error: call to unsafe function is unsafe and requires an unsafe function or block
865
877
}
866
878
"# ,
867
879
) ;
You can’t perform that action at this time.
0 commit comments