diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-02-25 05:41:03 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-02-25 05:41:03 +0100 |
| commit | e9f6bb7f79ef68859cc5c7641dcc8a399e9e9c46 (patch) | |
| tree | 09285c46119107854df7c969a96004050f1572e7 | |
| parent | 1d33717583c34bb09fcef236884774ae082cc1fd (diff) | |
| download | rust-e9f6bb7f79ef68859cc5c7641dcc8a399e9e9c46.tar.gz rust-e9f6bb7f79ef68859cc5c7641dcc8a399e9e9c46.zip | |
check_pat_path: use pattern_cause
| -rw-r--r-- | src/librustc_typeck/check/pat.rs | 9 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-12552.stderr | 3 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-37026.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-5100.stderr | 2 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-7867.stderr | 2 | ||||
| -rw-r--r-- | src/test/ui/match/match-tag-nullary.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/pattern/pattern-ident-path-generics.stderr | 2 | ||||
| -rw-r--r-- | src/test/ui/resolve/name-clash-nullary.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/rfc-2005-default-binding-mode/const.stderr | 2 |
9 files changed, 27 insertions, 5 deletions
diff --git a/src/librustc_typeck/check/pat.rs b/src/librustc_typeck/check/pat.rs index a003c7c365d..ef80803adde 100644 --- a/src/librustc_typeck/check/pat.rs +++ b/src/librustc_typeck/check/pat.rs @@ -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) @@ -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; @@ -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 } diff --git a/src/test/ui/issues/issue-12552.stderr b/src/test/ui/issues/issue-12552.stderr index 60c4cceac51..45fede44106 100644 --- a/src/test/ui/issues/issue-12552.stderr +++ b/src/test/ui/issues/issue-12552.stderr @@ -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` | diff --git a/src/test/ui/issues/issue-37026.stderr b/src/test/ui/issues/issue-37026.stderr index 361369e68bc..f0285730c5a 100644 --- a/src/test/ui/issues/issue-37026.stderr +++ b/src/test/ui/issues/issue-37026.stderr @@ -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 diff --git a/src/test/ui/issues/issue-5100.stderr b/src/test/ui/issues/issue-5100.stderr index c47e8689436..5fc0ff575d6 100644 --- a/src/test/ui/issues/issue-5100.stderr +++ b/src/test/ui/issues/issue-5100.stderr @@ -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` | diff --git a/src/test/ui/issues/issue-7867.stderr b/src/test/ui/issues/issue-7867.stderr index 58e82facf80..4a29464aebd 100644 --- a/src/test/ui/issues/issue-7867.stderr +++ b/src/test/ui/issues/issue-7867.stderr @@ -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` | diff --git a/src/test/ui/match/match-tag-nullary.stderr b/src/test/ui/match/match-tag-nullary.stderr index 4b6260b2199..3703a59edb8 100644 --- a/src/test/ui/match/match-tag-nullary.stderr +++ b/src/test/ui/match/match-tag-nullary.stderr @@ -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 diff --git a/src/test/ui/pattern/pattern-ident-path-generics.stderr b/src/test/ui/pattern/pattern-ident-path-generics.stderr index 338eb6ff0c8..24b5cdf98d5 100644 --- a/src/test/ui/pattern/pattern-ident-path-generics.stderr +++ b/src/test/ui/pattern/pattern-ident-path-generics.stderr @@ -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` | diff --git a/src/test/ui/resolve/name-clash-nullary.stderr b/src/test/ui/resolve/name-clash-nullary.stderr index aeeb0c45191..2de0b6a4969 100644 --- a/src/test/ui/resolve/name-clash-nullary.stderr +++ b/src/test/ui/resolve/name-clash-nullary.stderr @@ -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<_>` diff --git a/src/test/ui/rfc-2005-default-binding-mode/const.stderr b/src/test/ui/rfc-2005-default-binding-mode/const.stderr index f25fc300d7f..27efd450b94 100644 --- a/src/test/ui/rfc-2005-default-binding-mode/const.stderr +++ b/src/test/ui/rfc-2005-default-binding-mode/const.stderr @@ -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` |
