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

possible bug with borrowing and moving things into tasks #3684

Closed
erickt opened this issue Oct 6, 2012 · 1 comment
Closed

possible bug with borrowing and moving things into tasks #3684

erickt opened this issue Oct 6, 2012 · 1 comment

Comments

@erickt
Copy link
Contributor

erickt commented Oct 6, 2012

I was trying to help out @ben0x539 with some code of his: https://gist.github.com/3846368. He's messing around with moving a channel into a task, which is then passed to a closure. This fails with

foo.rs:5:56: 5:58 error: copying a noncopyable value
foo.rs:5         let fail_: fn~(~str) -> ! = fn~(x: ~str) -> ! { wr.send(x); fail; };
                                                                 ^~
foo.rs:5:56: 5:58 note: non-copyable value cannot be copied into a ~fn closure
foo.rs:5         let fail_: fn~(~str) -> ! = fn~(x: ~str) -> ! { wr.send(x); fail; };

However, if we get rid of the task, it works fine. I would have thought that moving the channel into the task would be roughly equivalent to the non-task version, but I'm probably missing some subtly in the borrower.

In the meantime, you can use pipes::SharedChan to write this kind of function.

@nikomatsakis
Copy link
Contributor

This is a dup of #2549. Basically the problem here is that you cannot move out of upvars right now, because Rust function types always assume they may be called more than once. To work around this, you must either use a channel to send the value to the task (rather than capturing it via an upvar) or use the so-called "option dance". Hopefully this will be fixed in 0.5.

bors pushed a commit to rust-lang-ci/rust that referenced this issue May 15, 2021
RalfJung pushed a commit to RalfJung/rust that referenced this issue Jun 29, 2024
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

No branches or pull requests

2 participants