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

<Foo as Trait>::AssocType triggers non-Copy union check even when it is copy #90903

Closed
TheEdward162 opened this issue Nov 14, 2021 · 1 comment
Labels
C-bug Category: This is a bug.

Comments

@TheEdward162
Copy link

Hello, I ran into what I think is a bug with unions and type normalization.

trait Trait {
    type Assoc: Copy;
}

struct Foo;
impl Trait for Foo {
    type Assoc = u8;
}

union Bar {
    // The `Copy` bound on `Trait::Assoc` shouldn't even be required as this isn't even generic, the type is known to be `u8`
    foo: <Foo as Trait>::Assoc
}

// Ideally this is what Bar should normalize to
union Baz {
    foo: u8
}

Playground:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=b9c65cbec84f266463da8192cf7c2d21

I expected to see this happen: This should compile: <Foo as Trait>::Assoc is both bounded to be Copy and should normalize directly to u8 since it uses a concrete type.

Instead, this happened:

   Compiling playground v0.0.1 (/playground)
error[E0658]: unions with non-`Copy` fields other than `ManuallyDrop<T>` are unstable
  --> src/lib.rs:12:5
   |
12 |     foo: <Foo as Trait>::Assoc
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: see issue #55149 <https://github.com/rust-lang/rust/issues/55149> for more information

For more information about this error, try `rustc --explain E0658`.
error: could not compile `playground` due to previous error

Wrapping the type in ManuallyDrop does indeed work, and is a possible workaround for simple types, but I believe this should still work.

Meta

Stable 1.56.1 playground, happens on nightly 1.58.0-nightly (2021-11-13 b416e38) playground as well

Maybe this is connected to #81199? If I remove impl Trait for Foo it ICEs on stable and errors on nightly (i.e. fixed on nightly).

@TheEdward162 TheEdward162 added the C-bug Category: This is a bug. label Nov 14, 2021
@Dylan-DPC
Copy link
Member

Yeah this is fixed and no longer errors on stable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants