rust/src/test/ui/deref-on-ref.rs
2019-07-27 18:56:16 +03:00

20 lines
303 B
Rust

// run-pass
// Test that `&T` and `&mut T` implement `Deref<T>`
use std::ops::Deref;
fn deref<U:Copy,T:Deref<Target=U>>(t: T) -> U {
*t
}
fn main() {
let x: isize = 3;
let y = deref(&x);
assert_eq!(y, 3);
let mut x: isize = 4;
let y = deref(&mut x);
assert_eq!(y, 4);
}