gcc/testsuite/rust/execute/torture/index1.rs
raw| 1 | // { dg-additional-options "-w" } |
| 2 | #[lang = "sized"] |
| 3 | pub trait Sized {} |
| 4 | |
| 5 | #[lang = "index"] |
| 6 | trait Index<Idx> { |
| 7 | type Output; |
| 8 | |
| 9 | fn index(&self, index: Idx) -> &Self::Output; |
| 10 | } |
| 11 | |
| 12 | struct Foo(i32, i32); |
| 13 | impl Index<isize> for Foo { |
| 14 | type Output = i32; |
| 15 | |
| 16 | fn index(&self, index: isize) -> &i32 { |
| 17 | if index == 0 { |
| 18 | &self.0 |
| 19 | } else { |
| 20 | &self.1 |
| 21 | } |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | fn main() -> i32 { |
| 26 | let a = Foo(1, 2); |
| 27 | let b = a[0]; |
| 28 | let c = a[1]; |
| 29 | |
| 30 | c - b - 1 |
| 31 | } |