Today, I wrote some rust code exercise, learning about const knowledge, every thing goes well, except the const raw pointer.
Below is the code snippet
const FOO_PTR: *const FOO = &FOO {} as *const FOO;
struct FOO {}
fn main() {
}
impl Drop for FOO {
fn drop(&mut self) {
println!("FOO drop");
}
}
compile it, and I got
error: untyped pointers are not allowed in constant
--> src\main.rs:11:1
|
11 | const FOO_PTR: *const FOO = &FOO {} as *const FOO;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
If I remove the Drop implement code, it compiles success.
Does anyone know what's going there?