Closed
Description
Given the following code:
fn main() {
let p: *mut () = std::ptr::null_mut();
p.as_mut_ref();
}
(I don't know why to this day, I still type as_mut_ret
... it's beyond me...)
The current output is:
error[E0599]: no method named `as_mut_ref` found for raw pointer `*mut ()` in the current scope
--> src/main.rs:3:7
|
3 | p.as_mut_ref();
| ^^^^^^^^^^ method not found in `*mut ()`
|
= note: try using `<*const T>::as_ref()` to get a reference to the type behind the pointer: https://doc.rust-lang.org/std/primitive.pointer.html#method.as_ref
= note: using `<*const T>::as_ref()` on a pointer which is unaligned or points to invalid or uninitialized memory is undefined behavior
The note is misleading in two ways:
- it's suggesting a method on
*const T
, when it should be a method on*mut T
. - it's suggesting
as_ref
while it should beas_mut
.