using librustc fails when trying to compile a second time #19371

Closed
jaredly opened this Issue Nov 28, 2014 · 6 comments

Projects

None yet

3 participants

@jaredly
jaredly commented Nov 28, 2014

The first time it works just fine, but it seems there's some global state somewhere that's messing with the parser. Here's the code: http://is.gd/K0dYsK

The main looks like:

fn main() {
    println!("Start");
    let src = "fn main() { println!(\"Awesome\"); }".to_string();

    let out = Path::new("/tmp/awesome".to_string());

    compile(src.clone(), out.clone(), None);

    println!("[[first worked]]");

    //this should work too, but it seems there's some state being held on to somewere, in the parser?
    compile(src.clone(), out.clone(), None);

    println!("[[second worked]]")
}

And the error is:

<anon>:1:1: 1:3 error: expected item, found `fn`
<anon>:1 fn main() { println!("Awesome"); }
         ^~
task '<main>' panicked at 'Box<Any>', /build/rust-git/src/rust/src/libsyntax/diagnostic.rs:86
playpen: application terminated with error code 101
@nrc
Contributor
nrc commented Nov 28, 2014
@murarth
Contributor
murarth commented Nov 29, 2014

I ran into this same issue not too long ago. There are two instances of thread-local data that are used in compilation. I can submit a PR for a fix, but the workaround is easy: As the data are thread-local, you can run each compile function in a separate task.

@nrc
Contributor
nrc commented Nov 29, 2014

@murarth it would be great to have a fix if you have the time to put a PR together

@murarth
Contributor
murarth commented Nov 29, 2014

@nick29581 No problem. I'm not sure about writing a test, though. How do I find sysroot from the test program?

@nrc
Contributor
nrc commented Nov 29, 2014

@murarth I don't think you need it - you could have a makefile test which does something similar to @jaredly's example code and just check it doesn't panic

@bors bors closed this in 8d8f41b Nov 29, 2014
@jaredly
jaredly commented Nov 30, 2014

Sweet thanks!

On Sat, Nov 29, 2014, 4:47 PM bors notifications@github.com wrote:

Closed #19371 #19371 via 8d8f41b
8d8f41b
.


Reply to this email directly or view it on GitHub
#19371 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment