Skip to content

Commit

Permalink
check_pat_path: use pattern_cause
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Feb 25, 2020
1 parent 1d33717 commit e9f6bb7
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/librustc_typeck/check/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.check_pat_tuple_struct(pat, qpath, subpats, ddpos, expected, def_bm, ti)
}
PatKind::Path(ref qpath) => {
self.check_pat_path(pat, path_res.unwrap(), qpath, expected)
self.check_pat_path(pat, path_res.unwrap(), qpath, expected, ti)
}
PatKind::Struct(ref qpath, fields, etc) => {
self.check_pat_struct(pat, qpath, fields, etc, expected, def_bm, ti)
Expand Down Expand Up @@ -671,6 +671,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
path_resolution: (Res, Option<Ty<'tcx>>, &'b [hir::PathSegment<'b>]),
qpath: &hir::QPath<'_>,
expected: Ty<'tcx>,
ti: TopInfo<'tcx>,
) -> Ty<'tcx> {
let tcx = self.tcx;

Expand All @@ -696,7 +697,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// Type-check the path.
let pat_ty = self.instantiate_value_path(segments, opt_ty, res, pat.span, pat.hir_id).0;
self.demand_suptype(pat.span, expected, pat_ty);
if let Some(mut err) =
self.demand_suptype_with_origin(&self.pattern_cause(ti, pat.span), expected, pat_ty)
{
err.emit();
}
pat_ty
}

Expand Down
3 changes: 3 additions & 0 deletions src/test/ui/issues/issue-12552.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ LL | Some(k) => match k {
error[E0308]: mismatched types
--> $DIR/issue-12552.rs:9:5
|
LL | match t {
| - this expression has type `std::result::Result<_, {integer}>`
...
LL | None => ()
| ^^^^ expected enum `std::result::Result`, found enum `std::option::Option`
|
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/issues/issue-37026.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ error[E0308]: mismatched types
--> $DIR/issue-37026.rs:6:9
|
LL | let empty_struct::XEmpty2 = ();
| ^^^^^^^^^^^^^^^^^^^^^ expected `()`, found struct `empty_struct::XEmpty2`
| ^^^^^^^^^^^^^^^^^^^^^ -- this expression has type `()`
| |
| expected `()`, found struct `empty_struct::XEmpty2`

error[E0308]: mismatched types
--> $DIR/issue-37026.rs:7:9
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/issues/issue-5100.stderr
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
error[E0308]: mismatched types
--> $DIR/issue-5100.rs:8:9
|
LL | match (true, false) {
| ------------- this expression has type `(bool, bool)`
LL | A::B => (),
| ^^^^ expected tuple, found enum `A`
|
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/issues/issue-7867.stderr
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
error[E0308]: mismatched types
--> $DIR/issue-7867.rs:7:9
|
LL | match (true, false) {
| ------------- this expression has type `(bool, bool)`
LL | A::B => (),
| ^^^^ expected tuple, found enum `A`
|
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/match/match-tag-nullary.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ error[E0308]: mismatched types
--> $DIR/match-tag-nullary.rs:4:40
|
LL | fn main() { let x: A = A::A; match x { B::B => { } } }
| ^^^^ expected enum `A`, found enum `B`
| - ^^^^ expected enum `A`, found enum `B`
| |
| this expression has type `A`

error: aborting due to previous error

Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/pattern/pattern-ident-path-generics.stderr
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
error[E0308]: mismatched types
--> $DIR/pattern-ident-path-generics.rs:3:9
|
LL | match Some("foo") {
| ----------- this expression has type `std::option::Option<&str>`
LL | None::<isize> => {}
| ^^^^^^^^^^^^^ expected `&str`, found `isize`
|
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/resolve/name-clash-nullary.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ error[E0308]: mismatched types
--> $DIR/name-clash-nullary.rs:2:7
|
LL | let None: isize = 42;
| ^^^^ expected `isize`, found enum `std::option::Option`
| ^^^^ ----- expected due to this
| |
| expected `isize`, found enum `std::option::Option`
|
= note: expected type `isize`
found enum `std::option::Option<_>`
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/rfc-2005-default-binding-mode/const.stderr
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
error[E0308]: mismatched types
--> $DIR/const.rs:14:9
|
LL | match &f {
| -- this expression has type `&Foo`
LL | FOO => {},
| ^^^ expected `&Foo`, found struct `Foo`

Expand Down

0 comments on commit e9f6bb7

Please sign in to comment.