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 } => {
if ty.is_suggestable() {
// 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 ty.is_box() && ty.boxed_ty() == found {

View File

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

View File

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

View File

@ -8,7 +8,7 @@ error[E0308]: mismatched types
--> $DIR/exclusive_range_pattern_syntax_collision.rs:5:13
|
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.., _] => {},
| ^^ 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
|
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..] => {},
| ^^ 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
|
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, _] => {},
| ^ expected struct `std::ops::Range`, found integer
|
@ -19,7 +19,7 @@ error[E0308]: mismatched types
--> $DIR/exclusive_range_pattern_syntax_collision3.rs:5:15
|
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, _] => {},
| ^^ --- this is of type `{integer}`
| |

View File

@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/issue-11844.rs:6:9
|
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) =>
| ^^^^^ 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
|
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 {
| ^^^^^^^ 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
|
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,
| ^^^^^ expected enum `std::option::Option`, found enum `std::result::Result`
|
@ -13,7 +13,7 @@ error[E0308]: mismatched types
--> $DIR/issue-13466.rs:14:9
|
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)
| ^^^^^^ 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
|
LL | let u = match e {
| - this match expression has type `main::R`
| - this expression has type `main::R`
LL | E::B(
LL | Tau{t: x},
| ^^^^^^^^^ expected enum `main::R`, found struct `main::Tau`

View File

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

View File

@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/issue-3680.rs:3:9
|
LL | match None {
| ---- this match expression has type `std::option::Option<_>`
| ---- this expression has type `std::option::Option<_>`
LL | Err(_) => ()
| ^^^^^^ 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
|
LL | match (true, false) {
| ------------- this match expression has type `(bool, bool)`
| ------------- this expression has type `(bool, bool)`
LL | box (true, false) => ()
| ^^^^^^^^^^^^^^^^^ expected tuple, found struct `std::boxed::Box`
|

View File

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

View File

@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/issue-57741-1.rs:14:9
|
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,
| ^^^^^^^^^^ expected struct `std::boxed::Box`, found enum `S`
|
@ -13,7 +13,7 @@ error[E0308]: mismatched types
--> $DIR/issue-57741-1.rs:14:22
|
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,
| ^^^^^^^^^^^^^ expected struct `std::boxed::Box`, found enum `S`
|

View File

@ -4,7 +4,7 @@ error[E0308]: mismatched types
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`
LL | T::A(a) | T::B(a) => a,
| ^^^^^^^ expected struct `std::boxed::Box`, found enum `T`
@ -18,7 +18,7 @@ error[E0308]: mismatched types
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`
LL | T::A(a) | T::B(a) => a,
| ^^^^^^^ expected struct `std::boxed::Box`, found enum `T`
@ -32,7 +32,7 @@ error[E0308]: mismatched types
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`
LL | S::A { a } | S::B { b: a } => a,
| ^^^^^^^^^^ expected struct `std::boxed::Box`, found enum `S`
@ -46,7 +46,7 @@ error[E0308]: mismatched types
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`
LL | S::A { a } | S::B { b: a } => a,
| ^^^^^^^^^^^^^ expected struct `std::boxed::Box`, found enum `S`

View File

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/pattern-tyvar.rs:5:18
|
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)) => {
| ^^^^^^^^^^^^^^^^ expected struct `std::vec::Vec`, found `isize`
|

View File

@ -630,7 +630,7 @@ error[E0308]: mismatched types
--> $DIR/disallowed-positions.rs:67:12
|
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`
|
@ -650,7 +650,7 @@ error[E0308]: mismatched types
--> $DIR/disallowed-positions.rs:71:12
|
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`
|
@ -697,7 +697,7 @@ error[E0308]: mismatched types
--> $DIR/disallowed-positions.rs:86:12
|
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`
|
@ -818,7 +818,7 @@ error[E0308]: mismatched types
--> $DIR/disallowed-positions.rs:131:15
|
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`
|
@ -838,7 +838,7 @@ error[E0308]: mismatched types
--> $DIR/disallowed-positions.rs:135:15
|
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`
|
@ -885,7 +885,7 @@ error[E0308]: mismatched types
--> $DIR/disallowed-positions.rs:150:15
|
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`
|
@ -961,7 +961,7 @@ error[E0308]: mismatched types
--> $DIR/disallowed-positions.rs:198:10
|
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`
|

View File

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