rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

`non_canonical_partial_ord_impl` is overzealous for trivial impls

Open clarfonthey opened this issue 10 months ago • 5 comments

Summary

I have a ZST where I'm manually implementing PartialOrd and Ord to remove some trait bounds. However, it warns that inlining the trivial Equal result as Some(Equal) in the PartialOrd impl is non-canonical.

I think that in this particular case, we can loosen the lint a bit. Calling the method is overkill and can increase the amount of generated code.

Lint Name

non_canonical_partial_ord_impl

Reproducer

This should not trigger the lint:

use core::cmp;

pub struct Test;

impl PartialOrd for Test {
    fn partial_cmp(&self, _: &Self) -> Option<cmp::Ordering> {
        Some(cmp::Ordering::Equal)
    }
}

impl Ord for Test {
    fn cmp(&self, _: &Self) -> cmp::Ordering {
        cmp::Ordering::Equal
    }
}

Version

clippy 0.1.94 (2850ca8295 2026-01-13)

Additional Labels

No response

clarfonthey avatar Jan 17 '26 15:01 clarfonthey

This is neither a bug nor a false positive, but a request for enhancement.

@rustbot label -C-bug -I-false-positive +C-enhancement

samueltardieu avatar Jan 17 '26 23:01 samueltardieu

I labelled it as a false positive because it's a request to make a lint not fire when it currently is, but sure, we can call it an enhancement too. The specific label here doesn't matter.

clarfonthey avatar Jan 18 '26 01:01 clarfonthey

@rustbot claim

Carlos-Chong200 avatar Feb 09 '26 06:02 Carlos-Chong200

Hi @samueltardieu! I’ve recently submitted a PR for a Clippy good-first-issue improving a lint, and I’d be interested in working on this enhancement as well.

Carlos-Chong200 avatar Feb 09 '26 06:02 Carlos-Chong200

@rustbot claim

saberoueslati avatar Sep 18 '26 22:09 saberoueslati