Skip to content

fix: Implement Expactation::Castable and add a test case for it #14104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2023

Conversation

Veykril
Copy link
Member

@Veykril Veykril commented Feb 8, 2023

Fixes #11571

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 8, 2023
@Veykril
Copy link
Member Author

Veykril commented Feb 8, 2023

@bors r+

@bors
Copy link
Contributor

bors commented Feb 8, 2023

📌 Commit 527ae76 has been approved by Veykril

It is now in the queue for this repository.

bors added a commit that referenced this pull request Feb 8, 2023
fix: Implement Expactation::Castable and add a test case for it

Fixes #11571
@bors
Copy link
Contributor

bors commented Feb 8, 2023

⌛ Testing commit 527ae76 with merge 8c99124...

@bors
Copy link
Contributor

bors commented Feb 8, 2023

💔 Test failed - checks-actions

@Veykril
Copy link
Member Author

Veykril commented Feb 8, 2023

@bors r+

@bors
Copy link
Contributor

bors commented Feb 8, 2023

📌 Commit f8f1cb9 has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Feb 8, 2023

⌛ Testing commit f8f1cb9 with merge eaed19c...

@bors
Copy link
Contributor

bors commented Feb 8, 2023

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing eaed19c to master...

@bors bors merged commit eaed19c into rust-lang:master Feb 8, 2023
@Veykril Veykril deleted the castable-expect branch February 16, 2023 09:14
bors added a commit that referenced this pull request Jul 28, 2023
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`]: https://github.com/rust-lang/rust/blob/da1d099f91ea387a2814a6244dd875a2048b486f/compiler/rustc_hir_typeck/src/cast.rs#L55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A test for cast propagation
3 participants