Skip to content

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

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
jaredly opened this issue Nov 28, 2014 · 6 comments
Closed

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

jaredly opened this issue Nov 28, 2014 · 6 comments
Labels
A-parser Area: The lexing & parsing of Rust source code to an AST

Comments

@jaredly
Copy link

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
Copy link
Member

nrc commented Nov 28, 2014

cc @nick29581

@nrc nrc added A-build A-parser Area: The lexing & parsing of Rust source code to an AST labels Nov 28, 2014
@murarth
Copy link
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
Copy link
Member

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
Copy link
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
Copy link
Member

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

@jaredly
Copy link
Author

jaredly commented Nov 30, 2014

Sweet thanks!

On Sat, Nov 29, 2014, 4:47 PM bors [email protected] 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
Labels
A-parser Area: The lexing & parsing of Rust source code to an AST
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants