Skip to content

Span: the Eq/PartialEq trait implementation can lead to benign-looking code that is actually buggy. #32

@jhseu

Description

@jhseu

I'm doing a experimental migration of my project from chrono to jiff, and I've run into subtle errors involving Span comparisons. This usually involves subtracting two DateTimes and checking that its TimeDelta/Span is some value.

The documentation says:
A Span implements the PartialEq and Eq traits, but not the PartialOrd or Ord traits. In particular, its Eq trait implementation compares for field-wise equality only. This means two spans can represent identical durations while comparing inequal

Perhaps Span should not implement PartialEq and Eq at all. I would rather the compiler give an error if I'm doing the wrong thing rather than have a subtle bug go through. This behavior breaks the principle of least surprise. If a person unfamiliar with jiff sees &dt1 - &dt2 == some_span in code review, they probably would not think that it's a serious bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking changeIssues that require a breaking change for resolution.bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions