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

suggets simplifying Err(_), Some(_) or Ok(_) to _ inside match if all options are exhausted #3262

Open
matthiaskrgr opened this issue Oct 4, 2018 · 3 comments

Comments

@matthiaskrgr
Copy link
Member

fn get_result(b: bool) -> Result<(u16, u16), String> {
    if b {
        Ok((42, 1337))
    } else {
        Err("oh no".to_string())
    }
}

fn main() {
    let (_, _) = match get_result(false) {
        Err(_) => (0, 0),
        Ok((x, y)) => (x, y),
    };
    //println!("a: {}, b: {}", a, b);
}

the match of the main function can be simplified to

    let (_, _) = match get_result(false) {
        Ok((x, y)) => (x, y),
        _ => (0,0),
    };
@clarfonthey
Copy link
Contributor

This should be allow by default.

@matthiaskrgr
Copy link
Member Author

It could be put into the pedantic group.

@camsteffen
Copy link
Contributor

IMO this would have to be restriction. The Err adds clarity. I also like putting the error case (or the "unhappy path") first in general.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants