1 #![deny(useless_asref)]
7 #[allow(should_implement_trait)]
9 fn as_ref(&self) -> &Self { self }
14 impl<'a, 'b, 'c> AsRef<&'a &'b &'c MoreRef> for MoreRef {
15 fn as_ref(&self) -> &&'a &'b &'c MoreRef {
20 fn foo_rstr(x: &str) { println!("{:?}", x); }
21 fn foo_rslice(x: &[i32]) { println!("{:?}", x); }
22 fn foo_mrslice(x: &mut [i32]) { println!("{:?}", x); }
23 fn foo_rrrrmr(_: &&&&MoreRef) { println!("so many refs"); }
26 let rstr: &str = "hello";
27 let mut mrslice: &mut [i32] = &mut [1,2,3];
30 let rslice: &[i32] = &*mrslice;
31 foo_rstr(rstr.as_ref());
33 foo_rslice(rslice.as_ref());
37 foo_mrslice(mrslice.as_mut());
39 foo_rslice(mrslice.as_ref());
44 let rrrrrstr = &&&&rstr;
45 let rrrrrslice = &&&&&*mrslice;
46 foo_rslice(rrrrrslice.as_ref());
47 foo_rslice(rrrrrslice);
48 foo_rstr(rrrrrstr.as_ref());
52 let mrrrrrslice = &mut &mut &mut &mut mrslice;
53 foo_mrslice(mrrrrrslice.as_mut());
54 foo_mrslice(mrrrrrslice);
55 foo_rslice(mrrrrrslice.as_ref());
56 foo_rslice(mrrrrrslice);
58 foo_rrrrmr((&&&&MoreRef).as_ref());
60 generic_not_ok(mrslice);
65 let string = "hello".to_owned();
66 let mut arr = [1,2,3];
67 let mut vec = vec![1,2,3];
70 foo_rstr(string.as_ref());
71 foo_rslice(arr.as_ref());
72 foo_rslice(vec.as_ref());
75 foo_mrslice(arr.as_mut());
76 foo_mrslice(vec.as_mut());
80 let rrrrstring = &&&&string;
81 let rrrrarr = &&&&arr;
82 let rrrrvec = &&&&vec;
83 foo_rstr(rrrrstring.as_ref());
84 foo_rslice(rrrrarr.as_ref());
85 foo_rslice(rrrrvec.as_ref());
88 let mrrrrarr = &mut &mut &mut &mut arr;
89 let mrrrrvec = &mut &mut &mut &mut vec;
90 foo_mrslice(mrrrrarr.as_mut());
91 foo_mrslice(mrrrrvec.as_mut());
94 foo_rrrrmr(MoreRef.as_ref());
96 generic_not_ok(arr.as_mut());
100 fn foo_mrt<T: Debug + ?Sized>(t: &mut T) { println!("{:?}", t); }
101 fn foo_rt<T: Debug + ?Sized>(t: &T) { println!("{:?}", t); }
103 fn generic_not_ok<T: AsMut<T> + AsRef<T> + Debug + ?Sized>(mrt: &mut T) {
104 foo_mrt(mrt.as_mut());
106 foo_rt(mrt.as_ref());
110 fn generic_ok<U: AsMut<T> + AsRef<T> + ?Sized, T: Debug + ?Sized>(mru: &mut U) {
111 foo_mrt(mru.as_mut());
112 foo_rt(mru.as_ref());