2019-07-26 16:54:25 -05:00
|
|
|
// run-pass
|
2014-11-06 16:34:33 -06:00
|
|
|
// Test that `&T` and `&mut T` implement `Deref<T>`
|
|
|
|
|
2015-03-22 15:13:15 -05:00
|
|
|
|
2014-12-22 11:04:23 -06:00
|
|
|
use std::ops::Deref;
|
|
|
|
|
2015-01-01 13:53:20 -06:00
|
|
|
fn deref<U:Copy,T:Deref<Target=U>>(t: T) -> U {
|
2014-11-06 16:34:33 -06:00
|
|
|
*t
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2015-03-25 19:06:52 -05:00
|
|
|
let x: isize = 3;
|
2014-11-06 16:34:33 -06:00
|
|
|
let y = deref(&x);
|
|
|
|
assert_eq!(y, 3);
|
|
|
|
|
2015-03-25 19:06:52 -05:00
|
|
|
let mut x: isize = 4;
|
2014-11-06 16:34:33 -06:00
|
|
|
let y = deref(&mut x);
|
|
|
|
assert_eq!(y, 4);
|
|
|
|
}
|