1 #![feature(tool_lints)]
3 #![deny(clippy::useless_asref)]
4 #![allow(clippy::trivially_copy_pass_by_ref)]
9 #[allow(clippy::should_implement_trait)]
11 fn as_ref(&self) -> &Self { self }
16 impl<'a, 'b, 'c> AsRef<&'a &'b &'c MoreRef> for MoreRef {
17 fn as_ref(&self) -> &&'a &'b &'c MoreRef {
22 fn foo_rstr(x: &str) { println!("{:?}", x); }
23 fn foo_rslice(x: &[i32]) { println!("{:?}", x); }
24 fn foo_mrslice(x: &mut [i32]) { println!("{:?}", x); }
25 fn foo_rrrrmr(_: &&&&MoreRef) { println!("so many refs"); }
28 let rstr: &str = "hello";
29 let mut mrslice: &mut [i32] = &mut [1,2,3];
32 let rslice: &[i32] = &*mrslice;
33 foo_rstr(rstr.as_ref());
35 foo_rslice(rslice.as_ref());
39 foo_mrslice(mrslice.as_mut());
41 foo_rslice(mrslice.as_ref());
46 let rrrrrstr = &&&&rstr;
47 let rrrrrslice = &&&&&*mrslice;
48 foo_rslice(rrrrrslice.as_ref());
49 foo_rslice(rrrrrslice);
50 foo_rstr(rrrrrstr.as_ref());
54 let mrrrrrslice = &mut &mut &mut &mut mrslice;
55 foo_mrslice(mrrrrrslice.as_mut());
56 foo_mrslice(mrrrrrslice);
57 foo_rslice(mrrrrrslice.as_ref());
58 foo_rslice(mrrrrrslice);
60 foo_rrrrmr((&&&&MoreRef).as_ref());
62 generic_not_ok(mrslice);
67 let string = "hello".to_owned();
68 let mut arr = [1,2,3];
69 let mut vec = vec![1,2,3];
72 foo_rstr(string.as_ref());
73 foo_rslice(arr.as_ref());
74 foo_rslice(vec.as_ref());
77 foo_mrslice(arr.as_mut());
78 foo_mrslice(vec.as_mut());
82 let rrrrstring = &&&&string;
83 let rrrrarr = &&&&arr;
84 let rrrrvec = &&&&vec;
85 foo_rstr(rrrrstring.as_ref());
86 foo_rslice(rrrrarr.as_ref());
87 foo_rslice(rrrrvec.as_ref());
90 let mrrrrarr = &mut &mut &mut &mut arr;
91 let mrrrrvec = &mut &mut &mut &mut vec;
92 foo_mrslice(mrrrrarr.as_mut());
93 foo_mrslice(mrrrrvec.as_mut());
96 foo_rrrrmr(MoreRef.as_ref());
98 generic_not_ok(arr.as_mut());
102 fn foo_mrt<T: Debug + ?Sized>(t: &mut T) { println!("{:?}", t); }
103 fn foo_rt<T: Debug + ?Sized>(t: &T) { println!("{:?}", t); }
105 fn generic_not_ok<T: AsMut<T> + AsRef<T> + Debug + ?Sized>(mrt: &mut T) {
106 foo_mrt(mrt.as_mut());
108 foo_rt(mrt.as_ref());
112 fn generic_ok<U: AsMut<T> + AsRef<T> + ?Sized, T: Debug + ?Sized>(mru: &mut U) {
113 foo_mrt(mru.as_mut());
114 foo_rt(mru.as_ref());