2013-12-28 20:24:15 +00:00
|
|
|
pub struct CrateId {
|
2014-05-22 23:57:53 +00:00
|
|
|
local_path: String,
|
2020-05-20 17:58:41 +00:00
|
|
|
junk: String,
|
2013-09-29 21:46:23 +00:00
|
|
|
}
|
|
|
|
|
2013-12-28 20:24:15 +00:00
|
|
|
impl CrateId {
|
|
|
|
fn new(s: &str) -> CrateId {
|
2020-05-20 17:58:41 +00:00
|
|
|
CrateId { local_path: s.to_string(), junk: "wutevs".to_string() }
|
2013-09-29 21:46:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn remove_package_from_database() {
|
2018-01-03 23:54:33 +00:00
|
|
|
let mut lines_to_use: Vec<&CrateId> = Vec::new();
|
2020-05-20 17:58:41 +00:00
|
|
|
//~^ NOTE `lines_to_use` declared here, outside of the closure body
|
2015-02-01 17:44:15 +00:00
|
|
|
let push_id = |installed_id: &CrateId| {
|
2020-05-20 17:58:41 +00:00
|
|
|
//~^ NOTE `installed_id` is a reference that is only valid in the closure body
|
2013-09-29 21:46:23 +00:00
|
|
|
lines_to_use.push(installed_id);
|
2020-05-20 17:58:41 +00:00
|
|
|
//~^ ERROR borrowed data escapes outside of closure
|
|
|
|
//~| NOTE `installed_id` escapes the closure body here
|
2013-09-29 21:46:23 +00:00
|
|
|
};
|
|
|
|
list_database(push_id);
|
|
|
|
|
2015-01-31 17:20:46 +00:00
|
|
|
for l in &lines_to_use {
|
2013-10-14 01:48:47 +00:00
|
|
|
println!("{}", l.local_path);
|
2013-09-29 21:46:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-20 17:58:41 +00:00
|
|
|
pub fn list_database<F>(mut f: F)
|
|
|
|
where
|
|
|
|
F: FnMut(&CrateId),
|
|
|
|
{
|
2013-09-29 21:46:23 +00:00
|
|
|
let stuff = ["foo", "bar"];
|
|
|
|
|
2015-01-31 17:20:46 +00:00
|
|
|
for l in &stuff {
|
2013-12-28 20:24:15 +00:00
|
|
|
f(&CrateId::new(*l));
|
2013-09-29 21:46:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
remove_package_from_database();
|
|
|
|
}
|