]> git.lizzy.rs Git - rust.git/blob - src/test/ui/regions/regions-refcell.rs
Rollup merge of #89468 - FabianWolff:issue-89358, r=jackh726
[rust.git] / src / test / ui / regions / regions-refcell.rs
1 // run-pass
2 // This is a regression test for something that only came up while
3 // attempting to bootstrap librustc with new destructor lifetime
4 // semantics.
5
6
7 use std::collections::HashMap;
8 use std::cell::RefCell;
9
10 // This version does not yet work (associated type issues)...
11 #[cfg(cannot_use_this_yet)]
12 fn foo<'a>(map: RefCell<HashMap<&'static str, &'a [u8]>>) {
13     let one = [1];
14     assert_eq!(map.borrow().get("one"), Some(&one[..]));
15 }
16
17 #[cfg(cannot_use_this_yet_either)]
18 // ... and this version does not work (the lifetime of `one` is
19 // supposed to match the lifetime `'a`) ...
20 fn foo<'a>(map: RefCell<HashMap<&'static str, &'a [u8]>>) {
21     let one = [1];
22     assert_eq!(map.borrow().get("one"), Some(&&one[..]));
23 }
24
25 #[cfg(all(not(cannot_use_this_yet),not(cannot_use_this_yet_either)))]
26 fn foo<'a>(map: RefCell<HashMap<&'static str, &'a [u8]>>) {
27     // ...so instead we walk through the trivial slice and make sure
28     // it contains the element we expect.
29
30     for (i, &x) in map.borrow().get("one").unwrap().iter().enumerate() {
31         assert_eq!((i, x), (0, 1));
32     }
33 }
34
35 fn main() {
36     let zer = [0];
37     let one = [1];
38     let two = [2];
39     let mut map = HashMap::new();
40     map.insert("zero", &zer[..]);
41     map.insert("one",  &one[..]);
42     map.insert("two",  &two[..]);
43     let map = RefCell::new(map);
44     foo(map);
45 }