Fix mutaby used async function argument in closure for needless_pass_by_ref_mut
This commit is contained in:
parent
b788addfcc
commit
e3267b1fe7
3 changed files with 118 additions and 21 deletions
|
|
@ -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];
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue