Skip to content

Commit 73a68cd

Browse files
committed
auto merge of #14133 : db48x/rust/ord-for-mut-refs, r=alexcrichton
Also Show, which is useful in assertions. Fixes #14074
2 parents e10fd31 + 9eb723d commit 73a68cd

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/libcore/cmp.rs

+33-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -217,6 +217,29 @@ mod impls {
217217
}
218218
impl<'a, T: TotalEq> TotalEq for &'a T {}
219219

220+
// &mut pointers
221+
impl<'a, T: Eq> Eq for &'a mut T {
222+
#[inline]
223+
fn eq(&self, other: &&'a mut T) -> bool { **self == *(*other) }
224+
#[inline]
225+
fn ne(&self, other: &&'a mut T) -> bool { **self != *(*other) }
226+
}
227+
impl<'a, T: Ord> Ord for &'a mut T {
228+
#[inline]
229+
fn lt(&self, other: &&'a mut T) -> bool { **self < **other }
230+
#[inline]
231+
fn le(&self, other: &&'a mut T) -> bool { **self <= **other }
232+
#[inline]
233+
fn ge(&self, other: &&'a mut T) -> bool { **self >= **other }
234+
#[inline]
235+
fn gt(&self, other: &&'a mut T) -> bool { **self > **other }
236+
}
237+
impl<'a, T: TotalOrd> TotalOrd for &'a mut T {
238+
#[inline]
239+
fn cmp(&self, other: &&'a mut T) -> Ordering { (**self).cmp(*other) }
240+
}
241+
impl<'a, T: TotalEq> TotalEq for &'a mut T {}
242+
220243
// @ pointers
221244
impl<T:Eq> Eq for @T {
222245
#[inline]
@@ -254,6 +277,15 @@ mod test {
254277
assert_eq!(12u.cmp(-5), Greater);
255278
}
256279

280+
#[test]
281+
fn test_mut_int_totalord() {
282+
assert_eq!((&mut 5u).cmp(&10), Less);
283+
assert_eq!((&mut 10u).cmp(&5), Greater);
284+
assert_eq!((&mut 5u).cmp(&5), Equal);
285+
assert_eq!((&mut -5u).cmp(&12), Less);
286+
assert_eq!((&mut 12u).cmp(-5), Greater);
287+
}
288+
257289
#[test]
258290
fn test_ordering_order() {
259291
assert!(Less < Equal);

src/libstd/fmt/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,9 @@ impl<T: Show> Show for Box<T> {
11381138
impl<'a, T: Show> Show for &'a T {
11391139
fn fmt(&self, f: &mut Formatter) -> Result { secret_show(*self, f) }
11401140
}
1141+
impl<'a, T: Show> Show for &'a mut T {
1142+
fn fmt(&self, f: &mut Formatter) -> Result { secret_show(*self, f) }
1143+
}
11411144

11421145
impl Bool for bool {
11431146
fn fmt(&self, f: &mut Formatter) -> Result {

0 commit comments

Comments
 (0)