Skip to content

Commit e9f6bb7

Browse files
committed
check_pat_path: use pattern_cause
1 parent 1d33717 commit e9f6bb7

File tree

9 files changed

+27
-5
lines changed

9 files changed

+27
-5
lines changed

src/librustc_typeck/check/pat.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
155155
self.check_pat_tuple_struct(pat, qpath, subpats, ddpos, expected, def_bm, ti)
156156
}
157157
PatKind::Path(ref qpath) => {
158-
self.check_pat_path(pat, path_res.unwrap(), qpath, expected)
158+
self.check_pat_path(pat, path_res.unwrap(), qpath, expected, ti)
159159
}
160160
PatKind::Struct(ref qpath, fields, etc) => {
161161
self.check_pat_struct(pat, qpath, fields, etc, expected, def_bm, ti)
@@ -671,6 +671,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
671671
path_resolution: (Res, Option<Ty<'tcx>>, &'b [hir::PathSegment<'b>]),
672672
qpath: &hir::QPath<'_>,
673673
expected: Ty<'tcx>,
674+
ti: TopInfo<'tcx>,
674675
) -> Ty<'tcx> {
675676
let tcx = self.tcx;
676677

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

697698
// Type-check the path.
698699
let pat_ty = self.instantiate_value_path(segments, opt_ty, res, pat.span, pat.hir_id).0;
699-
self.demand_suptype(pat.span, expected, pat_ty);
700+
if let Some(mut err) =
701+
self.demand_suptype_with_origin(&self.pattern_cause(ti, pat.span), expected, pat_ty)
702+
{
703+
err.emit();
704+
}
700705
pat_ty
701706
}
702707

src/test/ui/issues/issue-12552.stderr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ LL | Some(k) => match k {
1212
error[E0308]: mismatched types
1313
--> $DIR/issue-12552.rs:9:5
1414
|
15+
LL | match t {
16+
| - this expression has type `std::result::Result<_, {integer}>`
17+
...
1518
LL | None => ()
1619
| ^^^^ expected enum `std::result::Result`, found enum `std::option::Option`
1720
|

src/test/ui/issues/issue-37026.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0308]: mismatched types
22
--> $DIR/issue-37026.rs:6:9
33
|
44
LL | let empty_struct::XEmpty2 = ();
5-
| ^^^^^^^^^^^^^^^^^^^^^ expected `()`, found struct `empty_struct::XEmpty2`
5+
| ^^^^^^^^^^^^^^^^^^^^^ -- this expression has type `()`
6+
| |
7+
| expected `()`, found struct `empty_struct::XEmpty2`
68

79
error[E0308]: mismatched types
810
--> $DIR/issue-37026.rs:7:9

src/test/ui/issues/issue-5100.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
error[E0308]: mismatched types
22
--> $DIR/issue-5100.rs:8:9
33
|
4+
LL | match (true, false) {
5+
| ------------- this expression has type `(bool, bool)`
46
LL | A::B => (),
57
| ^^^^ expected tuple, found enum `A`
68
|

src/test/ui/issues/issue-7867.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
error[E0308]: mismatched types
22
--> $DIR/issue-7867.rs:7:9
33
|
4+
LL | match (true, false) {
5+
| ------------- this expression has type `(bool, bool)`
46
LL | A::B => (),
57
| ^^^^ expected tuple, found enum `A`
68
|

src/test/ui/match/match-tag-nullary.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0308]: mismatched types
22
--> $DIR/match-tag-nullary.rs:4:40
33
|
44
LL | fn main() { let x: A = A::A; match x { B::B => { } } }
5-
| ^^^^ expected enum `A`, found enum `B`
5+
| - ^^^^ expected enum `A`, found enum `B`
6+
| |
7+
| this expression has type `A`
68

79
error: aborting due to previous error
810

src/test/ui/pattern/pattern-ident-path-generics.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
error[E0308]: mismatched types
22
--> $DIR/pattern-ident-path-generics.rs:3:9
33
|
4+
LL | match Some("foo") {
5+
| ----------- this expression has type `std::option::Option<&str>`
46
LL | None::<isize> => {}
57
| ^^^^^^^^^^^^^ expected `&str`, found `isize`
68
|

src/test/ui/resolve/name-clash-nullary.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0308]: mismatched types
22
--> $DIR/name-clash-nullary.rs:2:7
33
|
44
LL | let None: isize = 42;
5-
| ^^^^ expected `isize`, found enum `std::option::Option`
5+
| ^^^^ ----- expected due to this
6+
| |
7+
| expected `isize`, found enum `std::option::Option`
68
|
79
= note: expected type `isize`
810
found enum `std::option::Option<_>`

src/test/ui/rfc-2005-default-binding-mode/const.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
error[E0308]: mismatched types
22
--> $DIR/const.rs:14:9
33
|
4+
LL | match &f {
5+
| -- this expression has type `&Foo`
46
LL | FOO => {},
57
| ^^^ expected `&Foo`, found struct `Foo`
68

0 commit comments

Comments
 (0)