Skip to content

Commit

Permalink
check_pat_ref: use pattern_cause
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Feb 25, 2020
1 parent b1de8f1 commit d234e13
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)`
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/destructure-trait-ref.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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`
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
Expand Up @@ -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
|
Expand Down
9 changes: 6 additions & 3 deletions src/test/ui/mismatched_types/issue-38371.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`
|
Expand All @@ -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`
Expand All @@ -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 `&_`
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/mut/mut-pattern-mismatched.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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 `&_`
Expand All @@ -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 _`
Expand Down
6 changes: 5 additions & 1 deletion src/test/ui/suggestions/match-ergonomics.stderr
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
error[E0308]: mismatched types
--> $DIR/match-ergonomics.rs:4:10
|
LL | match &x[..] {
| ------ this expression has type `&[i32]`
LL | [&v] => {},
| ^^
| |
Expand All @@ -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 => {},
| ^^
| |
Expand All @@ -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`
Expand Down

0 comments on commit d234e13

Please sign in to comment.