Skip to content

More type inference for more binary expressions #451

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 3 commits into from
Jan 7, 2019
Merged

More type inference for more binary expressions #451

merged 3 commits into from
Jan 7, 2019

Conversation

marcusklaas
Copy link
Contributor

Implements more of #390. Just works for primitive (numeric) types for now.

Found an issue where let x: Ty = expr; doesn't actually propagate the type information unless Ty is primitive and numeric. I'll open an issue for this.

Mostly just for primitive numeric types such as u32 and f64. Not
yet a general solution using trait resolution.
Copy link
Member

@flodiebold flodiebold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM apart from two nits and a missing file ;)

@@ -529,15 +529,40 @@ struct InferenceContext<'a, D: HirDatabase> {

// helper function that determines whether a binary operator
// always returns a boolean
fn is_boolean_operator(op: BinaryOp) -> bool {
fn boolean_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be called binary_op_return_ty, right? it's not just for boolean ops. Also, the comment is outdated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!

let lhs_ty = self.infer_expr(*lhs, &lhs_expectation)?;
// TODO: find implementation of trait corresponding to operation
// symbol and resolve associated `Output` type
let rhs_expectation = match op {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this big match could also be extracted into a function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Will do.

}
"#,
"boolean_op.txt",
"binary_op.txt",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems you forgot to add the renamed file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uhh, I forgot to add it to git I think! 😨

@marcusklaas
Copy link
Contributor Author

Thanks again for the review and apologies for the sloppy mistakes - I will try to do better!

@flodiebold
Copy link
Member

No problem, thank you 😄

bors r+

bors bot added a commit that referenced this pull request Jan 7, 2019
451: More type inference for more binary expressions r=flodiebold a=marcusklaas

Implements more of #390. Just works for primitive (numeric) types for now.

Found an issue where `let x: Ty = expr;` doesn't actually propagate the type information unless `Ty` is primitive and numeric. I'll open an issue for this.

Co-authored-by: Marcus Klaas de Vries <[email protected]>
@bors
Copy link
Contributor

bors bot commented Jan 7, 2019

Build succeeded

@bors bors bot merged commit 5d15dd7 into rust-lang:master Jan 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants