1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // check raw fat pointer ops
15 fn assert_inorder
<T
: PartialEq
+ PartialOrd
>(a
: &[T
]) {
20 assert
!(a
[i
] <= a
[j
]);
21 assert
!(!(a
[i
] == a
[j
]));
22 assert
!(a
[i
] != a
[j
]);
23 assert
!(!(a
[i
] >= a
[j
]));
24 assert
!(!(a
[i
] > a
[j
]));
26 assert
!(!(a
[i
] < a
[j
]));
27 assert
!(a
[i
] <= a
[j
]);
28 assert
!(a
[i
] == a
[j
]);
29 assert
!(!(a
[i
] != a
[j
]));
30 assert
!(a
[i
] >= a
[j
]);
31 assert
!(!(a
[i
] > a
[j
]));
33 assert
!(!(a
[i
] < a
[j
]));
34 assert
!(!(a
[i
] <= a
[j
]));
35 assert
!(!(a
[i
] == a
[j
]));
36 assert
!(a
[i
] != a
[j
]);
37 assert
!(a
[i
] >= a
[j
]);
44 trait Foo { fn foo(&self) -> usize; }
46 fn foo(&self) -> usize {
51 struct S
<T
:?Sized
>(u32, T
);
54 let mut array
= [0,1,2,3,4];
55 let mut array2
= [5,6,7,8,9];
57 // fat ptr comparison: addr then extra
59 // check ordering for arrays
60 let mut ptrs
: Vec
<*const [u8]> = vec
![
61 &array
[0..0], &array
[0..1], &array
, &array
[1..]
64 let array_addr
= &array
as *const [u8] as *const u8 as usize;
65 let array2_addr
= &array2
as *const [u8] as *const u8 as usize;
66 if array2_addr
< array_addr
{
67 ptrs
.insert(0, &array2
);
71 assert_inorder(&ptrs
);
73 // check ordering for mut arrays
74 let mut ptrs
: Vec
<*mut [u8]> = vec
![
75 &mut array
[0..0], &mut array
[0..1], &mut array
, &mut array
[1..]
78 let array_addr
= &mut array
as *mut [u8] as *mut u8 as usize;
79 let array2_addr
= &mut array2
as *mut [u8] as *mut u8 as usize;
80 if array2_addr
< array_addr
{
81 ptrs
.insert(0, &mut array2
);
83 ptrs
.push(&mut array2
);
85 assert_inorder(&ptrs
);
87 let mut u8_
= (0u8, 1u8);
88 let mut u32_
= (4u32, 5u32);
90 // check ordering for ptrs
91 let buf
: &mut [*const Foo
] = &mut [
96 let u
: [*const (); 2] = unsafe { mem::transmute(*u) }
;
97 let v
: [*const (); 2] = unsafe { mem::transmute(*v) }
;
102 // check ordering for mut ptrs
103 let buf
: &mut [*mut Foo
] = &mut [
104 &mut u8_
, &mut u8_
.0,
105 &mut u32_
, &mut u32_
.0,
108 let u
: [*const (); 2] = unsafe { mem::transmute(*u) }
;
109 let v
: [*const (); 2] = unsafe { mem::transmute(*v) }
;
114 // check ordering for structs containing arrays
123 &ss
.0 as *const S
<[u8]>,
124 &ss
.1 as *const S
<[u8]>,
125 &ss
.2 as *const S
<[u8]>