Debian Codegraph @

gcc/testsuite/rust/compile/issue-1289.rs

raw
1 #![feature(intrinsics)]
2
3 #[lang = "sized"]
4 pub trait Sized {}
5
6 extern "C" {
7 fn printf(s: *const i8, ...);
8 }
9
10 mod intrinsics {
11 extern "rust-intrinsic" {
12 #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
13 pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
14 }
15 }
16
17 #[lang = "mut_ptr"]
18 impl<T> *mut T {
19 pub const unsafe fn offset(self, count: isize) -> *mut T {
20 unsafe { intrinsics::offset(self, count) as *mut T }
21 }
22
23 pub const unsafe fn add(self, count: usize) -> Self {
24 unsafe { self.offset(count as isize) }
25 }
26 }
27
28 #[lang = "const_ptr"]
29 impl<T> *const T {
30 pub const unsafe fn offset(self, count: isize) -> *mut T {
31 unsafe { intrinsics::offset(self, count) as *mut T }
32 }
33
34 pub const unsafe fn add(self, count: usize) -> Self {
35 unsafe { self.offset(count as isize) }
36 }
37 }
38
39 fn main() -> i32 {
40 let a: *mut _ = &mut 123;
41 unsafe {
42 let _b = a.add(123);
43 }
44
45 0
46 }