Skip to content

Commit b67d9f8

Browse files
committed
Add closure test
1 parent fbc6050 commit b67d9f8

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

tests/ui/needless_borrow.fixed

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,16 @@ fn issue9383() {
329329
ManuallyDrop::drop(&mut ocean.coral);
330330
}
331331
}
332+
333+
#[allow(dead_code)]
334+
fn closure_test() {
335+
let env = "env".to_owned();
336+
let arg = "arg".to_owned();
337+
let f = |arg| {
338+
let loc = "loc".to_owned();
339+
let _ = std::fs::write("x", &env); // Don't lint. In environment
340+
let _ = std::fs::write("x", arg);
341+
let _ = std::fs::write("x", loc);
342+
};
343+
f(arg);
344+
}

tests/ui/needless_borrow.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,16 @@ fn issue9383() {
329329
ManuallyDrop::drop(&mut ocean.coral);
330330
}
331331
}
332+
333+
#[allow(dead_code)]
334+
fn closure_test() {
335+
let env = "env".to_owned();
336+
let arg = "arg".to_owned();
337+
let f = |arg| {
338+
let loc = "loc".to_owned();
339+
let _ = std::fs::write("x", &env); // Don't lint. In environment
340+
let _ = std::fs::write("x", &arg);
341+
let _ = std::fs::write("x", &loc);
342+
};
343+
f(arg);
344+
}

tests/ui/needless_borrow.stderr

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,5 +186,23 @@ error: the borrowed expression implements the required traits
186186
LL | let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap();
187187
| ^^^^^^^^^^^^^ help: change this to: `["-a", "-l"]`
188188

189-
error: aborting due to 31 previous errors
189+
error: the borrowed expression implements the required traits
190+
--> $DIR/needless_borrow.rs:340:37
191+
|
192+
LL | let _ = std::fs::write("x", &arg);
193+
| ^^^^ help: change this to: `arg`
194+
195+
error: the borrowed expression implements the required traits
196+
--> $DIR/needless_borrow.rs:341:37
197+
|
198+
LL | let _ = std::fs::write("x", &loc);
199+
| ^^^^ help: change this to: `loc`
200+
201+
error: the borrowed expression implements the required traits
202+
--> $DIR/needless_borrow.rs:360:15
203+
|
204+
LL | debug(&x);
205+
| ^^ help: change this to: `x`
206+
207+
error: aborting due to 34 previous errors
190208

0 commit comments

Comments
 (0)