Skip to content

Fix broken Eq/Ord consistency for AssetCapacity#1206

Closed
Copilot wants to merge 2 commits intomainfrom
copilot/fix-eq-ord-semantics-assetcapacity
Closed

Fix broken Eq/Ord consistency for AssetCapacity#1206
Copilot wants to merge 2 commits intomainfrom
copilot/fix-eq-ord-semantics-assetcapacity

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 17, 2026

AssetCapacity derived PartialEq (float == semantics) while Ord used total_cmp, violating the Rust contract that a == b must imply a.cmp(&b) == Ordering::Equal. Concretely, Continuous(0.0) == Continuous(-0.0) was true but cmp returned Less.

Changes

  • src/asset/capacity.rs: Remove PartialEq from #[derive]; add a manual impl PartialEq that delegates to self.cmp(other) == Ordering::Equal, aligning equality with total_cmp ordering:
impl PartialEq for AssetCapacity {
    fn eq(&self, other: &Self) -> bool {
        self.cmp(other) == Ordering::Equal
    }
}
  • Tests: Add parameterised eq_consistent_with_ord cases covering the 0.0 vs -0.0 edge case, equal/unequal continuous, and equal/unequal discrete variants.
  • Release notes: Add entry to docs/release_notes/upcoming.md.
Original prompt

This section details on the original issue you should resolve

<issue_title>Broken Eq/Ord semantics for AssetCapacity</issue_title>
<issue_description>AssetCapacity derives PartialEq (float == semantics) but implements Ord using total_cmp, and also declares Eq. This violates the required consistency between Eq/Ord and equality (e.g., 0.0 == -0.0 but total_cmp orders them differently; NaN also breaks reflexivity). Consider implementing PartialEq/Eq manually to align with total_cmp (or drop Ord/Eq if total ordering isn’t required).

Originally posted by @copilot in #1158 (comment)
</issue_description>

Comments on the Issue (you are @copilot in this section)


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

…Eq via total_cmp

Co-authored-by: alexdewar <23149834+alexdewar@users.noreply.github.com>
Copilot AI changed the title [WIP] [MUSE2-1158] Fix broken Eq and Ord semantics for AssetCapacity Fix broken Eq/Ord consistency for AssetCapacity Mar 17, 2026
Copilot AI requested a review from alexdewar March 17, 2026 11:41
[#1021]: https://github.com/EnergySystemsModellingLab/MUSE2/pull/1021
[#1022]: https://github.com/EnergySystemsModellingLab/MUSE2/pull/1022
[#1030]: https://github.com/EnergySystemsModellingLab/MUSE2/pull/1030
[#1158]: https://github.com/EnergySystemsModellingLab/MUSE2/pull/1158
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This isn't the correct PR number. This PR is #1206. Fix the link and the text.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.03%. Comparing base (5389d44) to head (b442550).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1206   +/-   ##
=======================================
  Coverage   89.02%   89.03%           
=======================================
  Files          57       57           
  Lines        7838     7841    +3     
  Branches     7838     7841    +3     
=======================================
+ Hits         6978     6981    +3     
  Misses        564      564           
  Partials      296      296           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

alexdewar added a commit that referenced this pull request Mar 17, 2026
@alexdewar alexdewar mentioned this pull request Mar 17, 2026
11 tasks
@alexdewar alexdewar closed this Mar 17, 2026
alexdewar added a commit that referenced this pull request Mar 17, 2026
…pacity`

The implementations for these traits shouldn't panic and can cause UB if they do. The only thing we need them for is the `min()` method, but we can just implement this manually instead.

Fixes #1206.
alexdewar added a commit that referenced this pull request Mar 17, 2026
…pacity`

The implementations for these traits shouldn't panic and can cause UB if they do. The only thing we need them for is the `min()` method, but we can just implement this manually instead.

Fixes #1206.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Broken Eq/Ord semantics for AssetCapacity

2 participants