]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/regions-refcell.rs
rustdoc: Replace no-pretty-expanded with pretty-expanded
[rust.git] / src / test / run-pass / regions-refcell.rs
1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // This is a regression test for something that only came up while
12 // attempting to bootstrap librustc with new destructor lifetime
13 // semantics.
14
15 // pretty-expanded FIXME #23616
16
17 use std::collections::HashMap;
18 use std::cell::RefCell;
19
20 // This version does not yet work (associated type issues)...
21 #[cfg(cannot_use_this_yet)]
22 fn foo<'a>(map: RefCell<HashMap<&'static str, &'a [u8]>>) {
23     let one = [1];
24     assert_eq!(map.borrow().get("one"), Some(&one[..]));
25 }
26
27 #[cfg(cannot_use_this_yet_either)]
28 // ... and this version does not work (the lifetime of `one` is
29 // supposed to match the lifetime `'a`) ...
30 fn foo<'a>(map: RefCell<HashMap<&'static str, &'a [u8]>>) {
31     let one = [1];
32     assert_eq!(map.borrow().get("one"), Some(&one.as_slice()));
33 }
34
35 #[cfg(all(not(cannot_use_this_yet),not(cannot_use_this_yet_either)))]
36 fn foo<'a>(map: RefCell<HashMap<&'static str, &'a [u8]>>) {
37     // ...so instead we walk through the trivial slice and make sure
38     // it contains the element we expect.
39
40     for (i, &x) in map.borrow().get("one").unwrap().iter().enumerate() {
41         assert_eq!((i, x), (0, 1));
42     }
43 }
44
45 fn main() {
46     let zer = [0];
47     let one = [1];
48     let two = [2];
49     let mut map = HashMap::new();
50     map.insert("zero", &zer[..]);
51     map.insert("one",  &one[..]);
52     map.insert("two",  &two[..]);
53     let map = RefCell::new(map);
54     foo(map);
55 }