3 #![warn(clippy::explicit_auto_deref)]
8 clippy::needless_borrow,
10 clippy::redundant_field_names,
11 clippy::too_many_arguments,
12 clippy::borrow_deref_ref
17 fn callable_str(&self) -> Self::T;
19 impl CallableStr for () {
21 fn callable_str(&self) -> Self::T {
26 impl CallableStr for i32 {
27 type T = <() as CallableStr>::T;
28 fn callable_str(&self) -> Self::T {
33 trait CallableT<U: ?Sized> {
35 fn callable_t(&self) -> Self::T;
37 impl<U: ?Sized> CallableT<U> for () {
39 fn callable_t(&self) -> Self::T {
40 fn f<U: ?Sized>(_: &U) {}
44 impl<U: ?Sized> CallableT<U> for i32 {
45 type T = <() as CallableT<U>>::T;
46 fn callable_t(&self) -> Self::T {
52 fn f_string(_: &String) {}
54 fn f_ref_t<T: ?Sized>(_: &T) {}
56 fn f_str_t<T>(_: &str, _: T) {}
58 fn f_box_t<T>(_: &Box<T>) {}
61 let s = String::new();
64 let _ = &*s; // Don't lint. Inferred type would change.
65 let _: &_ = &*s; // Don't lint. Inferred type would change.
68 f_t(&*s); // Don't lint. Inferred type would change.
69 f_ref_t(&*s); // Don't lint. Inferred type would change.
71 f_str_t(&*s, &*s); // Don't lint second param.
73 let b = Box::new(Box::new(Box::new(5)));
74 let _: &Box<i32> = &**b;
75 let _: &Box<_> = &**b; // Don't lint. Inferred type would change.
77 f_box_t(&**b); // Don't lint. Inferred type would change.
79 let c = |_x: &str| ();
83 c(&*s); // Don't lint. Inferred type would change.
85 fn _f(x: &String) -> &str {
89 fn _f1(x: &String) -> &str {
93 fn _f2(x: &String) -> &str {
97 fn _f3(x: &Box<Box<Box<i32>>>) -> &Box<i32> {
106 f4: impl CallableStr,
107 f5: <() as CallableStr>::T,
108 f6: <i32 as CallableStr>::T,
109 f7: &dyn CallableStr<T = fn(&str)>,
110 f8: impl CallableT<str>,
111 f9: <() as CallableT<str>>::T,
112 f10: <i32 as CallableT<str>>::T,
113 f11: &dyn CallableT<str, T = fn(&str)>,
118 f4.callable_str()(&*x);
121 f7.callable_str()(&*x);
122 f8.callable_t()(&*x);
125 f11.callable_t()(&*x);
128 struct S1<'a>(&'a str);
134 let _ = S2 { s: &*s };
136 struct S3<'a, T: ?Sized>(&'a T);
137 let _ = S3(&*s); // Don't lint. Inferred type would change.
139 struct S4<'a, T: ?Sized> {
142 let _ = S4 { s: &*s }; // Don't lint. Inferred type would change.
149 fn m1(s: &'a String) {
150 let _ = Self::S1(&**s);
151 let _ = Self::S2 { s: &**s };
155 let _ = E1::S2 { s: &*s };
157 enum E2<'a, T: ?Sized> {
161 let _ = E2::S1(&*s); // Don't lint. Inferred type would change.
162 let _ = E2::S2 { s: &*s }; // Don't lint. Inferred type would change.
165 let _: &String = &*ref_s; // Don't lint reborrow.
166 f_string(&*ref_s); // Don't lint reborrow.
171 let b = Box::new(Box::new(S5 { foo: 5 }));
179 impl core::ops::Deref for S6 {
181 fn deref(&self) -> &Self::Target {
185 let s6 = S6 { foo: S5 { foo: 5 } };
186 let _ = (*s6).foo; // Don't lint. `S6` also has a field named `foo`