You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With #73986 having landed, one would expect something like this to work:
#![feature(raw_ref_op)]#![feature(slice_ptr_get)]structS{keys:[i32;2],}unsafefnget_last(s:*constS) -> i32{let keys = &rawconst(*s).keys;*keys.get_unchecked(1)}fnmain(){let s = S{keys:[24,42]};let p = &rawconst s;assert_eq!(unsafe{ get_last(p)},42);}
However, this fails saying
error[E0599]: no method named `get_unchecked` found for raw pointer `*const [i32; 2]` in the current scope
--> src/main.rs:11:11
|
11 | *keys.get_unchecked(1)
| ^^^^^^^^^^^^^ method not found in `*const [i32; 2]`
|
= 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
One has to add a *const [_] type annotation to force an unsizing coercion for this to work.
The text was updated successfully, but these errors were encountered:
@RalfJung The reason this currently doesn't work is that the compiler doesn't identify *const [T] as a supertype of *const [T;n]. This happens here, get_unchecked is actually considered as a candidate, but rejected because of the type relation.
I'm not sure how we should handle this, seems unlikely that this type relation should hold, but hasn't been implemented yet. If so should this call even work? Or would it be enough if we output an error suggestion for a coercion in this case?
Without this coercion, raw-ptr-as-self is unergonomic in yet another way. That's why I think the coercion should happen, at least in method receiver position.
With #73986 having landed, one would expect something like this to work:
However, this fails saying
One has to add a
*const [_]
type annotation to force an unsizing coercion for this to work.The text was updated successfully, but these errors were encountered: