diff --git a/src/test/ui/mir/mir_raw_fat_ptr.rs b/src/test/ui/mir/mir_raw_fat_ptr.rs index 6583852aa9b..aa2b499b027 100644 --- a/src/test/ui/mir/mir_raw_fat_ptr.rs +++ b/src/test/ui/mir/mir_raw_fat_ptr.rs @@ -1,6 +1,7 @@ // run-pass // check raw fat pointer ops in mir // FIXME: please improve this when we get monomorphization support +#![feature(raw_ref_op)] use std::mem; @@ -104,7 +105,7 @@ impl Foo for T { struct S(u32, T); -fn main() { +fn main_ref() { let array = [0,1,2,3,4]; let array2 = [5,6,7,8,9]; @@ -156,3 +157,59 @@ fn main() { assert!(simple_eq(&0u8 as *const _, &0u8 as *const _)); assert!(!simple_eq(&0u8 as *const _, &1u8 as *const _)); } + +// similar to above, but using &raw +fn main_raw() { + let array = [0,1,2,3,4]; + let array2 = [5,6,7,8,9]; + + // fat ptr comparison: addr then extra + + // check ordering for arrays + let mut ptrs: Vec<*const [u8]> = vec![ + &raw const array[0..0], &raw const array[0..1], &raw const array, &raw const array[1..] + ]; + + let array_addr = &raw const array as *const u8 as usize; + let array2_addr = &raw const array2 as *const u8 as usize; + if array2_addr < array_addr { + ptrs.insert(0, &raw const array2); + } else { + ptrs.push(&raw const array2); + } + assert_inorder(&ptrs, compare_au8); + + let u8_ = (0u8, 1u8); + let u32_ = (4u32, 5u32); + + // check ordering for ptrs + let buf: &mut [*const dyn Foo] = &mut [ + &raw const u8_, &raw const u8_.0, + &raw const u32_, &raw const u32_.0, + ]; + buf.sort_by(|u,v| { + let u : [*const (); 2] = unsafe { mem::transmute(*u) }; + let v : [*const (); 2] = unsafe { mem::transmute(*v) }; + u.cmp(&v) + }); + assert_inorder(buf, compare_foo); + + // check ordering for structs containing arrays + let ss: (S<[u8; 2]>, + S<[u8; 3]>, + S<[u8; 2]>) = ( + S(7, [8, 9]), + S(10, [11, 12, 13]), + S(4, [5, 6]) + ); + assert_inorder(&[ + &raw const ss.0 as *const S<[u8]>, + &raw const ss.1 as *const S<[u8]>, + &raw const ss.2 as *const S<[u8]> + ], compare_su8); +} + +fn main() { + main_ref(); + main_raw(); +}