]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/issue-7573.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / 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 { local_path: s.to_string(), junk: "wutevs".to_string() }
9     }
10 }
11
12 pub fn remove_package_from_database() {
13     let mut lines_to_use: Vec<&CrateId> = Vec::new();
14     //~^ NOTE `lines_to_use` declared here, outside of the closure body
15     let push_id = |installed_id: &CrateId| {
16         //~^ NOTE `installed_id` is a reference that is only valid in the closure body
17         lines_to_use.push(installed_id);
18         //~^ ERROR borrowed data escapes outside of closure
19         //~| NOTE `installed_id` escapes the closure body here
20     };
21     list_database(push_id);
22
23     for l in &lines_to_use {
24         println!("{}", l.local_path);
25     }
26 }
27
28 pub fn list_database<F>(mut f: F)
29 where
30     F: FnMut(&CrateId),
31 {
32     let stuff = ["foo", "bar"];
33
34     for l in &stuff {
35         f(&CrateId::new(*l));
36     }
37 }
38
39 pub fn main() {
40     remove_package_from_database();
41 }