1
Fork 0

MatchExpressionArmPattern: Use more generic wording.

The existing wording was inappropriate for e.g.
`if let Ok(_) = expr { .. }`. The diagnostic would
leak the fact that we desugar to a `match`.
This commit is contained in:
Mazdak Farrokhzad 2019-12-30 07:02:24 +01:00
parent 73db83aa70
commit ab050d6a83
24 changed files with 38 additions and 38 deletions

View file

@ -584,7 +584,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
ObligationCauseCode::MatchExpressionArmPattern { span, ty } => { ObligationCauseCode::MatchExpressionArmPattern { span, ty } => {
if ty.is_suggestable() { if ty.is_suggestable() {
// don't show type `_` // don't show type `_`
err.span_label(span, format!("this match expression has type `{}`", ty)); err.span_label(span, format!("this expression has type `{}`", ty));
} }
if let Some(ty::error::ExpectedFound { found, .. }) = exp_found { if let Some(ty::error::ExpectedFound { found, .. }) = exp_found {
if ty.is_box() && ty.boxed_ty() == found { if ty.is_box() && ty.boxed_ty() == found {

View file

@ -10,7 +10,7 @@ error[E0308]: mismatched types
--> $DIR/issue-13624.rs:20:9 --> $DIR/issue-13624.rs:20:9
| |
LL | match enum_struct_variant { LL | match enum_struct_variant {
| ------------------- this match expression has type `()` | ------------------- this expression has type `()`
LL | a::Enum::EnumStructVariant { x, y, z } => { LL | a::Enum::EnumStructVariant { x, y, z } => {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found enum `a::Enum` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found enum `a::Enum`

View file

@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/E0308-4.rs:4:15 --> $DIR/E0308-4.rs:4:15
| |
LL | match x { LL | match x {
| - this match expression has type `u8` | - this expression has type `u8`
LL | 0u8..=3i8 => (), LL | 0u8..=3i8 => (),
| --- ^^^ expected `u8`, found `i8` | --- ^^^ expected `u8`, found `i8`
| | | |

View file

@ -8,7 +8,7 @@ error[E0308]: mismatched types
--> $DIR/exclusive_range_pattern_syntax_collision.rs:5:13 --> $DIR/exclusive_range_pattern_syntax_collision.rs:5:13
| |
LL | match [5..4, 99..105, 43..44] { LL | match [5..4, 99..105, 43..44] {
| ----------------------- this match expression has type `std::ops::Range<{integer}>` | ----------------------- this expression has type `std::ops::Range<{integer}>`
LL | [_, 99.., _] => {}, LL | [_, 99.., _] => {},
| ^^ expected struct `std::ops::Range`, found integer | ^^ expected struct `std::ops::Range`, found integer
| |

View file

@ -14,7 +14,7 @@ error[E0308]: mismatched types
--> $DIR/exclusive_range_pattern_syntax_collision2.rs:5:13 --> $DIR/exclusive_range_pattern_syntax_collision2.rs:5:13
| |
LL | match [5..4, 99..105, 43..44] { LL | match [5..4, 99..105, 43..44] {
| ----------------------- this match expression has type `std::ops::Range<{integer}>` | ----------------------- this expression has type `std::ops::Range<{integer}>`
LL | [_, 99..] => {}, LL | [_, 99..] => {},
| ^^ expected struct `std::ops::Range`, found integer | ^^ expected struct `std::ops::Range`, found integer
| |

View file

@ -8,7 +8,7 @@ error[E0308]: mismatched types
--> $DIR/exclusive_range_pattern_syntax_collision3.rs:5:12 --> $DIR/exclusive_range_pattern_syntax_collision3.rs:5:12
| |
LL | match [5..4, 99..105, 43..44] { LL | match [5..4, 99..105, 43..44] {
| ----------------------- this match expression has type `std::ops::Range<{integer}>` | ----------------------- this expression has type `std::ops::Range<{integer}>`
LL | [..9, 99..100, _] => {}, LL | [..9, 99..100, _] => {},
| ^ expected struct `std::ops::Range`, found integer | ^ expected struct `std::ops::Range`, found integer
| |
@ -19,7 +19,7 @@ error[E0308]: mismatched types
--> $DIR/exclusive_range_pattern_syntax_collision3.rs:5:15 --> $DIR/exclusive_range_pattern_syntax_collision3.rs:5:15
| |
LL | match [5..4, 99..105, 43..44] { LL | match [5..4, 99..105, 43..44] {
| ----------------------- this match expression has type `std::ops::Range<{integer}>` | ----------------------- this expression has type `std::ops::Range<{integer}>`
LL | [..9, 99..100, _] => {}, LL | [..9, 99..100, _] => {},
| ^^ --- this is of type `{integer}` | ^^ --- this is of type `{integer}`
| | | |

View file

@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/issue-11844.rs:6:9 --> $DIR/issue-11844.rs:6:9
| |
LL | match a { LL | match a {
| - this match expression has type `std::option::Option<std::boxed::Box<{integer}>>` | - this expression has type `std::option::Option<std::boxed::Box<{integer}>>`
LL | Ok(a) => LL | Ok(a) =>
| ^^^^^ expected enum `std::option::Option`, found enum `std::result::Result` | ^^^^^ expected enum `std::option::Option`, found enum `std::result::Result`
| |

View file

@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/issue-12552.rs:6:5 --> $DIR/issue-12552.rs:6:5
| |
LL | match t { LL | match t {
| - this match expression has type `std::result::Result<_, {integer}>` | - this expression has type `std::result::Result<_, {integer}>`
LL | Some(k) => match k { LL | Some(k) => match k {
| ^^^^^^^ expected enum `std::result::Result`, found enum `std::option::Option` | ^^^^^^^ expected enum `std::result::Result`, found enum `std::option::Option`
| |

View file

@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/issue-13466.rs:8:9 --> $DIR/issue-13466.rs:8:9
| |
LL | let _x: usize = match Some(1) { LL | let _x: usize = match Some(1) {
| ------- this match expression has type `std::option::Option<{integer}>` | ------- this expression has type `std::option::Option<{integer}>`
LL | Ok(u) => u, LL | Ok(u) => u,
| ^^^^^ expected enum `std::option::Option`, found enum `std::result::Result` | ^^^^^ expected enum `std::option::Option`, found enum `std::result::Result`
| |
@ -13,7 +13,7 @@ error[E0308]: mismatched types
--> $DIR/issue-13466.rs:14:9 --> $DIR/issue-13466.rs:14:9
| |
LL | let _x: usize = match Some(1) { LL | let _x: usize = match Some(1) {
| ------- this match expression has type `std::option::Option<{integer}>` | ------- this expression has type `std::option::Option<{integer}>`
... ...
LL | Err(e) => panic!(e) LL | Err(e) => panic!(e)
| ^^^^^^ expected enum `std::option::Option`, found enum `std::result::Result` | ^^^^^^ expected enum `std::option::Option`, found enum `std::result::Result`

View file

@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/issue-15896.rs:11:11 --> $DIR/issue-15896.rs:11:11
| |
LL | let u = match e { LL | let u = match e {
| - this match expression has type `main::R` | - this expression has type `main::R`
LL | E::B( LL | E::B(
LL | Tau{t: x}, LL | Tau{t: x},
| ^^^^^^^^^ expected enum `main::R`, found struct `main::Tau` | ^^^^^^^^^ expected enum `main::R`, found struct `main::Tau`

View file

@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/issue-16401.rs:8:9 --> $DIR/issue-16401.rs:8:9
| |
LL | match () { LL | match () {
| -- this match expression has type `()` | -- this expression has type `()`
LL | Slice { data: data, len: len } => (), LL | Slice { data: data, len: len } => (),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found struct `Slice` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found struct `Slice`
| |

View file

@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/issue-3680.rs:3:9 --> $DIR/issue-3680.rs:3:9
| |
LL | match None { LL | match None {
| ---- this match expression has type `std::option::Option<_>` | ---- this expression has type `std::option::Option<_>`
LL | Err(_) => () LL | Err(_) => ()
| ^^^^^^ expected enum `std::option::Option`, found enum `std::result::Result` | ^^^^^^ expected enum `std::option::Option`, found enum `std::result::Result`
| |

View file

@ -29,7 +29,7 @@ error[E0308]: mismatched types
--> $DIR/issue-5100.rs:33:9 --> $DIR/issue-5100.rs:33:9
| |
LL | match (true, false) { LL | match (true, false) {
| ------------- this match expression has type `(bool, bool)` | ------------- this expression has type `(bool, bool)`
LL | box (true, false) => () LL | box (true, false) => ()
| ^^^^^^^^^^^^^^^^^ expected tuple, found struct `std::boxed::Box` | ^^^^^^^^^^^^^^^^^ expected tuple, found struct `std::boxed::Box`
| |

View file

@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/issue-5358-1.rs:6:9 --> $DIR/issue-5358-1.rs:6:9
| |
LL | match S(Either::Left(5)) { LL | match S(Either::Left(5)) {
| ------------------ this match expression has type `S` | ------------------ this expression has type `S`
LL | Either::Right(_) => {} LL | Either::Right(_) => {}
| ^^^^^^^^^^^^^^^^ expected struct `S`, found enum `Either` | ^^^^^^^^^^^^^^^^ expected struct `S`, found enum `Either`
| |

View file

@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/issue-57741-1.rs:14:9 --> $DIR/issue-57741-1.rs:14:9
| |
LL | let y = match x { LL | let y = match x {
| - this match expression has type `std::boxed::Box<u32>` | - this expression has type `std::boxed::Box<u32>`
LL | S::A { a } | S::B { b: a } => a, LL | S::A { a } | S::B { b: a } => a,
| ^^^^^^^^^^ expected struct `std::boxed::Box`, found enum `S` | ^^^^^^^^^^ expected struct `std::boxed::Box`, found enum `S`
| |
@ -13,7 +13,7 @@ error[E0308]: mismatched types
--> $DIR/issue-57741-1.rs:14:22 --> $DIR/issue-57741-1.rs:14:22
| |
LL | let y = match x { LL | let y = match x {
| - this match expression has type `std::boxed::Box<u32>` | - this expression has type `std::boxed::Box<u32>`
LL | S::A { a } | S::B { b: a } => a, LL | S::A { a } | S::B { b: a } => a,
| ^^^^^^^^^^^^^ expected struct `std::boxed::Box`, found enum `S` | ^^^^^^^^^^^^^ expected struct `std::boxed::Box`, found enum `S`
| |

View file

@ -4,7 +4,7 @@ error[E0308]: mismatched types
LL | let y = match x { LL | let y = match x {
| - | -
| | | |
| this match expression has type `std::boxed::Box<T>` | this expression has type `std::boxed::Box<T>`
| help: consider dereferencing the boxed value: `*x` | help: consider dereferencing the boxed value: `*x`
LL | T::A(a) | T::B(a) => a, LL | T::A(a) | T::B(a) => a,
| ^^^^^^^ expected struct `std::boxed::Box`, found enum `T` | ^^^^^^^ expected struct `std::boxed::Box`, found enum `T`
@ -18,7 +18,7 @@ error[E0308]: mismatched types
LL | let y = match x { LL | let y = match x {
| - | -
| | | |
| this match expression has type `std::boxed::Box<T>` | this expression has type `std::boxed::Box<T>`
| help: consider dereferencing the boxed value: `*x` | help: consider dereferencing the boxed value: `*x`
LL | T::A(a) | T::B(a) => a, LL | T::A(a) | T::B(a) => a,
| ^^^^^^^ expected struct `std::boxed::Box`, found enum `T` | ^^^^^^^ expected struct `std::boxed::Box`, found enum `T`
@ -32,7 +32,7 @@ error[E0308]: mismatched types
LL | let y = match x { LL | let y = match x {
| - | -
| | | |
| this match expression has type `std::boxed::Box<S>` | this expression has type `std::boxed::Box<S>`
| help: consider dereferencing the boxed value: `*x` | help: consider dereferencing the boxed value: `*x`
LL | S::A { a } | S::B { b: a } => a, LL | S::A { a } | S::B { b: a } => a,
| ^^^^^^^^^^ expected struct `std::boxed::Box`, found enum `S` | ^^^^^^^^^^ expected struct `std::boxed::Box`, found enum `S`
@ -46,7 +46,7 @@ error[E0308]: mismatched types
LL | let y = match x { LL | let y = match x {
| - | -
| | | |
| this match expression has type `std::boxed::Box<S>` | this expression has type `std::boxed::Box<S>`
| help: consider dereferencing the boxed value: `*x` | help: consider dereferencing the boxed value: `*x`
LL | S::A { a } | S::B { b: a } => a, LL | S::A { a } | S::B { b: a } => a,
| ^^^^^^^^^^^^^ expected struct `std::boxed::Box`, found enum `S` | ^^^^^^^^^^^^^ expected struct `std::boxed::Box`, found enum `S`

View file

@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/issue-7092.rs:6:9 --> $DIR/issue-7092.rs:6:9
| |
LL | match x { LL | match x {
| - this match expression has type `Whatever` | - this expression has type `Whatever`
LL | Some(field) => LL | Some(field) =>
| ^^^^^^^^^^^ expected enum `Whatever`, found enum `std::option::Option` | ^^^^^^^^^^^ expected enum `Whatever`, found enum `std::option::Option`
| |

View file

@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/match-struct.rs:6:9 --> $DIR/match-struct.rs:6:9
| |
LL | match (S { a: 1 }) { LL | match (S { a: 1 }) {
| ------------ this match expression has type `S` | ------------ this expression has type `S`
LL | E::C(_) => (), LL | E::C(_) => (),
| ^^^^^^^ expected struct `S`, found enum `E` | ^^^^^^^ expected struct `S`, found enum `E`

View file

@ -4,7 +4,7 @@ error[E0308]: mismatched types
LL | fn main() { let x: A = A::A(0); match x { B::B(y) => { } } } LL | fn main() { let x: A = A::A(0); match x { B::B(y) => { } } }
| - ^^^^^^^ expected enum `A`, found enum `B` | - ^^^^^^^ expected enum `A`, found enum `B`
| | | |
| this match expression has type `A` | this expression has type `A`
error: aborting due to previous error error: aborting due to previous error

View file

@ -17,7 +17,7 @@ error[E0308]: mismatched types
--> $DIR/pat-tuple-5.rs:5:10 --> $DIR/pat-tuple-5.rs:5:10
| |
LL | match (0, 1) { LL | match (0, 1) {
| ------ this match expression has type `({integer}, {integer})` | ------ this expression has type `({integer}, {integer})`
LL | (PAT ..) => {} LL | (PAT ..) => {}
| ^^^ expected tuple, found `u8` | ^^^ expected tuple, found `u8`
| |

View file

@ -28,7 +28,7 @@ error[E0308]: mismatched types
--> $DIR/pattern-error-continue.rs:22:9 --> $DIR/pattern-error-continue.rs:22:9
| |
LL | match 'c' { LL | match 'c' {
| --- this match expression has type `char` | --- this expression has type `char`
LL | S { .. } => (), LL | S { .. } => (),
| ^^^^^^^^ expected `char`, found struct `S` | ^^^^^^^^ expected `char`, found struct `S`

View file

@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/pattern-tyvar.rs:5:18 --> $DIR/pattern-tyvar.rs:5:18
| |
LL | match t { LL | match t {
| - this match expression has type `std::option::Option<std::vec::Vec<isize>>` | - this expression has type `std::option::Option<std::vec::Vec<isize>>`
LL | Bar::T1(_, Some::<isize>(x)) => { LL | Bar::T1(_, Some::<isize>(x)) => {
| ^^^^^^^^^^^^^^^^ expected struct `std::vec::Vec`, found `isize` | ^^^^^^^^^^^^^^^^ expected struct `std::vec::Vec`, found `isize`
| |

View file

@ -630,7 +630,7 @@ error[E0308]: mismatched types
--> $DIR/disallowed-positions.rs:67:12 --> $DIR/disallowed-positions.rs:67:12
| |
LL | if let Range { start: _, end: _ } = true..true && false {} LL | if let Range { start: _, end: _ } = true..true && false {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this match expression has type `bool` | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this expression has type `bool`
| | | |
| expected `bool`, found struct `std::ops::Range` | expected `bool`, found struct `std::ops::Range`
| |
@ -650,7 +650,7 @@ error[E0308]: mismatched types
--> $DIR/disallowed-positions.rs:71:12 --> $DIR/disallowed-positions.rs:71:12
| |
LL | if let Range { start: _, end: _ } = true..true || false {} LL | if let Range { start: _, end: _ } = true..true || false {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this match expression has type `bool` | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this expression has type `bool`
| | | |
| expected `bool`, found struct `std::ops::Range` | expected `bool`, found struct `std::ops::Range`
| |
@ -697,7 +697,7 @@ error[E0308]: mismatched types
--> $DIR/disallowed-positions.rs:86:12 --> $DIR/disallowed-positions.rs:86:12
| |
LL | if let Range { start: true, end } = t..&&false {} LL | if let Range { start: true, end } = t..&&false {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ - this match expression has type `bool` | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - this expression has type `bool`
| | | |
| expected `bool`, found struct `std::ops::Range` | expected `bool`, found struct `std::ops::Range`
| |
@ -818,7 +818,7 @@ error[E0308]: mismatched types
--> $DIR/disallowed-positions.rs:131:15 --> $DIR/disallowed-positions.rs:131:15
| |
LL | while let Range { start: _, end: _ } = true..true && false {} LL | while let Range { start: _, end: _ } = true..true && false {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this match expression has type `bool` | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this expression has type `bool`
| | | |
| expected `bool`, found struct `std::ops::Range` | expected `bool`, found struct `std::ops::Range`
| |
@ -838,7 +838,7 @@ error[E0308]: mismatched types
--> $DIR/disallowed-positions.rs:135:15 --> $DIR/disallowed-positions.rs:135:15
| |
LL | while let Range { start: _, end: _ } = true..true || false {} LL | while let Range { start: _, end: _ } = true..true || false {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this match expression has type `bool` | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this expression has type `bool`
| | | |
| expected `bool`, found struct `std::ops::Range` | expected `bool`, found struct `std::ops::Range`
| |
@ -885,7 +885,7 @@ error[E0308]: mismatched types
--> $DIR/disallowed-positions.rs:150:15 --> $DIR/disallowed-positions.rs:150:15
| |
LL | while let Range { start: true, end } = t..&&false {} LL | while let Range { start: true, end } = t..&&false {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ - this match expression has type `bool` | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - this expression has type `bool`
| | | |
| expected `bool`, found struct `std::ops::Range` | expected `bool`, found struct `std::ops::Range`
| |
@ -961,7 +961,7 @@ error[E0308]: mismatched types
--> $DIR/disallowed-positions.rs:198:10 --> $DIR/disallowed-positions.rs:198:10
| |
LL | (let Range { start: _, end: _ } = true..true || false); LL | (let Range { start: _, end: _ } = true..true || false);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this match expression has type `bool` | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this expression has type `bool`
| | | |
| expected `bool`, found struct `std::ops::Range` | expected `bool`, found struct `std::ops::Range`
| |

View file

@ -86,7 +86,7 @@ error[E0308]: mismatched types
--> $DIR/structure-constructor-type-mismatch.rs:54:9 --> $DIR/structure-constructor-type-mismatch.rs:54:9
| |
LL | match (Point { x: 1, y: 2 }) { LL | match (Point { x: 1, y: 2 }) {
| ---------------------- this match expression has type `Point<{integer}>` | ---------------------- this expression has type `Point<{integer}>`
LL | PointF::<u32> { .. } => {} LL | PointF::<u32> { .. } => {}
| ^^^^^^^^^^^^^^^^^^^^ expected integer, found `f32` | ^^^^^^^^^^^^^^^^^^^^ expected integer, found `f32`
| |
@ -97,7 +97,7 @@ error[E0308]: mismatched types
--> $DIR/structure-constructor-type-mismatch.rs:59:9 --> $DIR/structure-constructor-type-mismatch.rs:59:9
| |
LL | match (Point { x: 1, y: 2 }) { LL | match (Point { x: 1, y: 2 }) {
| ---------------------- this match expression has type `Point<{integer}>` | ---------------------- this expression has type `Point<{integer}>`
LL | PointF { .. } => {} LL | PointF { .. } => {}
| ^^^^^^^^^^^^^ expected integer, found `f32` | ^^^^^^^^^^^^^ expected integer, found `f32`
| |
@ -108,7 +108,7 @@ error[E0308]: mismatched types
--> $DIR/structure-constructor-type-mismatch.rs:67:9 --> $DIR/structure-constructor-type-mismatch.rs:67:9
| |
LL | match (Pair { x: 1, y: 2 }) { LL | match (Pair { x: 1, y: 2 }) {
| --------------------- this match expression has type `Pair<{integer}, {integer}>` | --------------------- this expression has type `Pair<{integer}, {integer}>`
LL | PairF::<u32> { .. } => {} LL | PairF::<u32> { .. } => {}
| ^^^^^^^^^^^^^^^^^^^ expected integer, found `f32` | ^^^^^^^^^^^^^^^^^^^ expected integer, found `f32`
| |