Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/infer/cast.rs')
| -rw-r--r-- | crates/hir-ty/src/infer/cast.rs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/crates/hir-ty/src/infer/cast.rs b/crates/hir-ty/src/infer/cast.rs index 43364963eb..bc3ee3c4c5 100644 --- a/crates/hir-ty/src/infer/cast.rs +++ b/crates/hir-ty/src/infer/cast.rs @@ -106,6 +106,13 @@ impl CastCheck { self.expr_ty = table.eagerly_normalize_and_resolve_shallow_in(self.expr_ty.clone()); self.cast_ty = table.eagerly_normalize_and_resolve_shallow_in(self.cast_ty.clone()); + // This should always come first so that we apply the coercion, which impacts infer vars. + if let Ok((adj, _)) = table.coerce(&self.expr_ty, &self.cast_ty, CoerceNever::Yes) { + apply_adjustments(self.source_expr, adj); + set_coercion_cast(self.source_expr); + return Ok(()); + } + if self.expr_ty.contains_unknown() || self.cast_ty.contains_unknown() { return Ok(()); } @@ -126,12 +133,6 @@ impl CastCheck { return Ok(()); } - if let Ok((adj, _)) = table.coerce(&self.expr_ty, &self.cast_ty, CoerceNever::Yes) { - apply_adjustments(self.source_expr, adj); - set_coercion_cast(self.source_expr); - return Ok(()); - } - self.do_check(table, apply_adjustments) .map_err(|e| e.into_diagnostic(self.expr, self.expr_ty.clone(), self.cast_ty.clone())) } |