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

Comments

Projects
None yet
1 participant
@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 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

bors added a commit that referenced this issue Jan 10, 2019

Auto merge of #57366 - estebank:point-match-discrim, r=varkor
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 #57279.

Centril added a commit to Centril/rust that referenced this issue Jan 13, 2019

Rollup merge of rust-lang#57366 - estebank:point-match-discrim, r=varkor
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.

@bors bors closed this in #57366 Jan 14, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment