Code
fn oopsie_woopsie_uwu(ptr: *mut u32) {
unsafe { ptr.write(123); }
}
fn main() {
oopsie_woopsie_uwu(0 as _);
}
Current output
Desired output
warning: call to function `std::ptr::mut_ptr::<impl *mut T>::write` is unsafe but the pointer is an argument of a safe function
--> src/main.rs:2:7
|
1 | fn oopsie_woopsie_uwu(ptr: *mut u32) {
| ^^^^^^^^^^^^^
| argument declared here
|
2 | { ptr.write(123); }
| ^^^^^^^^^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior
Rationale and extra context
I propose a simple lint warning the developer that the function should be marked unsafe, otherwise preconditions are easily ignored. For now this should only include integers (unchecked_* functions) and pointers (read, write, arithmetic). It should not include struct fields unless the field is marked as pub and is mutable.
It could also include FFI functions that accept a pointer but are marked as safe.
Other cases
Rust Version
Anything else?
No response
Code
Current output
Desired output
Rationale and extra context
I propose a simple lint warning the developer that the function should be marked unsafe, otherwise preconditions are easily ignored. For now this should only include integers (
unchecked_*functions) and pointers (read, write, arithmetic). It should not include struct fields unless the field is marked aspuband is mutable.It could also include FFI functions that accept a pointer but are marked as safe.
Other cases
Rust Version
Anything else?
No response