]>
git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/useless_asref.rs
3 #![deny(clippy::useless_asref)]
4 #![allow(clippy::explicit_auto_deref)]
10 #[allow(clippy::should_implement_trait)]
12 fn as_ref(&self) -> &Self {
19 impl<'a
, 'b
, 'c
> AsRef
<&'a
&'b
&'c MoreRef
> for MoreRef
{
20 fn as_ref(&self) -> &&'a
&'b
&'c MoreRef
{
25 fn foo_rstr(x
: &str) {
28 fn foo_rslice(x
: &[i32]) {
31 fn foo_mrslice(x
: &mut [i32]) {
34 fn foo_rrrrmr(_
: &&&&MoreRef
) {
35 println
!("so many refs");
39 let rstr
: &str = "hello";
40 let mut mrslice
: &mut [i32] = &mut [1, 2, 3];
43 let rslice
: &[i32] = &*mrslice
;
44 foo_rstr(rstr
.as_ref());
46 foo_rslice(rslice
.as_ref());
50 foo_mrslice(mrslice
.as_mut());
52 foo_rslice(mrslice
.as_ref());
57 let rrrrrstr
= &&&&rstr
;
58 let rrrrrslice
= &&&&&*mrslice
;
59 foo_rslice(rrrrrslice
.as_ref());
60 foo_rslice(rrrrrslice
);
61 foo_rstr(rrrrrstr
.as_ref());
65 let mrrrrrslice
= &mut &mut &mut &mut mrslice
;
66 foo_mrslice(mrrrrrslice
.as_mut());
67 foo_mrslice(mrrrrrslice
);
68 foo_rslice(mrrrrrslice
.as_ref());
69 foo_rslice(mrrrrrslice
);
71 #[allow(unused_parens, clippy::double_parens, clippy::needless_borrow)]
72 foo_rrrrmr((&&&&MoreRef
).as_ref());
74 generic_not_ok(mrslice
);
79 let string
= "hello".to_owned();
80 let mut arr
= [1, 2, 3];
81 let mut vec
= vec
![1, 2, 3];
84 foo_rstr(string
.as_ref());
85 foo_rslice(arr
.as_ref());
86 foo_rslice(vec
.as_ref());
89 foo_mrslice(arr
.as_mut());
90 foo_mrslice(vec
.as_mut());
94 let rrrrstring
= &&&&string
;
95 let rrrrarr
= &&&&arr
;
96 let rrrrvec
= &&&&vec
;
97 foo_rstr(rrrrstring
.as_ref());
98 foo_rslice(rrrrarr
.as_ref());
99 foo_rslice(rrrrvec
.as_ref());
102 let mrrrrarr
= &mut &mut &mut &mut arr
;
103 let mrrrrvec
= &mut &mut &mut &mut vec
;
104 foo_mrslice(mrrrrarr
.as_mut());
105 foo_mrslice(mrrrrvec
.as_mut());
108 foo_rrrrmr(MoreRef
.as_ref());
110 generic_not_ok(arr
.as_mut());
111 generic_ok(&mut arr
);
114 fn foo_mrt
<T
: Debug
+ ?Sized
>(t
: &mut T
) {
117 fn foo_rt
<T
: Debug
+ ?Sized
>(t
: &T
) {
121 fn generic_not_ok
<T
: AsMut
<T
> + AsRef
<T
> + Debug
+ ?Sized
>(mrt
: &mut T
) {
122 foo_mrt(mrt
.as_mut());
124 foo_rt(mrt
.as_ref());
128 fn generic_ok
<U
: AsMut
<T
> + AsRef
<T
> + ?Sized
, T
: Debug
+ ?Sized
>(mru
: &mut U
) {
129 foo_mrt(mru
.as_mut());
130 foo_rt(mru
.as_ref());