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 #![feature(rustc_attrs)]
13 // check raw fat pointer ops in mir
14 // FIXME: please improve this when we get monomorphization support
18 #[derive(Debug, PartialEq, Eq)]
19 struct ComparisonResults
{
28 const LT
: ComparisonResults
= ComparisonResults
{
37 const EQ
: ComparisonResults
= ComparisonResults
{
46 const GT
: ComparisonResults
= ComparisonResults
{
56 fn compare_su8(a
: *const S
<[u8]>, b
: *const S
<[u8]>) -> ComparisonResults
{
68 fn compare_au8(a
: *const [u8], b
: *const [u8]) -> ComparisonResults
{
80 fn compare_foo
<'a
>(a
: *const (Foo
+'a
), b
: *const (Foo
+'a
)) -> ComparisonResults
{
92 fn simple_eq
<'a
>(a
: *const (Foo
+'a
), b
: *const (Foo
+'a
)) -> bool
{
97 fn assert_inorder
<T
: Copy
>(a
: &[T
],
98 compare
: fn(T
, T
) -> ComparisonResults
) {
100 for j
in 0..a
.len() {
101 let cres
= compare(a
[i
], a
[j
]);
103 assert_eq
!(cres
, LT
);
105 assert_eq
!(cres
, EQ
);
107 assert_eq
!(cres
, GT
);
113 trait Foo { fn foo(&self) -> usize; }
115 fn foo(&self) -> usize {
120 struct S
<T
:?Sized
>(u32, T
);
123 let array
= [0,1,2,3,4];
124 let array2
= [5,6,7,8,9];
126 // fat ptr comparison: addr then extra
128 // check ordering for arrays
129 let mut ptrs
: Vec
<*const [u8]> = vec
![
130 &array
[0..0], &array
[0..1], &array
, &array
[1..]
133 let array_addr
= &array
as *const [u8] as *const u8 as usize;
134 let array2_addr
= &array2
as *const [u8] as *const u8 as usize;
135 if array2_addr
< array_addr
{
136 ptrs
.insert(0, &array2
);
140 assert_inorder(&ptrs
, compare_au8
);
142 let u8_
= (0u8, 1u8);
143 let u32_
= (4u32, 5u32);
145 // check ordering for ptrs
146 let buf
: &mut [*const Foo
] = &mut [
151 let u
: [*const (); 2] = unsafe { mem::transmute(*u) }
;
152 let v
: [*const (); 2] = unsafe { mem::transmute(*v) }
;
155 assert_inorder(buf
, compare_foo
);
157 // check ordering for structs containing arrays
166 &ss
.0 as *const S
<[u8]>,
167 &ss
.1 as *const S
<[u8]>,
168 &ss
.2 as *const S
<[u8]>
171 assert
!(simple_eq(&0u8 as *const _
, &0u8 as *const _
));
172 assert
!(!simple_eq(&0u8 as *const _
, &1u8 as *const _
));