From 6b4b77aa4408d6c297e8270e79c3ad36a07b0f1b Mon Sep 17 00:00:00 2001 From: dswij Date: Thu, 9 Sep 2021 23:33:28 +0800 Subject: [PATCH] Update test for needless-borrow FP for mutable ref --- tests/ui/needless_borrow.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/tests/ui/needless_borrow.rs b/tests/ui/needless_borrow.rs index 059dc8cea..31977416b 100644 --- a/tests/ui/needless_borrow.rs +++ b/tests/ui/needless_borrow.rs @@ -1,17 +1,16 @@ // run-rustfix -#![allow(clippy::needless_borrowed_reference)] - -fn x(y: &i32) -> i32 { - *y -} - #[warn(clippy::all, clippy::needless_borrow)] #[allow(unused_variables)] fn main() { let a = 5; - let b = x(&a); - let c = x(&&a); + let _ = x(&a); // no warning + let _ = x(&&a); // warn + + let mut b = 5; + mut_ref(&mut b); // no warning + mut_ref(&mut &mut b); // warn + let s = &String::from("hi"); let s_ident = f(&s); // should not error, because `&String` implements Copy, but `String` does not let g_val = g(&Vec::new()); // should not error, because `&Vec` derefs to `&[T]` @@ -29,6 +28,15 @@ fn main() { }; } +#[allow(clippy::needless_borrowed_reference)] +fn x(y: &i32) -> i32 { + *y +} + +fn mut_ref(y: &mut i32) { + *y = 5; +} + fn f(y: &T) -> T { *y }