2018-08-30 12:18:55 +00:00
|
|
|
//@ run-pass
|
2015-01-05 12:26:29 +00:00
|
|
|
// This is a regression test for something that only came up while
|
|
|
|
// attempting to bootstrap librustc with new destructor lifetime
|
|
|
|
// semantics.
|
|
|
|
|
2024-04-06 22:33:37 +00:00
|
|
|
#![allow(unexpected_cfgs)] // for the cfg-as-descriptions
|
2015-03-22 20:13:15 +00:00
|
|
|
|
2015-01-05 12:26:29 +00:00
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::cell::RefCell;
|
|
|
|
|
|
|
|
// This version does not yet work (associated type issues)...
|
|
|
|
#[cfg(cannot_use_this_yet)]
|
|
|
|
fn foo<'a>(map: RefCell<HashMap<&'static str, &'a [u8]>>) {
|
2015-03-03 08:42:26 +00:00
|
|
|
let one = [1];
|
2015-02-18 19:48:57 +00:00
|
|
|
assert_eq!(map.borrow().get("one"), Some(&one[..]));
|
2015-01-05 12:26:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(cannot_use_this_yet_either)]
|
|
|
|
// ... and this version does not work (the lifetime of `one` is
|
|
|
|
// supposed to match the lifetime `'a`) ...
|
|
|
|
fn foo<'a>(map: RefCell<HashMap<&'static str, &'a [u8]>>) {
|
2015-03-03 08:42:26 +00:00
|
|
|
let one = [1];
|
2015-03-30 16:22:46 +00:00
|
|
|
assert_eq!(map.borrow().get("one"), Some(&&one[..]));
|
2015-01-05 12:26:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(all(not(cannot_use_this_yet),not(cannot_use_this_yet_either)))]
|
|
|
|
fn foo<'a>(map: RefCell<HashMap<&'static str, &'a [u8]>>) {
|
|
|
|
// ...so instead we walk through the trivial slice and make sure
|
|
|
|
// it contains the element we expect.
|
|
|
|
|
|
|
|
for (i, &x) in map.borrow().get("one").unwrap().iter().enumerate() {
|
|
|
|
assert_eq!((i, x), (0, 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2015-03-03 08:42:26 +00:00
|
|
|
let zer = [0];
|
|
|
|
let one = [1];
|
|
|
|
let two = [2];
|
2015-01-05 12:26:29 +00:00
|
|
|
let mut map = HashMap::new();
|
2015-02-18 19:48:57 +00:00
|
|
|
map.insert("zero", &zer[..]);
|
|
|
|
map.insert("one", &one[..]);
|
|
|
|
map.insert("two", &two[..]);
|
2015-01-05 12:26:29 +00:00
|
|
|
let map = RefCell::new(map);
|
|
|
|
foo(map);
|
|
|
|
}
|