gcc/testsuite/rust/execute/torture/issue-1249.rs
raw| 1 | // { dg-options "-w" } |
| 2 | // { dg-output "1\r*\n2\r*\n" } |
| 3 | |
| 4 | #[lang = "sized"] |
| 5 | pub trait Sized {} |
| 6 | |
| 7 | extern "C" { |
| 8 | fn printf(s: *const i8, ...); |
| 9 | } |
| 10 | |
| 11 | trait T { |
| 12 | fn foo(&self); |
| 13 | } |
| 14 | |
| 15 | impl dyn T { |
| 16 | fn bar(&self) { |
| 17 | unsafe { |
| 18 | let a = "1\n\0"; |
| 19 | let b = a as *const str; |
| 20 | let c = b as *const i8; |
| 21 | printf(c); |
| 22 | } |
| 23 | self.foo() |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | struct S; |
| 28 | impl T for S { |
| 29 | fn foo(&self) { |
| 30 | unsafe { |
| 31 | let a = "2\n\0"; |
| 32 | let b = a as *const str; |
| 33 | let c = b as *const i8; |
| 34 | printf(c); |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | pub fn main() -> i32 { |
| 40 | <dyn T>::bar(&S); |
| 41 | 0 |
| 42 | } |