-#![deny(useless_asref)]
+// run-rustfix
+
+#![deny(clippy::useless_asref)]
use std::fmt::Debug;
struct FakeAsRef;
-#[allow(should_implement_trait)]
+#[allow(clippy::should_implement_trait)]
impl FakeAsRef {
- fn as_ref(&self) -> &Self { self }
+ fn as_ref(&self) -> &Self {
+ self
+ }
}
struct MoreRef;
}
}
-fn foo_rstr(x: &str) { println!("{:?}", x); }
-fn foo_rslice(x: &[i32]) { println!("{:?}", x); }
-fn foo_mrslice(x: &mut [i32]) { println!("{:?}", x); }
-fn foo_rrrrmr(_: &&&&MoreRef) { println!("so many refs"); }
+fn foo_rstr(x: &str) {
+ println!("{:?}", x);
+}
+fn foo_rslice(x: &[i32]) {
+ println!("{:?}", x);
+}
+fn foo_mrslice(x: &mut [i32]) {
+ println!("{:?}", x);
+}
+fn foo_rrrrmr(_: &&&&MoreRef) {
+ println!("so many refs");
+}
fn not_ok() {
let rstr: &str = "hello";
- let mut mrslice: &mut [i32] = &mut [1,2,3];
+ let mut mrslice: &mut [i32] = &mut [1, 2, 3];
{
let rslice: &[i32] = &*mrslice;
foo_rslice(mrrrrrslice.as_ref());
foo_rslice(mrrrrrslice);
}
+ #[allow(unused_parens, clippy::double_parens)]
foo_rrrrmr((&&&&MoreRef).as_ref());
generic_not_ok(mrslice);
fn ok() {
let string = "hello".to_owned();
- let mut arr = [1,2,3];
- let mut vec = vec![1,2,3];
+ let mut arr = [1, 2, 3];
+ let mut vec = vec![1, 2, 3];
{
foo_rstr(string.as_ref());
generic_ok(&mut arr);
}
-fn foo_mrt<T: Debug + ?Sized>(t: &mut T) { println!("{:?}", t); }
-fn foo_rt<T: Debug + ?Sized>(t: &T) { println!("{:?}", t); }
+fn foo_mrt<T: Debug + ?Sized>(t: &mut T) {
+ println!("{:?}", t);
+}
+fn foo_rt<T: Debug + ?Sized>(t: &T) {
+ println!("{:?}", t);
+}
fn generic_not_ok<T: AsMut<T> + AsRef<T> + Debug + ?Sized>(mrt: &mut T) {
foo_mrt(mrt.as_mut());