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

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

Closed
arielb1 opened this Issue Apr 14, 2016 · 6 comments

Comments

Projects
None yet
3 participants
@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 label Apr 14, 2016

@arielb1

This comment has been minimized.

Copy link
Contributor Author

arielb1 commented Apr 14, 2016

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Apr 15, 2016

@arielb1 indeed.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Apr 15, 2016

triage: P-high

@arielb1

This comment has been minimized.

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

Rollup merge of rust-lang#33039 - bluss:trait-obj-error, r=arielb1
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

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Apr 18, 2016

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

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Apr 18, 2016

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

arielb1 added a commit to arielb1/rust that referenced this issue Apr 21, 2016

require the existential bounds of an object type to be object-safe
This is required, as Copy and Sized are object-unsafe.

Fixes rust-lang#32963

arielb1 added a commit to arielb1/rust that referenced this issue Apr 21, 2016

require the existential bounds of an object type to be object-safe
This is required, as Copy and Sized are object-unsafe.

Fixes rust-lang#32963

arielb1 added a commit to arielb1/rust that referenced this issue Apr 21, 2016

require the existential bounds of an object type to be object-safe
This is required, as Copy and Sized are object-unsafe.

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

Fixes rust-lang#32963

arielb1 added a commit to arielb1/rust that referenced this issue Apr 27, 2016

require the existential bounds of an object type to be object-safe
This is required, as Copy and Sized are object-unsafe.

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

Fixes rust-lang#32963

arielb1 added a commit to arielb1/rust that referenced this issue May 1, 2016

require the existential bounds of an object type to be object-safe
This is required, as Copy and Sized are object-unsafe.

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

Fixes rust-lang#32963

arielb1 added a commit to arielb1/rust that referenced this issue May 3, 2016

require the existential bounds of an object type to be object-safe
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

Auto merge of #33138 - arielb1:sized-shortcut, r=nikomatsakis
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

@bors bors closed this in #33138 May 6, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.