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