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