check_pat_ref: use pattern_cause

This commit is contained in:
Mazdak Farrokhzad 2020-02-25 05:53:21 +01:00
parent b1de8f16ca
commit d234e131b8
6 changed files with 22 additions and 7 deletions

View File

@ -1222,7 +1222,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
});
let rptr_ty = self.new_ref_ty(pat.span, mutbl, inner_ty);
debug!("check_pat_ref: demanding {:?} = {:?}", expected, rptr_ty);
let err = self.demand_eqtype_diag(pat.span, expected, rptr_ty);
let err = self.demand_eqtype_pat_diag(pat.span, expected, rptr_ty, ti);
// Look for a case like `fn foo(&foo: u32)` and suggest
// `fn foo(foo: &u32)`

View File

@ -20,7 +20,7 @@ error[E0308]: mismatched types
--> $DIR/destructure-trait-ref.rs:32:10
|
LL | let &&x = &1isize as &dyn T;
| ^^
| ^^ ----------------- this expression has type `&dyn T`
| |
| expected trait object `dyn T`, found reference
| help: you can probably remove the explicit borrow: `x`
@ -32,7 +32,7 @@ error[E0308]: mismatched types
--> $DIR/destructure-trait-ref.rs:36:11
|
LL | let &&&x = &(&1isize as &dyn T);
| ^^
| ^^ -------------------- this expression has type `&&dyn T`
| |
| expected trait object `dyn T`, found reference
| help: you can probably remove the explicit borrow: `x`

View File

@ -45,6 +45,8 @@ LL | box (true, false) => ()
error[E0308]: mismatched types
--> $DIR/issue-5100.rs:40:9
|
LL | match (true, false) {
| ------------- this expression has type `(bool, bool)`
LL | &(true, false) => ()
| ^^^^^^^^^^^^^^ expected tuple, found reference
|

View File

@ -3,7 +3,8 @@ error[E0308]: mismatched types
|
LL | fn foo(&foo: Foo) {
| ^^^^------
| |
| | |
| | expected due to this
| expected struct `Foo`, found reference
| help: did you mean `foo`: `&Foo`
|
@ -14,7 +15,7 @@ error[E0308]: mismatched types
--> $DIR/issue-38371.rs:18:9
|
LL | fn agh(&&bar: &u32) {
| ^^^^
| ^^^^ ---- expected due to this
| |
| expected `u32`, found reference
| help: you can probably remove the explicit borrow: `bar`
@ -26,7 +27,9 @@ error[E0308]: mismatched types
--> $DIR/issue-38371.rs:21:8
|
LL | fn bgh(&&bar: u32) {
| ^^^^^ expected `u32`, found reference
| ^^^^^ --- expected due to this
| |
| expected `u32`, found reference
|
= note: expected type `u32`
found reference `&_`

View File

@ -3,6 +3,9 @@ error[E0308]: mismatched types
|
LL | let &_
| ^^ types differ in mutability
...
LL | = foo;
| --- this expression has type `&mut {integer}`
|
= note: expected mutable reference `&mut {integer}`
found reference `&_`
@ -12,6 +15,9 @@ error[E0308]: mismatched types
|
LL | let &mut _
| ^^^^^^ types differ in mutability
...
LL | = bar;
| --- this expression has type `&{integer}`
|
= note: expected reference `&{integer}`
found mutable reference `&mut _`

View File

@ -1,6 +1,8 @@
error[E0308]: mismatched types
--> $DIR/match-ergonomics.rs:4:10
|
LL | match &x[..] {
| ------ this expression has type `&[i32]`
LL | [&v] => {},
| ^^
| |
@ -25,6 +27,8 @@ LL | [v] => {},
error[E0308]: mismatched types
--> $DIR/match-ergonomics.rs:29:9
|
LL | match y {
| - this expression has type `i32`
LL | &v => {},
| ^^
| |
@ -38,7 +42,7 @@ error[E0308]: mismatched types
--> $DIR/match-ergonomics.rs:40:13
|
LL | if let [&v] = &x[..] {}
| ^^
| ^^ ------ this expression has type `&[i32]`
| |
| expected `i32`, found reference
| help: you can probably remove the explicit borrow: `v`