File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
src/tools/rust-analyzer/crates
ide-diagnostics/src/handlers Expand file tree Collapse file tree 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> {
240240 let inside_assignment = mem:: replace ( & mut self . inside_assignment , false ) ;
241241 match expr {
242242 & 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 ) {
244245 self . check_call ( current, func) ;
245246 }
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+ }
246252 }
247253 Expr :: Path ( path) => {
248254 let guard =
Original file line number Diff line number Diff line change @@ -862,6 +862,18 @@ fn bar() {
862862fn baz() {
863863 foo();
864864 // ^^^^^ 💡 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
865877}
866878 "# ,
867879 ) ;
You can’t perform that action at this time.
0 commit comments