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

Point at match discriminant on type error in match arm pattern #57279

Closed
estebank opened this issue Jan 2, 2019 · 0 comments
Closed

Point at match discriminant on type error in match arm pattern #57279

estebank opened this issue Jan 2, 2019 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@estebank
Copy link
Contributor

estebank commented Jan 2, 2019

From https://www.reddit.com/r/rust/comments/abjzi7/expected_usize_found_enum_stdresultresult/

When encountering code like the following, where a match arm pattern is not the expected type, point at the match expression to provide more context

fn main() {
    let a: usize = 3;
    let b: usize = 3;
    let temp: usize = match a + b {
        Ok(num) => num,
        Err(_) => 0,
    };
}
error[E0308]: mismatched types
 --> src/main.rs:5:9
  |
4 |    let temp: usize = match a + b {
  |                            ----- this `match` expression is of type `usize`
5 |         Ok(num) => num,
  |         ^^^^^^^ expected usize, found enum `std::result::Result`
  |
  = note: expected type `usize`
             found type `std::result::Result<_, _>`

error[E0308]: mismatched types
 --> src/main.rs:6:9
  |
4 |    let temp: usize = match a + b {
  |                            ----- this `match` expression is of type `usize`
5 |         Ok(num) => num,
6 |         Err(_) => 0,
  |         ^^^^^^ expected usize, found enum `std::result::Result`
  |
  = note: expected type `usize`
             found type `std::result::Result<_, _>`

@estebank estebank added the A-diagnostics Area: Messages for errors, warnings, and lints label Jan 2, 2019
@estebank estebank changed the title Point at match expression on type error in match arm pattern Point at match discrimant on type error in match arm pattern Jan 6, 2019
@estebank estebank changed the title Point at match discrimant on type error in match arm pattern Point at match discriminant on type error in match arm pattern Jan 6, 2019
Centril added a commit to Centril/rust that referenced this issue Jan 13, 2019
Point at match discriminant on type error in match arm pattern

```
error[E0308]: mismatched types
 --> src/main.rs:5:9
  |
4 |    let temp: usize = match a + b {
  |                            ----- this expression has type `usize`
5 |         Ok(num) => num,
  |         ^^^^^^^ expected usize, found enum `std::result::Result`
  |
  = note: expected type `usize`
             found type `std::result::Result<_, _>`
```
Fix rust-lang#57279.
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

1 participant