Skip to content

Commit

Permalink
Add closure test
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Aug 27, 2022
1 parent 29a7057 commit 75ea471
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
13 changes: 13 additions & 0 deletions tests/ui/needless_borrow.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,16 @@ mod meets_msrv {
let _ = std::process::Command::new("ls").args(["-a", "-l"]).status().unwrap();
}
}

#[allow(dead_code)]
fn closure_test() {
let env = "env".to_owned();
let arg = "arg".to_owned();
let f = |arg| {
let loc = "loc".to_owned();
let _ = std::fs::write("x", &env); // Don't lint. In environment
let _ = std::fs::write("x", arg);
let _ = std::fs::write("x", loc);
};
f(arg);
}
13 changes: 13 additions & 0 deletions tests/ui/needless_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,16 @@ mod meets_msrv {
let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap();
}
}

#[allow(dead_code)]
fn closure_test() {
let env = "env".to_owned();
let arg = "arg".to_owned();
let f = |arg| {
let loc = "loc".to_owned();
let _ = std::fs::write("x", &env); // Don't lint. In environment
let _ = std::fs::write("x", &arg);
let _ = std::fs::write("x", &loc);
};
f(arg);
}
14 changes: 13 additions & 1 deletion tests/ui/needless_borrow.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,17 @@ error: the borrowed expression implements the required traits
LL | let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap();
| ^^^^^^^^^^^^^ help: change this to: `["-a", "-l"]`

error: aborting due to 31 previous errors
error: the borrowed expression implements the required traits
--> $DIR/needless_borrow.rs:311:37
|
LL | let _ = std::fs::write("x", &arg);
| ^^^^ help: change this to: `arg`

error: the borrowed expression implements the required traits
--> $DIR/needless_borrow.rs:312:37
|
LL | let _ = std::fs::write("x", &loc);
| ^^^^ help: change this to: `loc`

error: aborting due to 33 previous errors

0 comments on commit 75ea471

Please sign in to comment.