]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/issue-7573.rs
20a6a5c92f149b0419b144d8a3b8a3101f03692b
[rust.git] / src / test / ui / borrowck / issue-7573.rs
1 pub struct CrateId {
2     local_path: String,
3     junk: String
4 }
5
6 impl CrateId {
7     fn new(s: &str) -> CrateId {
8         CrateId {
9             local_path: s.to_string(),
10             junk: "wutevs".to_string()
11         }
12     }
13 }
14
15 pub fn remove_package_from_database() {
16     let mut lines_to_use: Vec<&CrateId> = Vec::new();
17         //~^ NOTE cannot infer an appropriate lifetime
18     let push_id = |installed_id: &CrateId| {
19         //~^ NOTE borrowed data cannot outlive this closure
20         //~| NOTE ...so that variable is valid at time of its declaration
21         lines_to_use.push(installed_id);
22         //~^ ERROR borrowed data cannot be stored outside of its closure
23         //~| NOTE cannot be stored outside of its closure
24     };
25     list_database(push_id);
26
27     for l in &lines_to_use {
28         println!("{}", l.local_path);
29     }
30
31 }
32
33 pub fn list_database<F>(mut f: F) where F: FnMut(&CrateId) {
34     let stuff = ["foo", "bar"];
35
36     for l in &stuff {
37         f(&CrateId::new(*l));
38     }
39 }
40
41 pub fn main() {
42     remove_package_from_database();
43 }