diff options
| author | bors <bors@rust-lang.org> | 2023-09-20 07:48:54 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-09-20 07:48:54 +0000 |
| commit | ece3878c8cc74da936d067ee25a4ccc959ea55dd (patch) | |
| tree | d8c0c9978990f202ef290c6c4477c1505c7d6067 /tests | |
| parent | f464149b8f3e4d24139491a8f4049bc6eef0de38 (diff) | |
| parent | b8b420cc79dc18423a9bf59ee3397a398e9aac2a (diff) | |
Auto merge of #11492 - GuillaumeGomez:async-fn-returned-closure, r=Centri3
Fix mutaby used async function argument in closure for `needless_pass_by_ref_mut` Fixes https://github.com/rust-lang/rust-clippy/issues/11380. The problem was that it needed to go through closures as well in async functions to correctly find the mutable usage of async function arguments. changelog: Correctly handle mutable usage of async function arguments in closures. r? `@Centri3`
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/needless_pass_by_ref_mut.rs | 28 | ||||
| -rw-r--r-- | tests/ui/needless_pass_by_ref_mut.stderr | 26 |
2 files changed, 52 insertions, 2 deletions
diff --git a/tests/ui/needless_pass_by_ref_mut.rs b/tests/ui/needless_pass_by_ref_mut.rs index e1e5e8fd220..da2a72caacb 100644 --- a/tests/ui/needless_pass_by_ref_mut.rs +++ b/tests/ui/needless_pass_by_ref_mut.rs @@ -1,4 +1,4 @@ -#![allow(clippy::if_same_then_else, clippy::no_effect)] +#![allow(clippy::if_same_then_else, clippy::no_effect, clippy::redundant_closure_call)] #![feature(lint_reasons)] //@no-rustfix use std::ptr::NonNull; @@ -231,6 +231,32 @@ async fn async_vec2(b: &mut Vec<bool>) { b.push(true); } +// Should not warn. +pub async fn closure(n: &mut usize) -> impl '_ + FnMut() { + || { + *n += 1; + } +} + +// Should warn. +pub fn closure2(n: &mut usize) -> impl '_ + FnMut() -> usize { + //~^ ERROR: this argument is a mutable reference, but not used mutably + || *n + 1 +} + +// Should not warn. +pub async fn closure3(n: &mut usize) { + (|| *n += 1)(); +} + +// Should warn. +pub async fn closure4(n: &mut usize) { + //~^ ERROR: this argument is a mutable reference, but not used mutably + (|| { + let _x = *n + 1; + })(); +} + fn main() { let mut u = 0; let mut v = vec![0]; diff --git a/tests/ui/needless_pass_by_ref_mut.stderr b/tests/ui/needless_pass_by_ref_mut.stderr index df3df045776..0fb9458d794 100644 --- a/tests/ui/needless_pass_by_ref_mut.stderr +++ b/tests/ui/needless_pass_by_ref_mut.stderr @@ -107,5 +107,29 @@ error: this argument is a mutable reference, but not used mutably LL | async fn inner_async3(x: &mut i32, y: &mut u32) { | ^^^^^^^^ help: consider changing to: `&i32` -error: aborting due to 17 previous errors +error: this argument is a mutable reference, but not used mutably + --> $DIR/needless_pass_by_ref_mut.rs:235:25 + | +LL | pub async fn closure(n: &mut usize) -> impl '_ + FnMut() { + | ^^^^^^^^^^ help: consider changing to: `&usize` + | + = warning: changing this function will impact semver compatibility + +error: this argument is a mutable reference, but not used mutably + --> $DIR/needless_pass_by_ref_mut.rs:242:20 + | +LL | pub fn closure2(n: &mut usize) -> impl '_ + FnMut() -> usize { + | ^^^^^^^^^^ help: consider changing to: `&usize` + | + = warning: changing this function will impact semver compatibility + +error: this argument is a mutable reference, but not used mutably + --> $DIR/needless_pass_by_ref_mut.rs:253:26 + | +LL | pub async fn closure4(n: &mut usize) { + | ^^^^^^^^^^ help: consider changing to: `&usize` + | + = warning: changing this function will impact semver compatibility + +error: aborting due to 20 previous errors |
