1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Test slicing sugar.
13 #![feature(slicing_syntax)]
14 #![feature(associated_types)]
17 use core::ops::{Index, IndexMut, Range, RangeTo, RangeFrom, FullRange};
19 static mut COUNT: uint = 0;
23 impl Index<Range<Foo>> for Foo {
25 fn index(&self, index: &Range<Foo>) -> &Foo {
26 unsafe { COUNT += 1; }
30 impl Index<RangeTo<Foo>> for Foo {
32 fn index(&self, index: &RangeTo<Foo>) -> &Foo {
33 unsafe { COUNT += 1; }
37 impl Index<RangeFrom<Foo>> for Foo {
39 fn index(&self, index: &RangeFrom<Foo>) -> &Foo {
40 unsafe { COUNT += 1; }
44 impl Index<FullRange> for Foo {
46 fn index(&self, _index: &FullRange) -> &Foo {
47 unsafe { COUNT += 1; }
52 impl IndexMut<Range<Foo>> for Foo {
54 fn index_mut(&mut self, index: &Range<Foo>) -> &mut Foo {
55 unsafe { COUNT += 1; }
59 impl IndexMut<RangeTo<Foo>> for Foo {
61 fn index_mut(&mut self, index: &RangeTo<Foo>) -> &mut Foo {
62 unsafe { COUNT += 1; }
66 impl IndexMut<RangeFrom<Foo>> for Foo {
68 fn index_mut(&mut self, index: &RangeFrom<Foo>) -> &mut Foo {
69 unsafe { COUNT += 1; }
73 impl IndexMut<FullRange> for Foo {
75 fn index_mut(&mut self, _index: &FullRange) -> &mut Foo {
76 unsafe { COUNT += 1; }