Skip to content

Commit dbadf37

Browse files
author
Evan Typanski
committed
Add test case where FnMut used once needs &mut
1 parent 85b8ff7 commit dbadf37

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

tests/ui/eta.fixed

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,14 @@ fn not_general_enough() {
305305
}
306306

307307
// https://github.com/rust-lang/rust-clippy/issues/9369
308-
pub fn mutable_impl_fn_mut(mut f: impl FnMut()) {
308+
pub fn mutable_impl_fn_mut(mut f: impl FnMut(), mut f_used_once: impl FnMut()) -> impl FnMut() {
309309
fn takes_fn_mut(_: impl FnMut()) {}
310310
takes_fn_mut(&mut f);
311311

312312
fn takes_fn_once(_: impl FnOnce()) {}
313313
takes_fn_once(&mut f);
314314

315315
f();
316+
317+
move || takes_fn_mut(&mut f_used_once)
316318
}

tests/ui/eta.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,14 @@ fn not_general_enough() {
305305
}
306306

307307
// https://github.com/rust-lang/rust-clippy/issues/9369
308-
pub fn mutable_impl_fn_mut(mut f: impl FnMut()) {
308+
pub fn mutable_impl_fn_mut(mut f: impl FnMut(), mut f_used_once: impl FnMut()) -> impl FnMut() {
309309
fn takes_fn_mut(_: impl FnMut()) {}
310310
takes_fn_mut(|| f());
311311

312312
fn takes_fn_once(_: impl FnOnce()) {}
313313
takes_fn_once(|| f());
314314

315315
f();
316+
317+
move || takes_fn_mut(|| f_used_once())
316318
}

tests/ui/eta.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,11 @@ error: redundant closure
128128
LL | takes_fn_once(|| f());
129129
| ^^^^^^ help: replace the closure with the function itself: `&mut f`
130130

131-
error: aborting due to 21 previous errors
131+
error: redundant closure
132+
--> $DIR/eta.rs:317:26
133+
|
134+
LL | move || takes_fn_mut(|| f_used_once())
135+
| ^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut f_used_once`
136+
137+
error: aborting due to 22 previous errors
132138

0 commit comments

Comments
 (0)