2020-01-23 16:28:01 +01:00
|
|
|
#![allow(unused_variables, clippy::many_single_char_names, clippy::clone_double_ref)]
|
|
|
|
#![warn(clippy::explicit_deref_method)]
|
2018-10-03 18:53:39 +02:00
|
|
|
|
|
|
|
use std::ops::{Deref, DerefMut};
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let a: &mut String = &mut String::from("foo");
|
|
|
|
|
|
|
|
// these should require linting
|
2020-01-23 16:28:01 +01:00
|
|
|
let b: &str = a.deref();
|
2018-10-03 18:53:39 +02:00
|
|
|
|
2020-01-23 16:28:01 +01:00
|
|
|
let b: &mut str = a.deref_mut();
|
2018-10-03 18:53:39 +02:00
|
|
|
|
2020-01-23 16:28:01 +01:00
|
|
|
let b: String = a.deref().clone();
|
2018-10-03 18:53:39 +02:00
|
|
|
|
2020-01-23 16:28:01 +01:00
|
|
|
let b: usize = a.deref_mut().len();
|
2018-10-03 18:53:39 +02:00
|
|
|
|
2020-01-23 16:28:01 +01:00
|
|
|
let b: &usize = &a.deref().len();
|
|
|
|
|
|
|
|
// only first deref should get linted here
|
|
|
|
let b: &str = a.deref().deref();
|
|
|
|
|
|
|
|
// both derefs should get linted here
|
|
|
|
let b: String = format!("{}, {}", a.deref(), a.deref());
|
2018-10-03 18:53:39 +02:00
|
|
|
|
|
|
|
// these should not require linting
|
|
|
|
|
2020-01-23 16:28:01 +01:00
|
|
|
let b: &str = &*a;
|
|
|
|
|
|
|
|
let b: &mut str = &mut *a;
|
2018-10-03 18:53:39 +02:00
|
|
|
|
2020-01-23 16:28:01 +01:00
|
|
|
macro_rules! expr_deref {
|
|
|
|
($body:expr) => {
|
|
|
|
$body.deref()
|
|
|
|
};
|
2018-10-03 18:53:39 +02:00
|
|
|
}
|
2020-01-23 16:28:01 +01:00
|
|
|
let b: &str = expr_deref!(a);
|
2018-10-03 18:53:39 +02:00
|
|
|
}
|