diff options
| author | Michael Goulet <michael@errs.io> | 2023-05-30 17:39:12 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2023-06-08 16:17:30 +0000 |
| commit | 522ae84e0344669ee64754595dd5f04eed9f0d1c (patch) | |
| tree | 4db57d0d729ed8fdd984792ddc5e0b71b3a04fed | |
| parent | e7409258db4a43f23dcc66e10061dee91c316055 (diff) | |
| download | rust-522ae84e0344669ee64754595dd5f04eed9f0d1c.tar.gz rust-522ae84e0344669ee64754595dd5f04eed9f0d1c.zip | |
Suggest type mismatches even when using ref syntax on binding
| -rw-r--r-- | compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs | 12 | ||||
| -rw-r--r-- | tests/ui/switched-expectations.stderr | 4 |
2 files changed, 14 insertions, 2 deletions
diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 30a543aab50..48c3d6f08de 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -1404,7 +1404,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // type of the place it is referencing, and not some // supertype thereof. let init_ty = self.check_expr_with_needs(init, Needs::maybe_mut_place(m)); - self.demand_eqtype(init.span, local_ty, init_ty); + if let Some(mut diag) = self.demand_eqtype_diag(init.span, local_ty, init_ty) { + self.emit_type_mismatch_suggestions( + &mut diag, + init.peel_drop_temps(), + init_ty, + local_ty, + None, + None, + ); + diag.emit(); + } init_ty } else { self.check_expr_coercible_to_type(init, local_ty, None) diff --git a/tests/ui/switched-expectations.stderr b/tests/ui/switched-expectations.stderr index 744d8483bd3..6e1bbf701d7 100644 --- a/tests/ui/switched-expectations.stderr +++ b/tests/ui/switched-expectations.stderr @@ -2,7 +2,9 @@ error[E0308]: mismatched types --> $DIR/switched-expectations.rs:3:30 | LL | let ref string: String = var; - | ^^^ expected `String`, found `i32` + | ^^^- help: try using a conversion method: `.to_string()` + | | + | expected `String`, found `i32` error: aborting due to previous error |
