Skip to content

Commit 59ea990

Browse files
pcwaltonpnkfelix
authored andcommitted
librustc::metadata accommodate by-val closures in filesearch and loader.
1 parent d61dcfe commit 59ea990

File tree

2 files changed

+62
-44
lines changed

2 files changed

+62
-44
lines changed

src/librustc/metadata/filesearch.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ pub struct FileSearch<'a> {
3434
pub triple: &'a str,
3535
}
3636

37+
impl<'a> Clone for FileSearch<'a> {
38+
fn clone(&self) -> FileSearch<'a> {
39+
FileSearch {
40+
sysroot: self.sysroot,
41+
addl_lib_search_paths: self.addl_lib_search_paths,
42+
triple: self.triple,
43+
}
44+
}
45+
}
46+
3747
impl<'a> FileSearch<'a> {
3848
pub fn for_each_lib_search_path(&self, f: |&Path| -> FileMatch) {
3949
let mut visited_dirs = HashSet::new();

src/librustc/metadata/loader.rs

Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -195,53 +195,61 @@ impl<'a> Context<'a> {
195195
// of the crate id (path/name/id).
196196
//
197197
// The goal of this step is to look at as little metadata as possible.
198-
self.filesearch.search(|path| {
199-
let file = match path.filename_str() {
200-
None => return FileDoesntMatch,
201-
Some(file) => file,
202-
};
203-
if file.starts_with(rlib_prefix.as_slice()) &&
204-
file.ends_with(".rlib") {
205-
info!("rlib candidate: {}", path.display());
206-
match self.try_match(file, rlib_prefix.as_slice(), ".rlib") {
207-
Some(hash) => {
208-
info!("rlib accepted, hash: {}", hash);
209-
let slot = candidates.find_or_insert_with(hash, |_| {
210-
(HashSet::new(), HashSet::new())
211-
});
212-
let (ref mut rlibs, _) = *slot;
213-
rlibs.insert(fs::realpath(path).unwrap());
214-
FileMatches
215-
}
216-
None => {
217-
info!("rlib rejected");
218-
FileDoesntMatch
219-
}
220-
}
221-
} else if file.starts_with(dylib_prefix.as_slice()) &&
222-
file.ends_with(dysuffix){
223-
info!("dylib candidate: {}", path.display());
224-
match self.try_match(file,
225-
dylib_prefix.as_slice(),
226-
dysuffix) {
227-
Some(hash) => {
228-
info!("dylib accepted, hash: {}", hash);
229-
let slot = candidates.find_or_insert_with(hash, |_| {
230-
(HashSet::new(), HashSet::new())
231-
});
232-
let (_, ref mut dylibs) = *slot;
233-
dylibs.insert(fs::realpath(path).unwrap());
234-
FileMatches
198+
{
199+
let filesearch = self.filesearch.clone();
200+
let candidates_ptr = &mut candidates;
201+
filesearch.search(|path| {
202+
let file = match path.filename_str() {
203+
None => return FileDoesntMatch,
204+
Some(file) => file,
205+
};
206+
if file.starts_with(rlib_prefix.as_slice()) &&
207+
file.ends_with(".rlib") {
208+
info!("rlib candidate: {}", path.display());
209+
match self.try_match(file,
210+
rlib_prefix.as_slice(),
211+
".rlib") {
212+
Some(hash) => {
213+
info!("rlib accepted, hash: {}", hash);
214+
let slot =
215+
candidates_ptr.find_or_insert_with(hash, |_| {
216+
(HashSet::new(), HashSet::new())
217+
});
218+
let (ref mut rlibs, _) = *slot;
219+
rlibs.insert(fs::realpath(path).unwrap());
220+
FileMatches
221+
}
222+
None => {
223+
info!("rlib rejected");
224+
FileDoesntMatch
225+
}
235226
}
236-
None => {
237-
info!("dylib rejected");
238-
FileDoesntMatch
227+
} else if file.starts_with(dylib_prefix.as_slice()) &&
228+
file.ends_with(dysuffix){
229+
info!("dylib candidate: {}", path.display());
230+
match self.try_match(file,
231+
dylib_prefix.as_slice(),
232+
dysuffix) {
233+
Some(hash) => {
234+
info!("dylib accepted, hash: {}", hash);
235+
let slot =
236+
candidates_ptr.find_or_insert_with(hash, |_| {
237+
(HashSet::new(), HashSet::new())
238+
});
239+
let (_, ref mut dylibs) = *slot;
240+
dylibs.insert(fs::realpath(path).unwrap());
241+
FileMatches
242+
}
243+
None => {
244+
info!("dylib rejected");
245+
FileDoesntMatch
246+
}
239247
}
248+
} else {
249+
FileDoesntMatch
240250
}
241-
} else {
242-
FileDoesntMatch
243-
}
244-
});
251+
});
252+
}
245253

246254
// We have now collected all known libraries into a set of candidates
247255
// keyed of the filename hash listed. For each filename, we also have a

0 commit comments

Comments
 (0)