mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 11:20:54 +00:00
Report calling unsafe fn pointer as unsafe
This commit is contained in:
parent
606cfeffa2
commit
9c27e0251c
@ -240,9 +240,15 @@ impl<'a> UnsafeVisitor<'a> {
|
||||
let inside_assignment = mem::replace(&mut self.inside_assignment, false);
|
||||
match expr {
|
||||
&Expr::Call { callee, .. } => {
|
||||
if let Some(func) = self.infer[callee].as_fn_def(self.db) {
|
||||
let callee = &self.infer[callee];
|
||||
if let Some(func) = callee.as_fn_def(self.db) {
|
||||
self.check_call(current, func);
|
||||
}
|
||||
if let TyKind::Function(fn_ptr) = callee.kind(Interner) {
|
||||
if fn_ptr.sig.safety == chalk_ir::Safety::Unsafe {
|
||||
self.on_unsafe_op(current.into(), UnsafetyReason::UnsafeFnCall);
|
||||
}
|
||||
}
|
||||
}
|
||||
Expr::Path(path) => {
|
||||
let guard =
|
||||
|
@ -862,6 +862,18 @@ fn bar() {
|
||||
fn baz() {
|
||||
foo();
|
||||
// ^^^^^ 💡 error: call to unsafe function is unsafe and requires an unsafe function or block
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unsafe_fn_ptr_call() {
|
||||
check_diagnostics(
|
||||
r#"
|
||||
fn f(it: unsafe fn()){
|
||||
it();
|
||||
// ^^^^ 💡 error: call to unsafe function is unsafe and requires an unsafe function or block
|
||||
}
|
||||
"#,
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user