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

Seemingly incorrect error about use of uninitialized value #7508

Closed
DaGenix opened this issue Jun 30, 2013 · 5 comments · Fixed by #10123
Closed

Seemingly incorrect error about use of uninitialized value #7508

DaGenix opened this issue Jun 30, 2013 · 5 comments · Fixed by #10123
Labels
A-parser Area: The parsing of Rust source code to an AST

Comments

@DaGenix
Copy link

DaGenix commented Jun 30, 2013

The following program:

fn test() -> (u32, u32) {
    return (0, 0);
}

fn main() {
    let mut X0: u32;
    let mut X1: u32;
    (X0, X1) = test();
}

Gives me the error:

multi-bind-issue.rs:9:5: 9:7 error: use of possibly uninitialized variable: X0
multi-bind-issue.rs:9 (X0, X1) = test();
^~
multi-bind-issue.rs:9:9: 9:11 error: use of possibly uninitialized variable: X1
multi-bind-issue.rs:9 (X0, X1) = test();
^~
error: aborting due to 2 previous errors

Which seems wrong, since the use its complaining about is the initialization of the variables.

Compiled with: 8883099

@Aatch
Copy link
Contributor

Aatch commented Jun 30, 2013

You are trying to pattern match outside of a let/match, so this code wouldn't work anyway. Its just that the checker for unintialized variables gets to the tuple expression first.

This is just an unclear error message, not a bug.

@DaGenix
Copy link
Author

DaGenix commented Jun 30, 2013

Ok, makes sense. Isn't it still an issue though that the error message is very unhelpful? Someone coming from a language that allows this type of construct (I think Scala does) will be confused.

@brson
Copy link
Contributor

brson commented Jul 10, 2013

I don't understand why this parses. What is (X0, X1) = test();?

@nikomatsakis
Copy link
Contributor

I think it parses because we accept an arbitrary expression on the LHS, but certainly there should be some point, either in typeck or before, that enforces that the LHS is an lvalue...perhaps there isn't?

@klutzy
Copy link
Contributor

klutzy commented Aug 30, 2013

(X0, X1) = test(); part is related to #7507

bors added a commit that referenced this issue Oct 30, 2013
This patch fixes rustc to emit explicit error if LHS of assignment is
not allowed.

Fixes #7507
Fixes #7508
@bors bors closed this as completed in 47abdbd Oct 30, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: The parsing of Rust source code to an AST
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants