aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/rust/compile/issue-1901.rs
blob: cfd8ef44fcc52bbcbdf74bd65c9bdd808a93c4cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#![feature(intrinsics)]

#[lang = "sized"]
pub trait Sized {}

mod intrinsics {
    extern "rust-intrinsic" {
        pub fn offset<T>(ptr: *const T, count: isize) -> *const T;
    }
}

mod ptr {
    #[lang = "const_ptr"]
    impl<T> *const T {
        pub unsafe fn offset(self, count: isize) -> *const T {
            intrinsics::offset(self, count)
        }
    }

    #[lang = "mut_ptr"]
    impl<T> *mut T {
        pub unsafe fn offset(self, count: isize) -> *mut T {
            intrinsics::offset(self, count) as *mut T
        }
    }
}

pub fn test_const(x: *const u8) {
    unsafe {
        x.offset(1);
    }
}

pub fn test_mut(x: *mut u8) {
    unsafe {
        x.offset(1);
    }
}