Skip to content

Improve error message of match arms have incompatible types #11319

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
klutzy opened this issue Jan 5, 2014 · 0 comments · Fixed by #14561
Closed

Improve error message of match arms have incompatible types #11319

klutzy opened this issue Jan 5, 2014 · 0 comments · Fixed by #14561
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@klutzy
Copy link
Contributor

klutzy commented Jan 5, 2014

Currently this code:

fn i() -> int { 1 }
fn u() -> uint { 1 }
fn uu() -> u8 { 1 }

fn main() {
    match 0 {
        1 => i(),
        2 => u(),
        3 => uu(),
        _ => {},
    }
}

causes:

y.rs:6:5: 11:6 error: match arms have incompatible types: expected `int` but found `uint` (expected int but found uint)
y.rs:6     match 0 {
y.rs:7         1 => i(),
y.rs:8         2 => u(),
y.rs:9         3 => uu(),
y.rs:10         _ => {},
y.rs:11     }

The error message just says there exists some type mismatch between some arms, but it doesn't say which arms actually are.
It would be better if rustc indicates that arm 1 and arm 2 have incompatible types.

flip1995 pushed a commit to flip1995/rust that referenced this issue Aug 24, 2023
[iter_overeager_cloned]: detect .cloned().map() and .cloned().for_each()

changelog: [`iter_overeager_cloned`]

key idea:
for `f` in `.map(f)` and `.for_each(f)`:
1. `f` must be closure
2. don't lint if mutable paramter in clsure `f`: `|mut x| ...`
3. don't lint if parameter is moved
4. maybe incorrect
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

Successfully merging a pull request may close this issue.

2 participants