From d234e131b8651ccf4bf8df05c9182e1085fa48fa Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 25 Feb 2020 05:53:21 +0100 Subject: [PATCH] check_pat_ref: use pattern_cause --- src/librustc_typeck/check/pat.rs | 2 +- src/test/ui/destructure-trait-ref.stderr | 4 ++-- src/test/ui/issues/issue-5100.stderr | 2 ++ src/test/ui/mismatched_types/issue-38371.stderr | 9 ++++++--- src/test/ui/mut/mut-pattern-mismatched.stderr | 6 ++++++ src/test/ui/suggestions/match-ergonomics.stderr | 6 +++++- 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/librustc_typeck/check/pat.rs b/src/librustc_typeck/check/pat.rs index da78667160e..1df7c64f2c6 100644 --- a/src/librustc_typeck/check/pat.rs +++ b/src/librustc_typeck/check/pat.rs @@ -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)` diff --git a/src/test/ui/destructure-trait-ref.stderr b/src/test/ui/destructure-trait-ref.stderr index f99bf2ffdc9..1382cf643a1 100644 --- a/src/test/ui/destructure-trait-ref.stderr +++ b/src/test/ui/destructure-trait-ref.stderr @@ -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` diff --git a/src/test/ui/issues/issue-5100.stderr b/src/test/ui/issues/issue-5100.stderr index 070c09d745b..c81d6dcaf02 100644 --- a/src/test/ui/issues/issue-5100.stderr +++ b/src/test/ui/issues/issue-5100.stderr @@ -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 | diff --git a/src/test/ui/mismatched_types/issue-38371.stderr b/src/test/ui/mismatched_types/issue-38371.stderr index 802a2fef6bd..c2bce305877 100644 --- a/src/test/ui/mismatched_types/issue-38371.stderr +++ b/src/test/ui/mismatched_types/issue-38371.stderr @@ -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 `&_` diff --git a/src/test/ui/mut/mut-pattern-mismatched.stderr b/src/test/ui/mut/mut-pattern-mismatched.stderr index ccc8ac1278c..cad1cef5155 100644 --- a/src/test/ui/mut/mut-pattern-mismatched.stderr +++ b/src/test/ui/mut/mut-pattern-mismatched.stderr @@ -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 _` diff --git a/src/test/ui/suggestions/match-ergonomics.stderr b/src/test/ui/suggestions/match-ergonomics.stderr index abdb754acc5..559a2d29551 100644 --- a/src/test/ui/suggestions/match-ergonomics.stderr +++ b/src/test/ui/suggestions/match-ergonomics.stderr @@ -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`