1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
10 #![deny(clippy::useless_asref)]
11 #![allow(clippy::trivially_copy_pass_by_ref)]
16 #[allow(clippy::should_implement_trait)]
18 fn as_ref(&self) -> &Self {
25 impl<'a, 'b, 'c> AsRef<&'a &'b &'c MoreRef> for MoreRef {
26 fn as_ref(&self) -> &&'a &'b &'c MoreRef {
31 fn foo_rstr(x: &str) {
34 fn foo_rslice(x: &[i32]) {
37 fn foo_mrslice(x: &mut [i32]) {
40 fn foo_rrrrmr(_: &&&&MoreRef) {
41 println!("so many refs");
45 let rstr: &str = "hello";
46 let mut mrslice: &mut [i32] = &mut [1, 2, 3];
49 let rslice: &[i32] = &*mrslice;
50 foo_rstr(rstr.as_ref());
52 foo_rslice(rslice.as_ref());
56 foo_mrslice(mrslice.as_mut());
58 foo_rslice(mrslice.as_ref());
63 let rrrrrstr = &&&&rstr;
64 let rrrrrslice = &&&&&*mrslice;
65 foo_rslice(rrrrrslice.as_ref());
66 foo_rslice(rrrrrslice);
67 foo_rstr(rrrrrstr.as_ref());
71 let mrrrrrslice = &mut &mut &mut &mut mrslice;
72 foo_mrslice(mrrrrrslice.as_mut());
73 foo_mrslice(mrrrrrslice);
74 foo_rslice(mrrrrrslice.as_ref());
75 foo_rslice(mrrrrrslice);
77 foo_rrrrmr((&&&&MoreRef).as_ref());
79 generic_not_ok(mrslice);
84 let string = "hello".to_owned();
85 let mut arr = [1, 2, 3];
86 let mut vec = vec![1, 2, 3];
89 foo_rstr(string.as_ref());
90 foo_rslice(arr.as_ref());
91 foo_rslice(vec.as_ref());
94 foo_mrslice(arr.as_mut());
95 foo_mrslice(vec.as_mut());
99 let rrrrstring = &&&&string;
100 let rrrrarr = &&&&arr;
101 let rrrrvec = &&&&vec;
102 foo_rstr(rrrrstring.as_ref());
103 foo_rslice(rrrrarr.as_ref());
104 foo_rslice(rrrrvec.as_ref());
107 let mrrrrarr = &mut &mut &mut &mut arr;
108 let mrrrrvec = &mut &mut &mut &mut vec;
109 foo_mrslice(mrrrrarr.as_mut());
110 foo_mrslice(mrrrrvec.as_mut());
113 foo_rrrrmr(MoreRef.as_ref());
115 generic_not_ok(arr.as_mut());
116 generic_ok(&mut arr);
119 fn foo_mrt<T: Debug + ?Sized>(t: &mut T) {
122 fn foo_rt<T: Debug + ?Sized>(t: &T) {
126 fn generic_not_ok<T: AsMut<T> + AsRef<T> + Debug + ?Sized>(mrt: &mut T) {
127 foo_mrt(mrt.as_mut());
129 foo_rt(mrt.as_ref());
133 fn generic_ok<U: AsMut<T> + AsRef<T> + ?Sized, T: Debug + ?Sized>(mru: &mut U) {
134 foo_mrt(mru.as_mut());
135 foo_rt(mru.as_ref());