Suggest type mismatches even when using ref syntax on binding
This commit is contained in:
parent
e7409258db
commit
522ae84e03
@ -1404,7 +1404,17 @@ pub fn check_decl_initializer(
|
||||
// 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)
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user