Skip to content
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 by Bors] - Make reflect_partial_eq return more accurate results #5210

Closed

Conversation

afonsolage
Copy link
Contributor

@afonsolage afonsolage commented Jul 5, 2022

Objective

Closes #5204

Solution

Changelog

Copy link
Contributor

@nicopap nicopap left a comment

Choose a reason for hiding this comment

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

LGTM, but maybe this could wait until #4761 is merged?

if let Some(false) | None = a.reflect_partial_eq(b) {
return Some(false);
let eq_result = a.reflect_partial_eq(b);
if let failed @ (Some(false) | None) = eq_result {
Copy link
Member

Choose a reason for hiding this comment

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

Woah, what's this @ syntax called?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor

@nicopap nicopap Jul 5, 2022

Choose a reason for hiding this comment

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

The reference doesn't mention the name. It just specifies it as a subset of identifier patterns. The rust book call them "@ bindings".

In traditional functional languages (Haskell, Ocaml), they usually use the as keyword. In rust this wouldn't work since it's the explicit casting operator. Looks like the Ocaml reference calls them "alias patterns", which I think is pretty descriptive https://v2.ocaml.org/manual/patterns.html#sss:pat-alias

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was new to me too. I had to check docs when I saw the @(at) pattern bindings. I'm glad I learn something new and useful.

@alice-i-cecile alice-i-cecile added C-Code-Quality A section of code that is hard to understand or change A-Reflection Runtime information about types labels Jul 5, 2022
Copy link
Member

@MrGVSV MrGVSV left a comment

Choose a reason for hiding this comment

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

LGTM!

Comment on lines 387 to 390
match a_field.reflect_partial_eq(b_field) {
Some(false) | None => return Some(false),
failed @ (Some(false) | None) => return failed,
Some(true) => {}
}
Copy link
Member

Choose a reason for hiding this comment

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

Nit: For consistency with the others, maybe this should be an if statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had the same thought, but I didn't wanted to touch to make changes as simple as possible. But this doesn't seems to be enough change to have it's own PR, so I can do it without any problems.

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Jul 5, 2022
@alice-i-cecile
Copy link
Member

alice-i-cecile commented Jul 5, 2022

@afonsolage can you add a brief Changelog section to your PR description to capture the changed behavior? You can just borrow from the linked issue.

Breaking change label added as this is subtly different (and more correct) behavior that will need migration work.

@alice-i-cecile alice-i-cecile added the M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label Jul 5, 2022
@afonsolage
Copy link
Contributor Author

@afonsolage can you add a brief Changelog section to your PR description to capture the changed behavior? You can just borrow from the linked issue.

Breaking change label added as this is subtly different (and more correct) behavior that will need migration work.

Added changelog. This way is good?

@alice-i-cecile
Copy link
Member

alice-i-cecile commented Jul 5, 2022

Looks great. I probably wouldn't note the doc comment changes; those should accompany every change.

@alice-i-cecile
Copy link
Member

@afonsolage once you address the nit raised above I'll merge this in :)

@alice-i-cecile
Copy link
Member

bors r+

@bors bors bot changed the title Make reflect_partial_eq return more accurate results [Merged by Bors] - Make reflect_partial_eq return more accurate results Jul 5, 2022
@bors bors bot closed this Jul 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Reflection Runtime information about types C-Code-Quality A section of code that is hard to understand or change M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make reflect_partial_eq return more accurate results
5 participants