]> git.proxmox.com Git - rustc.git/blob - src/test/ui/cross-crate/auxiliary/cci_nested_lib.rs
Update upstream source from tag 'upstream/1.57.0+dfsg1'
[rustc.git] / src / test / ui / cross-crate / auxiliary / cci_nested_lib.rs
1 use std::cell::RefCell;
2
3 pub struct Entry<A,B> {
4 key: A,
5 value: B
6 }
7
8 pub struct alist<A,B> {
9 eq_fn: extern "Rust" fn(A,A) -> bool,
10 data: Box<RefCell<Vec<Entry<A,B>>>>,
11 }
12
13 pub fn alist_add<A:'static,B:'static>(lst: &alist<A,B>, k: A, v: B) {
14 let mut data = lst.data.borrow_mut();
15 (*data).push(Entry{key:k, value:v});
16 }
17
18 pub fn alist_get<A:Clone + 'static,
19 B:Clone + 'static>(
20 lst: &alist<A,B>,
21 k: A)
22 -> B {
23 let eq_fn = lst.eq_fn;
24 let data = lst.data.borrow();
25 for entry in &(*data) {
26 if eq_fn(entry.key.clone(), k.clone()) {
27 return entry.value.clone();
28 }
29 }
30 panic!();
31 }
32
33 #[inline]
34 pub fn new_int_alist<B:'static>() -> alist<isize, B> {
35 fn eq_int(a: isize, b: isize) -> bool { a == b }
36 return alist {
37 eq_fn: eq_int,
38 data: Box::new(RefCell::new(Vec::new())),
39 };
40 }
41
42 #[inline]
43 pub fn new_int_alist_2<B:'static>() -> alist<isize, B> {
44 #[inline]
45 fn eq_int(a: isize, b: isize) -> bool { a == b }
46 return alist {
47 eq_fn: eq_int,
48 data: Box::new(RefCell::new(Vec::new())),
49 };
50 }