rust/tests/ui/overloaded/overloaded-autoderef-indexing.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

21 lines
317 B
Rust
Raw Normal View History

// run-pass
use std::ops::Deref;
struct DerefArray<'a, T:'a> {
inner: &'a [T]
}
2015-01-01 13:53:20 -06:00
impl<'a, T> Deref for DerefArray<'a, T> {
type Target = &'a [T];
fn deref<'b>(&'b self) -> &'b &'a [T] {
&self.inner
}
}
pub fn main() {
2015-01-25 15:05:03 -06:00
let a = &[1, 2, 3];
assert_eq!(DerefArray {inner: a}[1], 2);
}