From 4e8199b572f2035b7749cba276ece3a26630d23e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:18:21 +0200 Subject: Adding upstream version 1.67.1+dfsg1. Signed-off-by: Daniel Baumann --- src/tools/clippy/tests/ui/needless_borrow.fixed | 144 ++++++++++++++++++++---- 1 file changed, 125 insertions(+), 19 deletions(-) (limited to 'src/tools/clippy/tests/ui/needless_borrow.fixed') 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, @@ -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) {} } -#[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) {} fn use_x_again(_: impl AsRef) {} } + +// https://github.com/rust-lang/rust-clippy/issues/9111#issuecomment-1277114280 +mod issue_9111 { + struct A; + + impl Extend for A { + fn extend>(&mut self, _: T) { + unimplemented!() + } + } + + impl<'a> Extend<&'a u8> for A { + fn extend>(&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) {} +} + +mod issue_9739 { + fn foo(_it: impl IntoIterator) {} + + 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(&self, _it: impl IntoIterator) {} + } + + fn main() { + S.foo(if std::env::var_os("HI").is_some() { + &[0] + } else { + &[] as &[u32] + }); + } +} + +mod issue_9782 { + fn foo>(t: T) { + println!("{}", std::mem::size_of::()); + 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: T) { + println!("{}", std::mem::size_of::()); + 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>(&self, t: T) { + println!("{}", std::mem::size_of::()); + let _t: &[u8] = t.as_ref(); + } + } + + fn main() { + let a: [u8; 100] = [0u8; 100]; + + S.foo::<&[u8; 100]>(&a); + } +} -- cgit v1.2.3