Skip to content

Commit

Permalink
check_pat_tuple: use pattern_cause
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Feb 25, 2020
1 parent e9f6bb7 commit b1de8f1
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
});
let element_tys = tcx.mk_substs(element_tys_iter);
let pat_ty = tcx.mk_ty(ty::Tuple(element_tys));
if let Some(mut err) = self.demand_eqtype_diag(span, expected, pat_ty) {
if let Some(mut err) = self.demand_eqtype_pat_diag(span, expected, pat_ty, ti) {
err.emit();
// Walk subpatterns with an expected type of `err` in this case to silence
// further errors being emitted when using the bindings. #50333
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/elide-errors-on-mismatched-tuple.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ error[E0308]: mismatched types
--> $DIR/elide-errors-on-mismatched-tuple.rs:14:9
|
LL | let (a, b, c) = (A::new(), A::new()); // This tuple is 2 elements, should be three
| ^^^^^^^^^ expected a tuple with 2 elements, found one with 3 elements
| ^^^^^^^^^ -------------------- this expression has type `(A, A)`
| |
| expected a tuple with 2 elements, found one with 3 elements
|
= note: expected tuple `(A, A)`
found tuple `(_, _, _)`
Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/issues/issue-5100.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ LL | A::B => (),
error[E0308]: mismatched types
--> $DIR/issue-5100.rs:17:9
|
LL | match (true, false) {
| ------------- this expression has type `(bool, bool)`
LL | (true, false, false) => ()
| ^^^^^^^^^^^^^^^^^^^^ expected a tuple with 2 elements, found one with 3 elements
|
Expand All @@ -21,6 +23,8 @@ LL | (true, false, false) => ()
error[E0308]: mismatched types
--> $DIR/issue-5100.rs:25:9
|
LL | match (true, false) {
| ------------- this expression has type `(bool, bool)`
LL | (true, false, false) => ()
| ^^^^^^^^^^^^^^^^^^^^ expected a tuple with 2 elements, found one with 3 elements
|
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/pattern/pat-tuple-bad-type.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ LL | (..) => {}
error[E0308]: mismatched types
--> $DIR/pat-tuple-bad-type.rs:10:9
|
LL | match 0u8 {
| --- this expression has type `u8`
LL | (..) => {}
| ^^^^ expected `u8`, found `()`

Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/pattern/pat-tuple-overfield.stderr
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
error[E0308]: mismatched types
--> $DIR/pat-tuple-overfield.rs:5:9
|
LL | match (1, 2, 3) {
| --------- this expression has type `({integer}, {integer}, {integer})`
LL | (1, 2, 3, 4) => {}
| ^^^^^^^^^^^^ expected a tuple with 3 elements, found one with 4 elements
|
Expand All @@ -10,6 +12,9 @@ LL | (1, 2, 3, 4) => {}
error[E0308]: mismatched types
--> $DIR/pat-tuple-overfield.rs:6:9
|
LL | match (1, 2, 3) {
| --------- this expression has type `({integer}, {integer}, {integer})`
LL | (1, 2, 3, 4) => {}
LL | (1, 2, .., 3, 4) => {}
| ^^^^^^^^^^^^^^^^ expected a tuple with 3 elements, found one with 4 elements
|
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/suppressed-error.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ error[E0308]: mismatched types
--> $DIR/suppressed-error.rs:2:9
|
LL | let (x, y) = ();
| ^^^^^^ expected `()`, found tuple
| ^^^^^^ -- this expression has type `()`
| |
| expected `()`, found tuple
|
= note: expected unit type `()`
found tuple `(_, _)`
Expand Down

0 comments on commit b1de8f1

Please sign in to comment.