Skip to content

DST coercions are prevented by phantom data #26905

Closed
@Gankra

Description

@Gankra

This prevents Rc from having a sound definition with respect to dropcheck

#![feature(unsize, coerce_unsized)]

use std::marker::{Unsize, PhantomData};
use std::ops::CoerceUnsized;

struct MyRc<T: ?Sized> {
    ptr: *const T,
    _boo: PhantomData<T>,
}

impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<MyRc<U>> for MyRc<T>{ }

fn main() {}
<anon>:11:1: 11:77 error: the trait `CoerceUnsized` may only be implemented for a coercion between structures with one field being coerced, but 2 fields need coercions: ptr (*const T to *const U), _boo (core::marker::PhantomData<T> to core::marker::PhantomData<U>) [E0375]
<anon>:11 impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<MyRc<U>> for MyRc<T>{ }
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-DSTsArea: Dynamically-sized types (DSTs)P-highHigh priority

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions