rust/crates/hir-ty
bors 037844c8a0 Auto merge of #15271 - lowr:patch/re-castable, r=HKalbasi
Properly infer types with type casts

This PR reenables `Expectation::Castable` (previous attempt at #14104, reverted by #14120) and implements type cast checks, which enable us to infer a bit more.

Castable expectations are relatively weak -- they only influence the inference if we cannot infer the types by other means. Therefore, we need to defer possible type unification with the casted type until we type check all expressions of the body. This PR adds a struct and slots in `InferenceContext` for the deferred cast checks (c.f. [`CastCheck`] in `rustc_hir_typeck`).

I only implemented the bits that affect the inference result. It should be possible to return type adjustments for well-formed casts and report diagnostics for invalid casts, but I'm leaving them for future work for now.

Fixes #11571
Fixes #15246

[`CastCheck`]: da1d099f91/compiler/rustc_hir_typeck/src/cast.rs (L55)
2023-07-28 07:17:38 +00:00
..
src Auto merge of #15271 - lowr:patch/re-castable, r=HKalbasi 2023-07-28 07:17:38 +00:00
Cargo.toml Support getrandom syscall 2023-07-11 00:29:06 +03:30