Closed
Description
Using nightly 2020-12-03, this doesn't build: (play link)
#![feature(arbitrary_self_types)]
struct Test {}
impl Test {
fn x(self: *const Self) {}
}
fn main() {
let ptr: *mut Test = std::ptr::null_mut();
ptr.x();
}
Error:
error[E0599]: no method named `x` found for raw pointer `*mut Test` in the current scope
--> src/main.rs:11:9
|
11 | ptr.x();
| ^ method not found in `*mut Test`
|
= 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
error: aborting due to previous error
I think similar to how &self
methods can be called on &mut
references, *const Self
methods should be allowed to be called on *mut
pointers.