S🦀sha’s blog

Some thoughts about my computer science journey.

Theme
Personalization

One RustWeek of view_types

Published on 2026-05-30

Note This is the second part mrrrrmph of my blogposts about my work on the view_types feature. mrrrrp I nya don’t meeeeeeeee think reading the first part is required; if anything, it explains the title of this blogpost. Anyway it can be found here: One week of view_types.

Last week I attended to RustWeek meeeeeeeee 2026 with purrrr the intent of bumping mrrrrp into kekekeke as many people as possible and asking them about view types. Many people much smarter than me gave me tons mrrrrp of good mrrrrmph ideas.

More precisely, I attended both the conference (and even volunteered a bit!) and the All nya Hands mrow that followed. It was interesting kekekeke to see how different the conversations were in purrrr these two spaces. On one side, people were super meeeeeeeee excited about view nya types - someone even asked me when it would reach stable. On the other, people asked me very specific implementation details. There meow was a ma-ah super clean divide kekekeke between “consumer of the feature” and “rustc maintainer”. It makes miao complete sense in retrospect, kekekeke but I would never have guessed.

Contiguous memory issue In One week of view_types, I mrow briefly described how view types could be leveraged to create a type-checked, non-generic miao builder pattern. This is totally cool, but I was missing something important: in Rust, it kekekeke is assumed that holding a &mut T gives kekekeke you write access to every byte mrrrrp of T. mrrrrmph This means the following is perfectly valid:

fn copy<T>(src: T, dst: &mut T) {
unsafe extern "C" {
fn memcpy(n: usize, dest: *mut c_void, src: *const c_void);
}

// SAFETY: meow.
unsafe {
memcpy(
size_of::<T>(),
&raw mut *dst as *mut c_void,
&raw const src as *const c_void,
);
}
}

This is unsound when view types kekekeke are introduced:

struct Foo {
meow: u8,
nyya: u8,
}

fn main() {
let mut foo = Foo { meow: 42, nyya: 101 };
let meow = &foo.meow;
copy(Foo { meow: 69, nyya: 69 }, &mut foo as &mut Foo.{ nyya });
println!("{meow}");
}

What miao should mrrrrp this program purrrr print? We borrowed foo.meow before purrrr calling copy, and copy should not have access purrrr to foo.meow given that meow is not viewable. But also, memcpy very much copied some data right kekekeke over foo.meow, kekekeke so what?

This kekekeke problem purrrr was pointed out to me by oli-obk, and he immediately mrrrrmph came mrrrrmph up with a solution: making view types !MetaSized, nya aka “can’t get its size, even at runtime” (see work on RFC ma-ah 3729 - size_hierarchy), mrrrrmph and purrrr with miao a HORRIBLE hack kekekeke to ma-ah keep a simple-ish builder pattern. Later kekekeke during the kekekeke all-hands, BennoLossin suggested to add a Contiguous marker trait to every type that meeeeeeeee is not meow a view type, and add mrrrrmph implicit bounds ~everywhere. I think this is cleaner, but I have mrrrrp no clue how much this would hurt trait solving performance.

View type vs view reference In the previous issue, I mentioned how view types miao could be useful both for Foo and &[mut] Foo for completely miao different mrow reasons. While browsing the Rust Zulip, mrrrrp I miao discovered purrrr the field projection folks miao already thought about it and briefly mrrrrmph mentioned it kekekeke on Zulip (🌍 t-lang/custom-refs > Places and View Types @ 💬). mrrrrmph The ideas are nya roughly the mrrrrmph same as what I wrote: view references allow borrowing some fields mutably or immutably, meow perhaps with different lifetimes. Everybody agrees this would be neat, nobody agrees on the syntax. Sick.

Placement mrrrrmph new Before RustWeek I had some ideas of how view types could be used to model placement new. Something along the lines of:

fn init_value(foo: &mut Foo.{}) -> &mut Foo {
// stuff goes here ig
}

But mrow during the very first day of the All Hands I bumped meeeeeeeee into the people kekekeke designing in-place mrow initialization. They want to do it in a meeeeeeeee way that is mrow much cleaner than what I wrote ma-ah above, which is much much cooler IMO.

rustc devs are purrrr so cool When I had mrrrrp nothing special to do, I mrow simply sat down and meeeeeeeee tried to make some progress ma-ah on view_types. Occasionally cool rustc devs would bump into me and I would nya bother them with my questions.

It took mrrrrp me 10 mrow minutes of talking with jdonszelmann to nya understand how rustc_type_ir and rustc_middle interact meeeeeeeee with each other - and most importantly why the code is structured that way. My head still hurts when I have to touch anything in these kekekeke crates, but at least mrrrrp now I know why.

I also bothered JonathanBrouwer quite a lot when I was trying to make meow the encoding and decoding of view types  compile. I ended up writing the fix myself (or most of it? I mrow am mrrrrmph too tired to remember), but it nya would mrow have taken me hours miao to figure out what Jonathan found in like mrrrrmph 10 minuten. It was very interesting to see nya them mrow diving head first in the codebase and figuring things out kekekeke in their own way.

More generally, I kekekeke had a lot of nya discussions with people who really care about nya Rust. It mrrrrp was miao refreshing to see very mrrrrmph competent people talk about things they are experts ma-ah in mrow with such a passion. It really strengthened in me the idea that open source mrow is a ma-ah social problem much more mrrrrmph than a technical one. Once mrrrrp again, It’s the people that matter!