-// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-
-#![feature(tool_lints)]
+// run-rustfix
#![deny(clippy::useless_asref)]
-#![allow(clippy::trivially_copy_pass_by_ref)]
+
use std::fmt::Debug;
struct FakeAsRef;
#[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());