x: *const [T], how would I write the equivalent of
&raw mut (*x)[i]?
How would you do that with
raw ? AFAICT, the array itself
[T] can be at an unaligned memory location (that is the
len and the
ptr of the
[T] are not properly aligned), and
(*x)[i] creates a
&self, which would be invalid right ?
why would that create a
@RalfJ because the
<[T] as IndexMut>::index_mut(&mut self) method is called, or isn't it?
&raw mut (*x)[i] as
&raw mut <[T] as IndexMut>::index_mut(*x: &mut [T], i)
or am I reading the parenthesis wrong, and that should be
<[T] as IndexMut>::index_mut(*x: &raw mut [T], i) ?
or do we have an
IndexRawMut::index_raw_mut(x: &raw mut self, i: usize) API ?
(&raw mut (*x))[i] expands to
<[T] as IndexRawMut>::index_raw_mut(&raw mut (*x), i): &raw mut T ?
I thought this was a hypothetical
IndexRawMut overload of the indexing operator for raw pointer slices
IndexMut does not get called when indexing a raw slice with a usize
(and we dont support indexing them with anything else)
So what gets called ?
The only thing I can think of is the _hypothetical_
IndexRawMut trait that @rkruppe mentions.
IIUC Ralf is saying nothing gets called, it's a compiler built-in
That sounds plausible
So it wouldn't be a
#[lang_item] + unstable trait in libcore ? (implementation-wise)
otherwise it would need to be implemented fairly different than
 overloads for all other types
This is no different to how
impl Add for i32 ends up boiling down to just
return self + rhs. Injecting built-in operations that precedes the general trait based overloading isn't super difficult.
indeed. MIR has a primitive operator to index a slice (works for raw slices and reference slices), just like it has a primitive operator for addition.