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

Some objects get zeroed when copied from, affecting original object #22536

Closed
bvssvni opened this issue Feb 19, 2015 · 12 comments · Fixed by #22818
Closed

Some objects get zeroed when copied from, affecting original object #22536

bvssvni opened this issue Feb 19, 2015 · 12 comments · Fixed by #22818
Assignees
Milestone

Comments

@bvssvni
Copy link

bvssvni commented Feb 19, 2015

rustc 1.0.0-nightly (6c065fc8c 2015-02-17) (built 2015-02-18)

From gfx-rs/gfx#574

In Gfx, something happens when *buffer (BufferHandle) is called, which zeroes whole or parts of the original object.

This might be a compiler bug.

cc @csherratt @kvark

@kvark
Copy link
Contributor

kvark commented Feb 19, 2015

Also see the workaround by @csherratt in PistonDevelopers/gfx_graphics#136

@kvark
Copy link
Contributor

kvark commented Feb 19, 2015

I managed to extract and simplify the case:

trait Resources {
    type Buffer: Copy;
}

struct BufferHandle<R: Resources> {
    raw: <R as Resources>::Buffer,
}
impl<R: Resources> Copy for BufferHandle<R> {}

#[derive(Copy)]
enum Res {}
impl Resources for Res {
    type Buffer = u32;
}

fn main() {
    let b: BufferHandle<Res> = BufferHandle { raw: 1 };
    let c = b;
    print!("{}{}", c.raw, b.raw);
}

Prints: 10

@alexcrichton
Copy link
Member

cc @nikomatsakis, @pnkfelix, looks like an associated type bug. Thanks @kvark for the reduction!

Also nominating.

@nikomatsakis
Copy link
Contributor

Will investigate.

@nikomatsakis
Copy link
Contributor

And yes, thanks @kvark !

@dotdash
Copy link
Contributor

dotdash commented Feb 19, 2015

https://github.com/rust-lang/rust/blob/master/src/librustc/middle/ty.rs#L3594 -- I guess if BoundCopy is present, that should remove TC::NeedsDrop?

@kvark
Copy link
Contributor

kvark commented Feb 23, 2015

I'm sorry, is there any progress on this one? We are considering switching everything to clone() (in gfx-rs) as a workaround, and that would be pretty inconvenient, not to mention the work wasted...

@bvssvni
Copy link
Author

bvssvni commented Feb 24, 2015

This is the only bug that blocks Piston at the moment, but it does across several projects. Is there a way I can help?

@pnkfelix pnkfelix self-assigned this Feb 24, 2015
@brson
Copy link
Contributor

brson commented Feb 25, 2015

@kvark @bvssvni No progress yet, but @pnkfelix and @nikomatsakis will solve it soon, I just know it!

@pnkfelix
Copy link
Member

@kvark @bvssvni I have a plausible fix. I will hopefully put up a pull request with it tomorrow.

@bvssvni
Copy link
Author

bvssvni commented Feb 25, 2015

@pnkfelix You are awesome!

@pnkfelix
Copy link
Member

P-backcompat-lang, 1.0

@pnkfelix pnkfelix added this to the 1.0 milestone Feb 26, 2015
Manishearth added a commit to Manishearth/rust that referenced this issue Feb 27, 2015
…sakis

 Ensure we do not zero when \"moving\" types that are Copy.

Uses more precise `type_needs_drop` for deciding about emitting cleanup code.  Added notes about the weaknesses regarding `ty::type_contents` here.

Fix rust-lang#22536
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants