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 in mir
12 // FIXME: please improve this when we get monomorphization support
16 #[derive(Debug, PartialEq, Eq)]
17 struct ComparisonResults
{
26 const LT
: ComparisonResults
= ComparisonResults
{
35 const EQ
: ComparisonResults
= ComparisonResults
{
44 const GT
: ComparisonResults
= ComparisonResults
{
53 fn compare_su8(a
: *const S
<[u8]>, b
: *const S
<[u8]>) -> ComparisonResults
{
64 fn compare_au8(a
: *const [u8], b
: *const [u8]) -> ComparisonResults
{
75 fn compare_foo
<'a
>(a
: *const (Foo
+'a
), b
: *const (Foo
+'a
)) -> ComparisonResults
{
86 fn simple_eq
<'a
>(a
: *const (Foo
+'a
), b
: *const (Foo
+'a
)) -> bool
{
91 fn assert_inorder
<T
: Copy
>(a
: &[T
],
92 compare
: fn(T
, T
) -> ComparisonResults
) {
95 let cres
= compare(a
[i
], a
[j
]);
101 assert_eq
!(cres
, GT
);
107 trait Foo { fn foo(&self) -> usize; }
109 fn foo(&self) -> usize {
114 struct S
<T
:?Sized
>(u32, T
);
117 let array
= [0,1,2,3,4];
118 let array2
= [5,6,7,8,9];
120 // fat ptr comparison: addr then extra
122 // check ordering for arrays
123 let mut ptrs
: Vec
<*const [u8]> = vec
![
124 &array
[0..0], &array
[0..1], &array
, &array
[1..]
127 let array_addr
= &array
as *const [u8] as *const u8 as usize;
128 let array2_addr
= &array2
as *const [u8] as *const u8 as usize;
129 if array2_addr
< array_addr
{
130 ptrs
.insert(0, &array2
);
134 assert_inorder(&ptrs
, compare_au8
);
136 let u8_
= (0u8, 1u8);
137 let u32_
= (4u32, 5u32);
139 // check ordering for ptrs
140 let buf
: &mut [*const Foo
] = &mut [
145 let u
: [*const (); 2] = unsafe { mem::transmute(*u) }
;
146 let v
: [*const (); 2] = unsafe { mem::transmute(*v) }
;
149 assert_inorder(buf
, compare_foo
);
151 // check ordering for structs containing arrays
160 &ss
.0 as *const S
<[u8]>,
161 &ss
.1 as *const S
<[u8]>,
162 &ss
.2 as *const S
<[u8]>
165 assert
!(simple_eq(&0u8 as *const _
, &0u8 as *const _
));
166 assert
!(!simple_eq(&0u8 as *const _
, &1u8 as *const _
));