You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
PartialOrd is implemented manually for prometheus::proto::LabelPair and it only compares the name. However, PartialEq is derived, so it checks all fields. This violates PartialOrd requirements (a == b if and only if partial_cmp(a, b) == Some(Equal)) and may cause issues if LabelPair is used in standard containers.
To Reproduce
letmut a = LabelPair::new();
a.set_name("name".to_owned());
a.set_value("a".to_owned());letmut b = LabelPair::new();
b.set_name("name".to_owned());
b.set_value("b".to_owned());assert!(a.cmp(&b) == Ordering::Equal);assert_eq!(a, b)// fails
Expected behavior
Either PartialEq should be implemented manually to only compare the name field for consistency with PartialOrd, or PartialOrd should compare all fields. It's also worth mentioning in the docs if only name constitutes the equality, as it can be quite surprising.
Additional context
I had a bug because tried to put LabelPair into a BTreeSet.
The text was updated successfully, but these errors were encountered:
Describe the bug
PartialOrd is implemented manually for
prometheus::proto::LabelPair
and it only compares thename
. However,PartialEq
is derived, so it checks all fields. This violatesPartialOrd
requirements (a == b
if and only ifpartial_cmp(a, b) == Some(Equal)
) and may cause issues if LabelPair is used in standard containers.To Reproduce
Expected behavior
Either PartialEq should be implemented manually to only compare the
name
field for consistency with PartialOrd, or PartialOrd should compare all fields. It's also worth mentioning in the docs if onlyname
constitutes the equality, as it can be quite surprising.Additional context
I had a bug because tried to put
LabelPair
into aBTreeSet
.The text was updated successfully, but these errors were encountered: