rust/tests/ui/overloaded/overloaded-autoderef-indexing.rs
2023-01-11 09:32:08 +00:00

21 lines
317 B
Rust

// run-pass
use std::ops::Deref;
struct DerefArray<'a, T:'a> {
inner: &'a [T]
}
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() {
let a = &[1, 2, 3];
assert_eq!(DerefArray {inner: a}[1], 2);
}