// run-pass #![allow(unused_variables)] // Test slicing sugar. extern crate core; use core::ops::{Index, IndexMut, Range, RangeTo, RangeFrom, RangeFull}; static mut COUNT: usize = 0; struct Foo; impl Index> for Foo { type Output = Foo; fn index(&self, index: Range) -> &Foo { unsafe { COUNT += 1; } self } } impl Index> for Foo { type Output = Foo; fn index(&self, index: RangeTo) -> &Foo { unsafe { COUNT += 1; } self } } impl Index> for Foo { type Output = Foo; fn index(&self, index: RangeFrom) -> &Foo { unsafe { COUNT += 1; } self } } impl Index for Foo { type Output = Foo; fn index(&self, _index: RangeFull) -> &Foo { unsafe { COUNT += 1; } self } } impl IndexMut> for Foo { fn index_mut(&mut self, index: Range) -> &mut Foo { unsafe { COUNT += 1; } self } } impl IndexMut> for Foo { fn index_mut(&mut self, index: RangeTo) -> &mut Foo { unsafe { COUNT += 1; } self } } impl IndexMut> for Foo { fn index_mut(&mut self, index: RangeFrom) -> &mut Foo { unsafe { COUNT += 1; } self } } impl IndexMut for Foo { fn index_mut(&mut self, _index: RangeFull) -> &mut Foo { unsafe { COUNT += 1; } self } } fn main() { let mut x = Foo; let _ = &x[..]; let _ = &x[Foo..]; let _ = &x[..Foo]; let _ = &x[Foo..Foo]; let _ = &mut x[..]; let _ = &mut x[Foo..]; let _ = &mut x[..Foo]; let _ = &mut x[Foo..Foo]; unsafe { assert_eq!(COUNT, 8); } }