Skip to content

Commit d3fef54

Browse files
committed
Revert "Fix comparison operation"
This reverts commit d85726c.
1 parent d85726c commit d3fef54

File tree

3 files changed

+37
-33
lines changed

3 files changed

+37
-33
lines changed

fixed-map-derive/src/unit_variants.rs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ pub(crate) fn implement(cx: &Ctxt<'_>, en: &DataEnum) -> Result<TokenStream, ()>
5959
let mut keys_iter_init = Vec::new();
6060
let mut iter_init = Vec::new();
6161
let mut entry = Vec::new();
62-
let mut cmp_init = Vec::new();
6362

6463
for (index, variant) in en.variants.iter().enumerate() {
6564
let var = &variant.ident;
@@ -86,7 +85,6 @@ pub(crate) fn implement(cx: &Ctxt<'_>, en: &DataEnum) -> Result<TokenStream, ()>
8685
iter_init.push(quote!((#ident::#var, #name)));
8786
names.push(name.clone());
8887
entry.push(quote!(option_to_entry(#name, key)));
89-
cmp_init.push(quote!((#index, #name)));
9088
}
9189

9290
let count = en.variants.len();
@@ -176,18 +174,6 @@ pub(crate) fn implement(cx: &Ctxt<'_>, en: &DataEnum) -> Result<TokenStream, ()>
176174
quote!()
177175
};
178176

179-
let self_cmp_iter_init = quote! {{
180-
let [#(#names),*] = &self.data;
181-
let init: [(usize, &Option<V>); #count] = [#(#cmp_init),*];
182-
#iterator::flat_map(#into_iter(init), |(k, v)| #option::Some((k, #option::as_ref(v)?)))
183-
}};
184-
185-
let other_cmp_iter_init = quote! {{
186-
let [#(#names),*] = &other.data;
187-
let init: [(usize, &Option<V>); #count] = [#(#cmp_init),*];
188-
#iterator::flat_map(#into_iter(init), |(k, v)| #option::Some((k, #option::as_ref(v)?)))
189-
}};
190-
191177
Ok(quote! {
192178
const #const_wrapper: () = {
193179
#[repr(transparent)]
@@ -240,35 +226,53 @@ pub(crate) fn implement(cx: &Ctxt<'_>, en: &DataEnum) -> Result<TokenStream, ()>
240226
impl<V> #partial_ord for Storage<V> where V: #partial_ord {
241227
#[inline]
242228
fn partial_cmp(&self, other: &Self) -> Option<#ordering> {
243-
#iterator::partial_cmp(#self_cmp_iter_init, #other_cmp_iter_init)
229+
#partial_ord::partial_cmp(&self.data, &other.data)
244230
}
245231

246232
#[inline]
247233
fn lt(&self, other: &Self) -> bool {
248-
#iterator::lt(#self_cmp_iter_init, #other_cmp_iter_init)
234+
#partial_ord::lt(&self.data, &other.data)
249235
}
250236

251237
#[inline]
252238
fn le(&self, other: &Self) -> bool {
253-
#iterator::le(#self_cmp_iter_init, #other_cmp_iter_init)
239+
#partial_ord::le(&self.data, &other.data)
254240
}
255241

256242
#[inline]
257243
fn gt(&self, other: &Self) -> bool {
258-
#iterator::gt(#self_cmp_iter_init, #other_cmp_iter_init)
244+
#partial_ord::gt(&self.data, &other.data)
259245
}
260246

261247
#[inline]
262248
fn ge(&self, other: &Self) -> bool {
263-
#iterator::ge(#self_cmp_iter_init, #other_cmp_iter_init)
249+
#partial_ord::ge(&self.data, &other.data)
264250
}
265251
}
266252

267253
#[automatically_derived]
268254
impl<V> #ord for Storage<V> where V: #ord {
269255
#[inline]
270256
fn cmp(&self, other: &Self) -> #ordering {
271-
#iterator::cmp(#self_cmp_iter_init, #other_cmp_iter_init)
257+
#ord::cmp(self, other)
258+
}
259+
260+
#[inline]
261+
fn max(self, other: Self) -> Self {
262+
Self { data: #ord::max(self.data, other.data) }
263+
}
264+
265+
#[inline]
266+
fn min(self, other: Self) -> Self {
267+
Self { data: #ord::min(self.data, other.data) }
268+
}
269+
270+
#[inline]
271+
fn clamp(self, min: Self, max: Self) -> Self
272+
where
273+
Self: #partial_ord<Self>
274+
{
275+
Self { data: #ord::clamp(self.data, min.data, max.data) }
272276
}
273277
}
274278

src/map.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,10 +1105,10 @@ where
11051105
/// let mut b = Map::new();
11061106
/// b.insert(Key::Second, 1);
11071107
///
1108-
/// assert!(a < b);
1109-
/// assert!(a <= b);
1110-
/// assert!(!(a > b));
1111-
/// assert!(!(a >= b));
1108+
/// assert!(a > b);
1109+
/// assert!(a >= b);
1110+
/// assert!(!(a < b));
1111+
/// assert!(!(a <= b));
11121112
/// ```
11131113
///
11141114
/// Using a composite key:
@@ -1129,7 +1129,7 @@ where
11291129
/// b.insert(Key::Second, 1);
11301130
///
11311131
/// // TODO: support this
1132-
/// // assert!(a < b);
1132+
/// // assert!(a > b);
11331133
/// ```
11341134
impl<K, V> PartialOrd for Map<K, V>
11351135
where
@@ -1181,10 +1181,10 @@ where
11811181
/// let mut b = Map::new();
11821182
/// b.insert(Key::Second, 1);
11831183
///
1184-
/// let mut list = vec![b, a];
1184+
/// let mut list = vec![a, b];
11851185
/// list.sort();
11861186
///
1187-
/// assert_eq!(list, [a, b]);
1187+
/// assert_eq!(list, [b, a]);
11881188
/// ```
11891189
///
11901190
/// Using a composite key:

src/set.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -662,10 +662,10 @@ where
662662
/// let mut b = Set::new();
663663
/// b.insert(Key::Second);
664664
///
665-
/// assert!(a < b);
666-
/// assert!(a <= b);
667-
/// assert!(!(a > b));
668-
/// assert!(!(a >= b));
665+
/// assert!(a > b);
666+
/// assert!(a >= b);
667+
/// assert!(!(a < b));
668+
/// assert!(!(a <= b));
669669
/// ```
670670
///
671671
/// Using a composite key:
@@ -738,10 +738,10 @@ where
738738
/// let mut b = Set::new();
739739
/// b.insert(Key::Second);
740740
///
741-
/// let mut list = vec![b, a];
741+
/// let mut list = vec![a, b];
742742
/// list.sort();
743743
///
744-
/// assert_eq!(list, [a, b]);
744+
/// assert_eq!(list, [b, a]);
745745
/// ```
746746
///
747747
/// Using a composite key:

0 commit comments

Comments
 (0)