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

Alternating error messages when compiling the same source #15034

Closed
boschni opened this issue Jun 19, 2014 · 1 comment
Closed

Alternating error messages when compiling the same source #15034

boschni opened this issue Jun 19, 2014 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@boschni
Copy link

boschni commented Jun 19, 2014

I'm getting alternating error messages when compiling the following source multiple times:

pub struct Lexer<'a> {
    input: &'a str,
}

impl<'a> Lexer<'a> {
    pub fn new<'a>(input: &'a str) -> Lexer<'a> {
        Lexer { input: input }
    }
}

struct Parser<'a> {
    lexer: &'a mut Lexer<'a>,
}

impl<'a> Parser<'a> {
    pub fn new<'a>(lexer: &'a mut Lexer) -> Parser<'a> {
        Parser { lexer: lexer }
    }
}

fn main() {}

First error message:

$ rustc test.rs
test.rs:20:2: 25:3 note: consider using an explicit lifetime parameter as shown: fn new<'a>(lexer: &'a mut Lexer<'a>) -> Parser<'a>
test.rs:20  pub fn new<'a>(lexer: &'a mut Lexer) -> Parser<'a> {
test.rs:21 
test.rs:22      Parser {
test.rs:23          lexer: lexer,
test.rs:24      }
test.rs:25  }
test.rs:22:3: 24:4 error: cannot infer an appropriate lifetime for lifetime parameter `'a due to conflicting requirements
test.rs:22      Parser {
test.rs:23          lexer: lexer,
test.rs:24      }
error: aborting due to previous error

Second error message:

$ rustc test.rs
test.rs:22:3: 24:4 error: cannot infer an appropriate lifetime for lifetime parameter `'a due to conflicting requirements
test.rs:22      Parser {
test.rs:23          lexer: lexer,
test.rs:24      }
test.rs:23:11: 23:16 note: first, the lifetime cannot outlive the expression at 23:10...
test.rs:23          lexer: lexer,
                           ^~~~~
test.rs:23:11: 23:16 note: ...so that automatically reference is valid at the time of borrow
test.rs:23          lexer: lexer,
                           ^~~~~
test.rs:20:53: 25:3 note: but, the lifetime must be valid for the lifetime 'a as defined on the block at 20:52...
test.rs:20  pub fn new<'a>(lexer: &'a mut Lexer) -> Parser<'a> {
test.rs:21 
test.rs:22      Parser {
test.rs:23          lexer: lexer,
test.rs:24      }
test.rs:25  }
test.rs:22:3: 24:4 note: ...so that types are compatible (expected `Parser<'a>` but found `Parser<'_>`)
test.rs:22      Parser {
test.rs:23          lexer: lexer,
test.rs:24      }
error: aborting due to previous error

It can take a couple of re-compilations to see the different message.

Rust version:
f8c9aec
rustc 0.11.0-pre
host: x86_64-apple-darwin

I was also able to reproduce this behavior on http://play.rust-lang.org/.

@ghost
Copy link

ghost commented Jun 20, 2014

I guess the variability stems from HashSets being involved in producing those errors as the hasher is parametrised with a random value. An easy way would be to make rustc always use hash collections with a non-randomly initialised SipHasher.

@ghost ghost added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Oct 24, 2014
@bors bors closed this as completed in d1438f5 Dec 30, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

No branches or pull requests

2 participants