Skip to content

NonCopyable as T for Copyable<T> cause it to be non-copyable #20806

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
qrlpx opened this issue Jan 9, 2015 · 1 comment
Closed

NonCopyable as T for Copyable<T> cause it to be non-copyable #20806

qrlpx opened this issue Jan 9, 2015 · 1 comment

Comments

@qrlpx
Copy link

qrlpx commented Jan 9, 2015

Non-copyable types as type parameters for copyable types cause them to be non-copyable.

struct NonCopyable(uint, uint);

#[derive(Copy)]
struct Copyable<T>(uint);

fn foo(c: Copyable<NonCopyable>){
    foo(c);
    foo(c);
}

fn main() {}

this results in

<anon>:8:9: 8:10 error: use of moved value: `c`
<anon>:8     foo(c);
                 ^
<anon>:7:9: 7:10 note: `c` moved here because it has type `Copyable<NonCopyable>`, which is non-copyable
<anon>:7     foo(c);

replacing T for Copyable with a copyable type, it compiles fine

#[derive(Copy)]
struct Copyable<T>(uint);

fn foo(c: Copyable<bool>){
    foo(c);
    foo(c);
}

fn main(){}

rustc 1.0.0-nightly (44a287e6e 2015-01-08 17:03:40 -0800)

@alexcrichton
Copy link
Member

Closing as a dupe of #7671 (dealing with phantom types and deriving).

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants