Skip to content

Compiler allows repeated moves out of a captured variable in a proc() #10829

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

Closed
TisButMe opened this issue Dec 5, 2013 · 4 comments
Closed
Labels
A-type-system Area: Type system

Comments

@TisButMe
Copy link

TisButMe commented Dec 5, 2013

When running this code:
https://gist.github.com/TisButMe/74c121d98ef3fe00bfa9

The second time you enter an input to stdin, the program segfaults:

Segmentation fault (core dumped)

Sample input:

$./Client
If you're happy and you know it
Segfault!
Segmentation fault (core dumped)

Removing

writer.flush();

stops the segfault, but nothing gets written anymore (surprisingly...).

For testing purposes, here is the code to the server used:
https://gist.github.com/TisButMe/16999f80db443dfe4df8

This issue has been discovered on Ubuntu 13.04, using the master downloaded and compiled on 5 Dec.13

@alexcrichton
Copy link
Member

The good news is that this is not a bug in I/O. The bad news is that this is a bug in the compiler. I've simplified the program you have into this:

fn foo(_: ~int) {}  

fn main() {         
    let a = ~2;     
    do spawn {      
        loop {      
            foo(a); 
        }           
    }               
}                   

This program should not compile because it is repeatedly moving out of the local variable a. Your program should not compile either because you are repeatedly moving out of stream.

@alexcrichton
Copy link
Member

Updated title to the actual bug, and cc @nikomatsakis

@ben0x539
Copy link
Contributor

ben0x539 commented Dec 5, 2013

Same bug as #10398?

@alexcrichton
Copy link
Member

Looks like it, thanks!

Closing as a dupe (but will mention the code on the other bug).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system
Projects
None yet
Development

No branches or pull requests

3 participants