1 #![deny(clippy::useless_asref)]
2 #![allow(clippy::trivially_copy_pass_by_ref)]
7 #[allow(clippy::should_implement_trait)]
9 fn as_ref(&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) {
25 fn foo_rslice(x: &[i32]) {
28 fn foo_mrslice(x: &mut [i32]) {
31 fn foo_rrrrmr(_: &&&&MoreRef) {
32 println!("so many refs");
36 let rstr: &str = "hello";
37 let mut mrslice: &mut [i32] = &mut [1, 2, 3];
40 let rslice: &[i32] = &*mrslice;
41 foo_rstr(rstr.as_ref());
43 foo_rslice(rslice.as_ref());
47 foo_mrslice(mrslice.as_mut());
49 foo_rslice(mrslice.as_ref());
54 let rrrrrstr = &&&&rstr;
55 let rrrrrslice = &&&&&*mrslice;
56 foo_rslice(rrrrrslice.as_ref());
57 foo_rslice(rrrrrslice);
58 foo_rstr(rrrrrstr.as_ref());
62 let mrrrrrslice = &mut &mut &mut &mut mrslice;
63 foo_mrslice(mrrrrrslice.as_mut());
64 foo_mrslice(mrrrrrslice);
65 foo_rslice(mrrrrrslice.as_ref());
66 foo_rslice(mrrrrrslice);
68 foo_rrrrmr((&&&&MoreRef).as_ref());
70 generic_not_ok(mrslice);
75 let string = "hello".to_owned();
76 let mut arr = [1, 2, 3];
77 let mut vec = vec![1, 2, 3];
80 foo_rstr(string.as_ref());
81 foo_rslice(arr.as_ref());
82 foo_rslice(vec.as_ref());
85 foo_mrslice(arr.as_mut());
86 foo_mrslice(vec.as_mut());
90 let rrrrstring = &&&&string;
91 let rrrrarr = &&&&arr;
92 let rrrrvec = &&&&vec;
93 foo_rstr(rrrrstring.as_ref());
94 foo_rslice(rrrrarr.as_ref());
95 foo_rslice(rrrrvec.as_ref());
98 let mrrrrarr = &mut &mut &mut &mut arr;
99 let mrrrrvec = &mut &mut &mut &mut vec;
100 foo_mrslice(mrrrrarr.as_mut());
101 foo_mrslice(mrrrrvec.as_mut());
104 foo_rrrrmr(MoreRef.as_ref());
106 generic_not_ok(arr.as_mut());
107 generic_ok(&mut arr);
110 fn foo_mrt<T: Debug + ?Sized>(t: &mut T) {
113 fn foo_rt<T: Debug + ?Sized>(t: &T) {
117 fn generic_not_ok<T: AsMut<T> + AsRef<T> + Debug + ?Sized>(mrt: &mut T) {
118 foo_mrt(mrt.as_mut());
120 foo_rt(mrt.as_ref());
124 fn generic_ok<U: AsMut<T> + AsRef<T> + ?Sized, T: Debug + ?Sized>(mru: &mut U) {
125 foo_mrt(mru.as_mut());
126 foo_rt(mru.as_ref());