]> git.lizzy.rs Git - rust.git/commitdiff
check_pat_ref: use pattern_cause
authorMazdak Farrokhzad <twingoow@gmail.com>
Tue, 25 Feb 2020 04:53:21 +0000 (05:53 +0100)
committerMazdak Farrokhzad <twingoow@gmail.com>
Tue, 25 Feb 2020 04:53:21 +0000 (05:53 +0100)
src/librustc_typeck/check/pat.rs
src/test/ui/destructure-trait-ref.stderr
src/test/ui/issues/issue-5100.stderr
src/test/ui/mismatched_types/issue-38371.stderr
src/test/ui/mut/mut-pattern-mismatched.stderr
src/test/ui/suggestions/match-ergonomics.stderr

index da78667160e10c5f0ae226263b97d7d3803770fb..1df7c64f2c6f0e233475d100aff5a003600b5ab5 100644 (file)
@@ -1222,7 +1222,7 @@ fn check_pat_ref(
                     });
                     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)`
index f99bf2ffdc9d45dc85d7915d7776762ed0a5e6f2..1382cf643a17331cd7c18d2a7f8f619da16b3a2c 100644 (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`
index 070c09d745b9ce61e77da48c30a2f2d71a13216a..c81d6dcaf02173df0c0cfec556685c5da3b4cf7b 100644 (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
    |
index 802a2fef6bd40f24aa504f5fd1ad8714370c2575..c2bce305877b4048f3ead8d07f7fcb217917cb4c 100644 (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 `&_`
index ccc8ac1278c63576c2ed2d253c653f312e9f8338..cad1cef5155d5f1ba54e81808a613ebbaa467129 100644 (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 _`
index abdb754acc5fac48225087b160fa722778c5133d..559a2d29551d32295bc3e55c642ca7c1fb17cfb2 100644 (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`