From dbadf37336825faae9c14814eace50468da06b48 Mon Sep 17 00:00:00 2001 From: Evan Typanski Date: Fri, 30 Sep 2022 11:37:50 -0400 Subject: [PATCH] Add test case where `FnMut` used once needs `&mut` --- tests/ui/eta.fixed | 4 +++- tests/ui/eta.rs | 4 +++- tests/ui/eta.stderr | 8 +++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/ui/eta.fixed b/tests/ui/eta.fixed index 112bb4b4817a..e257b3b3afa6 100644 --- a/tests/ui/eta.fixed +++ b/tests/ui/eta.fixed @@ -305,7 +305,7 @@ fn not_general_enough() { } // https://github.com/rust-lang/rust-clippy/issues/9369 -pub fn mutable_impl_fn_mut(mut f: impl FnMut()) { +pub fn mutable_impl_fn_mut(mut f: impl FnMut(), mut f_used_once: impl FnMut()) -> impl FnMut() { fn takes_fn_mut(_: impl FnMut()) {} takes_fn_mut(&mut f); @@ -313,4 +313,6 @@ pub fn mutable_impl_fn_mut(mut f: impl FnMut()) { takes_fn_once(&mut f); f(); + + move || takes_fn_mut(&mut f_used_once) } diff --git a/tests/ui/eta.rs b/tests/ui/eta.rs index 970144e06ddf..486a251f30b0 100644 --- a/tests/ui/eta.rs +++ b/tests/ui/eta.rs @@ -305,7 +305,7 @@ fn not_general_enough() { } // https://github.com/rust-lang/rust-clippy/issues/9369 -pub fn mutable_impl_fn_mut(mut f: impl FnMut()) { +pub fn mutable_impl_fn_mut(mut f: impl FnMut(), mut f_used_once: impl FnMut()) -> impl FnMut() { fn takes_fn_mut(_: impl FnMut()) {} takes_fn_mut(|| f()); @@ -313,4 +313,6 @@ pub fn mutable_impl_fn_mut(mut f: impl FnMut()) { takes_fn_once(|| f()); f(); + + move || takes_fn_mut(|| f_used_once()) } diff --git a/tests/ui/eta.stderr b/tests/ui/eta.stderr index f7ead7257f6a..434706b7e258 100644 --- a/tests/ui/eta.stderr +++ b/tests/ui/eta.stderr @@ -128,5 +128,11 @@ error: redundant closure LL | takes_fn_once(|| f()); | ^^^^^^ help: replace the closure with the function itself: `&mut f` -error: aborting due to 21 previous errors +error: redundant closure + --> $DIR/eta.rs:317:26 + | +LL | move || takes_fn_mut(|| f_used_once()) + | ^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut f_used_once` + +error: aborting due to 22 previous errors