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

let () has a poor error message #17821

Closed
steveklabnik opened this issue Oct 6, 2014 · 6 comments
Closed

let () has a poor error message #17821

steveklabnik opened this issue Oct 6, 2014 · 6 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@steveklabnik
Copy link
Member

fn main() {
    let () = 1i;
}

gives

<anon>:2:9: 2:11 error: mismatched types: expected `int`, found `()` (expected int, found ())
<anon>:2     let () = 1i;
                 ^~

Obviously, () isn't a valid name for a binding, but this message isn't very helpful.

@kmcallister kmcallister added the A-diagnostics Area: Messages for errors, warnings, and lints label Oct 6, 2014
@kmcallister
Copy link
Contributor

It's a standard pattern type mismatch error, and seems pretty clear to me. What sort of message would you prefer? Is there a particular case of people writing let () that you have in mind?

@steveklabnik
Copy link
Member Author

To me, the fact that () can't be a valid name for binding is more important than some kind of type mis-match. But this might not be worth special casing. I don't know, the weirdness of it threw me off, maybe it's not that bad.

@kmcallister
Copy link
Contributor

I see. Conceptually it's not much different from

fn main() {
    let (a, b) = 1i;
}

which is more evidently a type mismatch. But I agree that it's not obvious () is a pattern in Rust. It was familiar to me because of my background in Haskell, where pattern-matching on () is fairly common (and has a run-time effect!)

@steveklabnik
Copy link
Member Author

Right, I was seeing it as unit, not a pattern.

@kmcallister
Copy link
Contributor

It's both. It's a pattern which matches the one and only value of the unit type.

@steveklabnik
Copy link
Member Author

But this might not be worth special casing. I don't know, the weirdness of it threw me off, maybe it's not that bad.

Agree with my past self, I've never seen anyone else run into this since.

lnicola pushed a commit to lnicola/rust that referenced this issue Aug 13, 2024
internal: Remove unnecessary CfgFlag definition in project-model
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
Projects
None yet
Development

No branches or pull requests

2 participants