| 1 |
/* { dg-output "add_assign\r*\n3\r*\n" } */ |
| 2 |
extern "C" { |
| 3 |
fn printf(s: *const i8, ...); |
| 4 |
} |
| 5 |
|
| 6 |
#[lang = "sized"] |
| 7 |
pub trait Sized {} |
| 8 |
|
| 9 |
#[lang = "add_assign"] |
| 10 |
pub trait AddAssign<Rhs = Self> { |
| 11 |
fn add_assign(&mut self, rhs: Rhs); |
| 12 |
} |
| 13 |
|
| 14 |
impl AddAssign for i32 { |
| 15 |
fn add_assign(&mut self, other: i32) { |
| 16 |
unsafe { |
| 17 |
let a = "add_assign\n\0"; |
| 18 |
let b = a as *const str; |
| 19 |
let c = b as *const i8; |
| 20 |
|
| 21 |
printf(c); |
| 22 |
} |
| 23 |
*self += other |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
fn main() -> i32 { |
| 28 |
let mut res = 1; |
| 29 |
res += 2; |
| 30 |
|
| 31 |
unsafe { |
| 32 |
let a = "%i\n\0"; |
| 33 |
let b = a as *const str; |
| 34 |
let c = b as *const i8; |
| 35 |
|
| 36 |
printf(c, res); |
| 37 |
} |
| 38 |
|
| 39 |
0 |
| 40 |
} |