1 #![allow(unused_variables, clippy::many_single_char_names, clippy::clone_double_ref)]
2 #![warn(clippy::explicit_deref_method)]
4 use std::ops::{Deref, DerefMut};
6 fn concat(deref_str: &str) -> String {
7 format!("{}bar", deref_str)
10 fn just_return(deref_str: &str) -> &str {
15 let a: &mut String = &mut String::from("foo");
17 // these should require linting
19 let b: &str = a.deref();
21 let b: &mut str = a.deref_mut();
23 // both derefs should get linted here
24 let b: String = format!("{}, {}", a.deref(), a.deref());
26 println!("{}", a.deref());
28 #[allow(clippy::match_single_binding)]
33 let b: String = concat(a.deref());
35 // following should not require linting
37 let b = just_return(a).deref();
39 let b: String = concat(just_return(a).deref());
41 let b: String = a.deref().clone();
43 let b: usize = a.deref_mut().len();
45 let b: &usize = &a.deref().len();
47 let b: &str = a.deref().deref();
51 let b: &mut str = &mut *a;
53 macro_rules! expr_deref {
58 let b: &str = expr_deref!(a);
61 let b = opt_a.unwrap().deref();