Skip to content

Commit ab51f66

Browse files
committed
added tests
1 parent 85801f5 commit ab51f66

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

tests/ui/needless_pass_by_ref_mut.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,18 @@ async fn async_vec(b: &mut Vec<bool>) {
230230
async fn async_vec2(b: &mut Vec<bool>) {
231231
b.push(true);
232232
}
233+
fn non_mut(n: &str) {}
234+
//Should warn
235+
pub async fn call_in_closure1(n: &mut str) {
236+
(|| non_mut(n))()
237+
}
238+
fn str_mut(str: &mut String) -> bool {
239+
str.pop().is_some()
240+
}
241+
//Should not warn
242+
pub async fn call_in_closure2(str: &mut String) {
243+
(|| str_mut(str))();
244+
}
233245

234246
// Should not warn.
235247
pub async fn closure(n: &mut usize) -> impl '_ + FnMut() {

tests/ui/needless_pass_by_ref_mut.stderr

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,28 +108,36 @@ LL | async fn inner_async3(x: &mut i32, y: &mut u32) {
108108
| ^^^^^^^^ help: consider changing to: `&i32`
109109

110110
error: this argument is a mutable reference, but not used mutably
111-
--> $DIR/needless_pass_by_ref_mut.rs:235:25
111+
--> $DIR/needless_pass_by_ref_mut.rs:235:34
112+
|
113+
LL | pub async fn call_in_closure1(n: &mut str) {
114+
| ^^^^^^^^ help: consider changing to: `&str`
115+
|
116+
= warning: changing this function will impact semver compatibility
117+
118+
error: this argument is a mutable reference, but not used mutably
119+
--> $DIR/needless_pass_by_ref_mut.rs:247:25
112120
|
113121
LL | pub async fn closure(n: &mut usize) -> impl '_ + FnMut() {
114122
| ^^^^^^^^^^ help: consider changing to: `&usize`
115123
|
116124
= warning: changing this function will impact semver compatibility
117125

118126
error: this argument is a mutable reference, but not used mutably
119-
--> $DIR/needless_pass_by_ref_mut.rs:242:20
127+
--> $DIR/needless_pass_by_ref_mut.rs:254:20
120128
|
121129
LL | pub fn closure2(n: &mut usize) -> impl '_ + FnMut() -> usize {
122130
| ^^^^^^^^^^ help: consider changing to: `&usize`
123131
|
124132
= warning: changing this function will impact semver compatibility
125133

126134
error: this argument is a mutable reference, but not used mutably
127-
--> $DIR/needless_pass_by_ref_mut.rs:253:26
135+
--> $DIR/needless_pass_by_ref_mut.rs:265:26
128136
|
129137
LL | pub async fn closure4(n: &mut usize) {
130138
| ^^^^^^^^^^ help: consider changing to: `&usize`
131139
|
132140
= warning: changing this function will impact semver compatibility
133141

134-
error: aborting due to 20 previous errors
142+
error: aborting due to 21 previous errors
135143

0 commit comments

Comments
 (0)