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
318 B
Rust
Raw Normal View History

//@ run-pass
use std::ops::Deref;
struct DerefArray<'a, T:'a> {
inner: &'a [T]
}
2015-01-01 19:53:20 +00: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 21:05:03 +00:00
let a = &[1, 2, 3];
assert_eq!(DerefArray {inner: a}[1], 2);
}