[Merged by Bors] - Make reflect_partial_eq return more accurate results#5210
[Merged by Bors] - Make reflect_partial_eq return more accurate results#5210afonsolage wants to merge 9 commits intobevyengine:mainfrom
Conversation
| 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 { |
There was a problem hiding this comment.
Woah, what's this @ syntax called?
There was a problem hiding this comment.
There was a problem hiding this comment.
The reference doesn't mention the name. It just specifies it as a subset of identifier patterns. The rust book call them "@ bindings".
- reference: https://doc.rust-lang.org/reference/patterns.html#identifier-patterns
- rust book: https://doc.rust-lang.org/book/ch18-03-pattern-syntax.html#-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
There was a problem hiding this comment.
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.
crates/bevy_reflect/src/tuple.rs
Outdated
| match a_field.reflect_partial_eq(b_field) { | ||
| Some(false) | None => return Some(false), | ||
| failed @ (Some(false) | None) => return failed, | ||
| Some(true) => {} | ||
| } |
There was a problem hiding this comment.
Nit: For consistency with the others, maybe this should be an if statement?
There was a problem hiding this comment.
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.
|
@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? |
|
Looks great. I probably wouldn't note the doc comment changes; those should accompany every change. |
|
@afonsolage once you address the nit raised above I'll merge this in :) |
|
bors r+ |
# Objective Closes #5204 ## Solution - Followed @nicopap suggestion on #4761 (comment) ## Changelog - [x] Updated [struct_trait](https://github.com/bevyengine/bevy/blob/dfe969005264fff54060f9fb148639f80f9cfb29/crates/bevy_reflect/src/struct_trait.rs#L455-L457), [tuple_struct](https://github.com/bevyengine/bevy/blob/dfe969005264fff54060f9fb148639f80f9cfb29/crates/bevy_reflect/src/tuple_struct.rs#L366-L368), [tuple](https://github.com/bevyengine/bevy/blob/dfe969005264fff54060f9fb148639f80f9cfb29/crates/bevy_reflect/src/tuple.rs#L386), [array](https://github.com/bevyengine/bevy/blob/dfe969005264fff54060f9fb148639f80f9cfb29/crates/bevy_reflect/src/array.rs#L335-L337), [list](https://github.com/bevyengine/bevy/blob/dfe969005264fff54060f9fb148639f80f9cfb29/crates/bevy_reflect/src/list.rs#L309-L311) and [map](https://github.com/bevyengine/bevy/blob/dfe969005264fff54060f9fb148639f80f9cfb29/crates/bevy_reflect/src/map.rs#L361-L363) to return `None` when comparison couldn't be performed. - [x] Updated docs comments to reflect above changes.
# Objective Closes bevyengine#5204 ## Solution - Followed @nicopap suggestion on bevyengine#4761 (comment) ## Changelog - [x] Updated [struct_trait](https://github.com/bevyengine/bevy/blob/dfe969005264fff54060f9fb148639f80f9cfb29/crates/bevy_reflect/src/struct_trait.rs#L455-L457), [tuple_struct](https://github.com/bevyengine/bevy/blob/dfe969005264fff54060f9fb148639f80f9cfb29/crates/bevy_reflect/src/tuple_struct.rs#L366-L368), [tuple](https://github.com/bevyengine/bevy/blob/dfe969005264fff54060f9fb148639f80f9cfb29/crates/bevy_reflect/src/tuple.rs#L386), [array](https://github.com/bevyengine/bevy/blob/dfe969005264fff54060f9fb148639f80f9cfb29/crates/bevy_reflect/src/array.rs#L335-L337), [list](https://github.com/bevyengine/bevy/blob/dfe969005264fff54060f9fb148639f80f9cfb29/crates/bevy_reflect/src/list.rs#L309-L311) and [map](https://github.com/bevyengine/bevy/blob/dfe969005264fff54060f9fb148639f80f9cfb29/crates/bevy_reflect/src/map.rs#L361-L363) to return `None` when comparison couldn't be performed. - [x] Updated docs comments to reflect above changes.
# Objective Closes bevyengine#5204 ## Solution - Followed @nicopap suggestion on bevyengine#4761 (comment) ## Changelog - [x] Updated [struct_trait](https://github.com/bevyengine/bevy/blob/dfe969005264fff54060f9fb148639f80f9cfb29/crates/bevy_reflect/src/struct_trait.rs#L455-L457), [tuple_struct](https://github.com/bevyengine/bevy/blob/dfe969005264fff54060f9fb148639f80f9cfb29/crates/bevy_reflect/src/tuple_struct.rs#L366-L368), [tuple](https://github.com/bevyengine/bevy/blob/dfe969005264fff54060f9fb148639f80f9cfb29/crates/bevy_reflect/src/tuple.rs#L386), [array](https://github.com/bevyengine/bevy/blob/dfe969005264fff54060f9fb148639f80f9cfb29/crates/bevy_reflect/src/array.rs#L335-L337), [list](https://github.com/bevyengine/bevy/blob/dfe969005264fff54060f9fb148639f80f9cfb29/crates/bevy_reflect/src/list.rs#L309-L311) and [map](https://github.com/bevyengine/bevy/blob/dfe969005264fff54060f9fb148639f80f9cfb29/crates/bevy_reflect/src/map.rs#L361-L363) to return `None` when comparison couldn't be performed. - [x] Updated docs comments to reflect above changes.
# Objective Closes bevyengine#5204 ## Solution - Followed @nicopap suggestion on bevyengine#4761 (comment) ## Changelog - [x] Updated [struct_trait](https://github.com/bevyengine/bevy/blob/dfe969005264fff54060f9fb148639f80f9cfb29/crates/bevy_reflect/src/struct_trait.rs#L455-L457), [tuple_struct](https://github.com/bevyengine/bevy/blob/dfe969005264fff54060f9fb148639f80f9cfb29/crates/bevy_reflect/src/tuple_struct.rs#L366-L368), [tuple](https://github.com/bevyengine/bevy/blob/dfe969005264fff54060f9fb148639f80f9cfb29/crates/bevy_reflect/src/tuple.rs#L386), [array](https://github.com/bevyengine/bevy/blob/dfe969005264fff54060f9fb148639f80f9cfb29/crates/bevy_reflect/src/array.rs#L335-L337), [list](https://github.com/bevyengine/bevy/blob/dfe969005264fff54060f9fb148639f80f9cfb29/crates/bevy_reflect/src/list.rs#L309-L311) and [map](https://github.com/bevyengine/bevy/blob/dfe969005264fff54060f9fb148639f80f9cfb29/crates/bevy_reflect/src/map.rs#L361-L363) to return `None` when comparison couldn't be performed. - [x] Updated docs comments to reflect above changes.
Objective
Closes #5204
Solution
Changelog
Nonewhen comparison couldn't be performed.