Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsize isn't implemented for unions #48863

Open
sfackler opened this issue Mar 9, 2018 · 2 comments
Open

Unsize isn't implemented for unions #48863

sfackler opened this issue Mar 9, 2018 · 2 comments
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. needs-rfc This change is large or controversial enough that it should have an RFC accepted before doing it. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@sfackler
Copy link
Member

sfackler commented Mar 9, 2018

This came up in the fix for #48493. It seems like unions should have unsize impls for all of their fields?

#![feature(untagged_unions, unsize, coerce_unsized)]
use std::marker::Unsize;
use std::ops::CoerceUnsized;

union Data<T: ?Sized> {
    v: T,
    u: (),
}

struct Pointer<T: ?Sized>(Box<Data<T>>);

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

fn main() {}
error[E0277]: the trait bound `Data<T>: std::marker::Unsize<Data<U>>` is not satisfied
  --> src/main.rs:12:1
   |
12 | impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Pointer<U>> for Pointer<T> {}
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Unsize<Data<U>>` is not implemented for `Data<T>`
   |
   = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<std::boxed::Box<Data<U>>>` for `std::boxed::Box<Data<T>>`

error: aborting due to previous error

If you want more information on this error, try using "rustc --explain E0277"
error: Could not compile `playground`.

To learn more, run the command again with --verbose.
@kennytm
Copy link
Member

kennytm commented Mar 9, 2018

Please check the discussion in #47650.

@sfackler
Copy link
Member Author

sfackler commented Mar 9, 2018

Ah thanks!

@pietroalbini pietroalbini added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 13, 2018
@Dylan-DPC Dylan-DPC added the needs-rfc This change is large or controversial enough that it should have an RFC accepted before doing it. label Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. needs-rfc This change is large or controversial enough that it should have an RFC accepted before doing it. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants