Derive PartialOrd
via Ord
when deriving both on a concrete type
#137459
Labels
C-optimization
Category: An issue highlighting optimization opportunities or PRs implementing such
I-heavy
Issue: Problems and improvements with respect to binary size of generated code.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Today, if you do https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=1ba35655ac2a5a415dc94df6a2b04988
it expands to
That's wonderful -- it's simpler than a bunch of
clone
calls, and likely codegens better too.However, if you try
you just get
which is unfortunate, because all those options take more time to compile and are harder for backends to optimize away.
It would be nice if, instead, it expanded to something like
Re-using the logic from
Ord
and making it easier for the optimizer to know thatFoo::partial_cmp
never actually returnsNone
.Like with
Clone
, this must only be done for fully concrete (non-generic) types, where the fact thatOrd
is also derived is enough to guarantee that we can callOrd
fromPartialOrd
(as there will be a compiler error in the derivedOrd
if not).The text was updated successfully, but these errors were encountered: