Skip to content

Commit f9f3f13

Browse files
committed
fix accidental type inference in array coercion
1 parent 70237a8 commit f9f3f13

File tree

1 file changed

+3
-1
lines changed
  • compiler/rustc_hir_typeck/src

1 file changed

+3
-1
lines changed

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1760,7 +1760,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17601760
let coerce_to = expected
17611761
.to_option(self)
17621762
.and_then(|uty| match *self.try_structurally_resolve_type(expr.span, uty).kind() {
1763-
ty::Array(ty, _) | ty::Slice(ty) => Some(ty),
1763+
// Avoid using a type variable as the coerce_to type, as it may resolve
1764+
// during the first coercion instead of being based on the common type.
1765+
ty::Array(ty, _) | ty::Slice(ty) if !ty.is_ty_var() => Some(ty),
17641766
_ => None,
17651767
})
17661768
.unwrap_or_else(|| self.next_ty_var(expr.span));

0 commit comments

Comments
 (0)