Skip to content

Commit d234e13

Browse files
committed
check_pat_ref: use pattern_cause
1 parent b1de8f1 commit d234e13

File tree

6 files changed

+22
-7
lines changed

6 files changed

+22
-7
lines changed

src/librustc_typeck/check/pat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12221222
});
12231223
let rptr_ty = self.new_ref_ty(pat.span, mutbl, inner_ty);
12241224
debug!("check_pat_ref: demanding {:?} = {:?}", expected, rptr_ty);
1225-
let err = self.demand_eqtype_diag(pat.span, expected, rptr_ty);
1225+
let err = self.demand_eqtype_pat_diag(pat.span, expected, rptr_ty, ti);
12261226

12271227
// Look for a case like `fn foo(&foo: u32)` and suggest
12281228
// `fn foo(foo: &u32)`

src/test/ui/destructure-trait-ref.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ error[E0308]: mismatched types
2020
--> $DIR/destructure-trait-ref.rs:32:10
2121
|
2222
LL | let &&x = &1isize as &dyn T;
23-
| ^^
23+
| ^^ ----------------- this expression has type `&dyn T`
2424
| |
2525
| expected trait object `dyn T`, found reference
2626
| help: you can probably remove the explicit borrow: `x`
@@ -32,7 +32,7 @@ error[E0308]: mismatched types
3232
--> $DIR/destructure-trait-ref.rs:36:11
3333
|
3434
LL | let &&&x = &(&1isize as &dyn T);
35-
| ^^
35+
| ^^ -------------------- this expression has type `&&dyn T`
3636
| |
3737
| expected trait object `dyn T`, found reference
3838
| help: you can probably remove the explicit borrow: `x`

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

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ LL | box (true, false) => ()
4545
error[E0308]: mismatched types
4646
--> $DIR/issue-5100.rs:40:9
4747
|
48+
LL | match (true, false) {
49+
| ------------- this expression has type `(bool, bool)`
4850
LL | &(true, false) => ()
4951
| ^^^^^^^^^^^^^^ expected tuple, found reference
5052
|

src/test/ui/mismatched_types/issue-38371.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ error[E0308]: mismatched types
33
|
44
LL | fn foo(&foo: Foo) {
55
| ^^^^------
6-
| |
6+
| | |
7+
| | expected due to this
78
| expected struct `Foo`, found reference
89
| help: did you mean `foo`: `&Foo`
910
|
@@ -14,7 +15,7 @@ error[E0308]: mismatched types
1415
--> $DIR/issue-38371.rs:18:9
1516
|
1617
LL | fn agh(&&bar: &u32) {
17-
| ^^^^
18+
| ^^^^ ---- expected due to this
1819
| |
1920
| expected `u32`, found reference
2021
| help: you can probably remove the explicit borrow: `bar`
@@ -26,7 +27,9 @@ error[E0308]: mismatched types
2627
--> $DIR/issue-38371.rs:21:8
2728
|
2829
LL | fn bgh(&&bar: u32) {
29-
| ^^^^^ expected `u32`, found reference
30+
| ^^^^^ --- expected due to this
31+
| |
32+
| expected `u32`, found reference
3033
|
3134
= note: expected type `u32`
3235
found reference `&_`

src/test/ui/mut/mut-pattern-mismatched.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ error[E0308]: mismatched types
33
|
44
LL | let &_
55
| ^^ types differ in mutability
6+
...
7+
LL | = foo;
8+
| --- this expression has type `&mut {integer}`
69
|
710
= note: expected mutable reference `&mut {integer}`
811
found reference `&_`
@@ -12,6 +15,9 @@ error[E0308]: mismatched types
1215
|
1316
LL | let &mut _
1417
| ^^^^^^ types differ in mutability
18+
...
19+
LL | = bar;
20+
| --- this expression has type `&{integer}`
1521
|
1622
= note: expected reference `&{integer}`
1723
found mutable reference `&mut _`

src/test/ui/suggestions/match-ergonomics.stderr

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
error[E0308]: mismatched types
22
--> $DIR/match-ergonomics.rs:4:10
33
|
4+
LL | match &x[..] {
5+
| ------ this expression has type `&[i32]`
46
LL | [&v] => {},
57
| ^^
68
| |
@@ -25,6 +27,8 @@ LL | [v] => {},
2527
error[E0308]: mismatched types
2628
--> $DIR/match-ergonomics.rs:29:9
2729
|
30+
LL | match y {
31+
| - this expression has type `i32`
2832
LL | &v => {},
2933
| ^^
3034
| |
@@ -38,7 +42,7 @@ error[E0308]: mismatched types
3842
--> $DIR/match-ergonomics.rs:40:13
3943
|
4044
LL | if let [&v] = &x[..] {}
41-
| ^^
45+
| ^^ ------ this expression has type `&[i32]`
4246
| |
4347
| expected `i32`, found reference
4448
| help: you can probably remove the explicit borrow: `v`

0 commit comments

Comments
 (0)