]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/overloaded/overloaded-index-autoderef.rs
2 #![allow(stable_features)]
4 // Test overloaded indexing combined with autoderef.
6 use std
::ops
::{Index, IndexMut}
;
13 impl Index
<isize> for Foo
{
16 fn index(&self, z
: isize) -> &isize {
25 impl IndexMut
<isize> for Foo
{
26 fn index_mut(&mut self, z
: isize) -> &mut isize {
36 fn get(self) -> isize;
37 fn get_from_ref(&self) -> isize;
42 fn get(self) -> isize { self }
43 fn get_from_ref(&self) -> isize { *self }
44 fn inc(&mut self) { *self += 1; }
48 let mut f
: Box
<_
> = Box
::new(Foo
{
59 // Test explicit IndexMut where `f` must be autoderef:
65 // Test explicit Index where `f` must be autoderef:
71 // Test calling methods with `&mut self`, `self, and `&self` receivers:
73 assert_eq
!(f
[1].get(), 5);
74 assert_eq
!(f
[1].get_from_ref(), 5);