Pre-RFC: Make `*CStr` a Thin Pointer

One more thing that needs to delay implementation of this. PR #46108 is going to introduce the DynSized trait, which will not be implemented for extern types, as required by RFC #1861.

The DynSized trait in the PR is currently just a marker trait, one cannot manually implement it and specify how the size and alignment can be computed (these are still handled in the compiler backend). This will break stable code that works today:

struct CStrTail {
    header: u8,
    tail: CStr, // will compile-error if CStr: !DynSized
}

So we need to be able to supply a custom DynSized implementation as a prerequisite:

impl DynSized for CStr {
    fn align_of_val(&self) -> usize { 1 }
    fn size_of_val(&self) -> usize { self.to_bytes_with_nul().len() }
}
3 Likes