summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/needless_borrow.fixed
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/clippy/tests/ui/needless_borrow.fixed')
-rw-r--r--src/tools/clippy/tests/ui/needless_borrow.fixed144
1 files changed, 125 insertions, 19 deletions
diff --git a/src/tools/clippy/tests/ui/needless_borrow.fixed b/src/tools/clippy/tests/ui/needless_borrow.fixed
index 340e89d2d..4cb7f6b68 100644
--- a/src/tools/clippy/tests/ui/needless_borrow.fixed
+++ b/src/tools/clippy/tests/ui/needless_borrow.fixed
@@ -1,13 +1,13 @@
// run-rustfix
-#![feature(custom_inner_attributes, lint_reasons)]
-
-#[warn(clippy::all, clippy::needless_borrow)]
-#[allow(unused_variables)]
-#[allow(
+#![feature(lint_reasons)]
+#![allow(
+ unused,
clippy::uninlined_format_args,
clippy::unnecessary_mut_passed,
clippy::unnecessary_to_owned
)]
+#![warn(clippy::needless_borrow)]
+
fn main() {
let a = 5;
let ref_a = &a;
@@ -171,14 +171,12 @@ impl<'a> Trait for &'a str {}
fn h(_: &dyn Trait) {}
-#[allow(dead_code)]
fn check_expect_suppression() {
let a = 5;
#[expect(clippy::needless_borrow)]
let _ = x(&&a);
}
-#[allow(dead_code)]
mod issue9160 {
pub struct S<F> {
f: F,
@@ -267,7 +265,6 @@ where
}
// https://github.com/rust-lang/rust-clippy/pull/9136#pullrequestreview-1037379321
-#[allow(dead_code)]
mod copyable_iterator {
#[derive(Clone, Copy)]
struct Iter;
@@ -287,25 +284,20 @@ mod copyable_iterator {
}
}
+#[clippy::msrv = "1.52.0"]
mod under_msrv {
- #![allow(dead_code)]
- #![clippy::msrv = "1.52.0"]
-
fn foo() {
let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap();
}
}
+#[clippy::msrv = "1.53.0"]
mod meets_msrv {
- #![allow(dead_code)]
- #![clippy::msrv = "1.53.0"]
-
fn foo() {
let _ = std::process::Command::new("ls").args(["-a", "-l"]).status().unwrap();
}
}
-#[allow(unused)]
fn issue9383() {
// Should not lint because unions need explicit deref when accessing field
use std::mem::ManuallyDrop;
@@ -334,7 +326,6 @@ fn issue9383() {
}
}
-#[allow(dead_code)]
fn closure_test() {
let env = "env".to_owned();
let arg = "arg".to_owned();
@@ -348,7 +339,6 @@ fn closure_test() {
f(arg);
}
-#[allow(dead_code)]
mod significant_drop {
#[derive(Debug)]
struct X;
@@ -368,7 +358,6 @@ mod significant_drop {
fn debug(_: impl std::fmt::Debug) {}
}
-#[allow(dead_code)]
mod used_exactly_once {
fn foo(x: String) {
use_x(x);
@@ -376,7 +365,6 @@ mod used_exactly_once {
fn use_x(_: impl AsRef<str>) {}
}
-#[allow(dead_code)]
mod used_more_than_once {
fn foo(x: String) {
use_x(&x);
@@ -385,3 +373,121 @@ mod used_more_than_once {
fn use_x(_: impl AsRef<str>) {}
fn use_x_again(_: impl AsRef<str>) {}
}
+
+// https://github.com/rust-lang/rust-clippy/issues/9111#issuecomment-1277114280
+mod issue_9111 {
+ struct A;
+
+ impl Extend<u8> for A {
+ fn extend<T: IntoIterator<Item = u8>>(&mut self, _: T) {
+ unimplemented!()
+ }
+ }
+
+ impl<'a> Extend<&'a u8> for A {
+ fn extend<T: IntoIterator<Item = &'a u8>>(&mut self, _: T) {
+ unimplemented!()
+ }
+ }
+
+ fn main() {
+ let mut a = A;
+ a.extend(&[]); // vs a.extend([]);
+ }
+}
+
+mod issue_9710 {
+ fn main() {
+ let string = String::new();
+ for _i in 0..10 {
+ f(&string);
+ }
+ }
+
+ fn f<T: AsRef<str>>(_: T) {}
+}
+
+mod issue_9739 {
+ fn foo<D: std::fmt::Display>(_it: impl IntoIterator<Item = D>) {}
+
+ fn main() {
+ foo(if std::env::var_os("HI").is_some() {
+ &[0]
+ } else {
+ &[] as &[u32]
+ });
+ }
+}
+
+mod issue_9739_method_variant {
+ struct S;
+
+ impl S {
+ fn foo<D: std::fmt::Display>(&self, _it: impl IntoIterator<Item = D>) {}
+ }
+
+ fn main() {
+ S.foo(if std::env::var_os("HI").is_some() {
+ &[0]
+ } else {
+ &[] as &[u32]
+ });
+ }
+}
+
+mod issue_9782 {
+ fn foo<T: AsRef<[u8]>>(t: T) {
+ println!("{}", std::mem::size_of::<T>());
+ let _t: &[u8] = t.as_ref();
+ }
+
+ fn main() {
+ let a: [u8; 100] = [0u8; 100];
+
+ // 100
+ foo::<[u8; 100]>(a);
+ foo(a);
+
+ // 16
+ foo::<&[u8]>(&a);
+ foo(a.as_slice());
+
+ // 8
+ foo::<&[u8; 100]>(&a);
+ foo(a);
+ }
+}
+
+mod issue_9782_type_relative_variant {
+ struct S;
+
+ impl S {
+ fn foo<T: AsRef<[u8]>>(t: T) {
+ println!("{}", std::mem::size_of::<T>());
+ let _t: &[u8] = t.as_ref();
+ }
+ }
+
+ fn main() {
+ let a: [u8; 100] = [0u8; 100];
+
+ S::foo::<&[u8; 100]>(&a);
+ }
+}
+
+mod issue_9782_method_variant {
+ struct S;
+
+ impl S {
+ fn foo<T: AsRef<[u8]>>(&self, t: T) {
+ println!("{}", std::mem::size_of::<T>());
+ let _t: &[u8] = t.as_ref();
+ }
+ }
+
+ fn main() {
+ let a: [u8; 100] = [0u8; 100];
+
+ S.foo::<&[u8; 100]>(&a);
+ }
+}