Skip to content

The trait object Foo+Copy implements the trait Copy #32963

New issue

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

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

Already on GitHub? # to your account

Closed
arielb1 opened this issue Apr 14, 2016 · 6 comments · Fixed by #33138
Closed

The trait object Foo+Copy implements the trait Copy #32963

arielb1 opened this issue Apr 14, 2016 · 6 comments · Fixed by #33138
Assignees
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@arielb1
Copy link
Contributor

arielb1 commented Apr 14, 2016

select considers the trait object type Foo+Copy to implement the trait Copy, and therefore its supertraits Clone and Sized. This is totally bogus, as the trait object type is not Sized.

For example:

use std::{fmt, mem};

fn size_of_copy<T: Copy+?Sized>() -> usize { mem::size_of::<T>() }

fn main() {
    println!("{}", size_of_copy::<fmt::Debug+Copy>());
}

This obviously should not compile, but it does (and prints 16, because of the size_of unsized hack).

@arielb1 arielb1 added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Apr 14, 2016
@arielb1
Copy link
Contributor Author

arielb1 commented Apr 14, 2016

cc @nikomatsakis

@nikomatsakis
Copy link
Contributor

@arielb1 indeed.

@nikomatsakis nikomatsakis added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 15, 2016
@nikomatsakis
Copy link
Contributor

triage: P-high

@rust-highfive rust-highfive added the P-high High priority label Apr 15, 2016
@arielb1
Copy link
Contributor Author

arielb1 commented Apr 16, 2016

I am working on a fix.

Manishearth added a commit to Manishearth/rust that referenced this issue Apr 17, 2016
Adjust example for error E0225

Adjust example for error E0225

It's using Copy as a trait object compatible trait, which is not
appropriate, change to use a more typical Read + Send + Sync example.

Also use whitespace around `+`.

This seems appropriate apropos issue rust-lang#32963
@nikomatsakis
Copy link
Contributor

@arielb1 saw your ping on IRC; it seems like we simply should consider Copy to be object-unsafe. Ideally with a warning period.

@nikomatsakis
Copy link
Contributor

(I've always thought that unsized types would be move-only.)

arielb1 added a commit to arielb1/rust that referenced this issue May 3, 2016
This is required, as Copy and Sized are object-unsafe.

As a soundness fix, this is a [breaking-change]

Fixes rust-lang#32963
bors added a commit that referenced this issue May 6, 2016
Short-cut `T: Sized` trait selection for ADTs

Basically avoids all nested obligations when checking whether an ADT is sized - this speeds up typeck by ~15%

The refactoring fixed #32963, but I also want to make `Copy` not object-safe (will commit that soon).

Fixes #33201

r? @nikomatsakis
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants