-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Fix parameter order for _by()
variants of min
/ max
/ minmax
in std::cmp
#139357
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
base: master
Are you sure you want to change the base?
Conversation
_by()
variants of min
/ max
/ minmax
i…_by()
variants of min
/ max
/ minmax
in std::cmp
@thomcc please let me know if you have any suggestions |
Can you add a test covering this? |
Hi, I've nominated this because it's a behavioral change. I gather it reverts an earlier behavioral change that we made unintentionally. |
doctest added & rebased on latest master |
We discussed this in the libs meeting. We would like to make this a documented guarantee. Could you update the documentation to actually guarantee that the ordering is preserved when passed to the closure? @rfcbot merge |
Team member @Amanieu has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
I just want to emphasize that violating duality like this is already explicitly called out as "a logic error" in the trait documentation, and thus anyone writing things like this should expect that their garbage in will result in garbage out in various situations. It's ok if we want to give something stronger for these functions, since we know that they only need one check (to the extent that the Also, this was an intentional change, since historically Hopefully it's better now, as a bunch of work has happened in rust and LLVM to try to improve things, but... |
We saw a regression introduced in version
1.86
that seems to be coming from switching the order ofv1
andv2
when callingcomparison
functions inmin_by
/max_by
/minmax_by
(cf. this PR: #136307)When the
compare
function is not symmetric in the arguments, this leads to false results. Apparently, the test cases do not cover this scenario currently. While asymmetric comparison may be an edge case, but current behavior is unexpected nevertheless.