]> git.lizzy.rs Git - rust.git/blob - src/test/ui/threads-sendsync/send_str_hashmap.rs
Rollup merge of #99064 - lyming2007:issue-97687-fix, r=estebank
[rust.git] / src / test / ui / threads-sendsync / send_str_hashmap.rs
1 // run-pass
2 use std::collections::HashMap;
3 use std::borrow::Cow;
4
5 use std::borrow::Cow::Borrowed as B;
6 use std::borrow::Cow::Owned as O;
7
8 type SendStr = Cow<'static, str>;
9
10 fn main() {
11     let mut map: HashMap<SendStr, usize> = HashMap::new();
12     assert!(map.insert(B("foo"), 42).is_none());
13     assert!(map.insert(O("foo".to_string()), 42).is_some());
14     assert!(map.insert(B("foo"), 42).is_some());
15     assert!(map.insert(O("foo".to_string()), 42).is_some());
16
17     assert!(map.insert(B("foo"), 43).is_some());
18     assert!(map.insert(O("foo".to_string()), 44).is_some());
19     assert!(map.insert(B("foo"), 45).is_some());
20     assert!(map.insert(O("foo".to_string()), 46).is_some());
21
22     let v = 46;
23
24     assert_eq!(map.get(&O("foo".to_string())), Some(&v));
25     assert_eq!(map.get(&B("foo")), Some(&v));
26
27     let (a, b, c, d) = (50, 51, 52, 53);
28
29     assert!(map.insert(B("abc"), a).is_none());
30     assert!(map.insert(O("bcd".to_string()), b).is_none());
31     assert!(map.insert(B("cde"), c).is_none());
32     assert!(map.insert(O("def".to_string()), d).is_none());
33
34     assert!(map.insert(B("abc"), a).is_some());
35     assert!(map.insert(O("bcd".to_string()), b).is_some());
36     assert!(map.insert(B("cde"), c).is_some());
37     assert!(map.insert(O("def".to_string()), d).is_some());
38
39     assert!(map.insert(O("abc".to_string()), a).is_some());
40     assert!(map.insert(B("bcd"), b).is_some());
41     assert!(map.insert(O("cde".to_string()), c).is_some());
42     assert!(map.insert(B("def"), d).is_some());
43
44     assert_eq!(map.get("abc"), Some(&a));
45     assert_eq!(map.get("bcd"), Some(&b));
46     assert_eq!(map.get("cde"), Some(&c));
47     assert_eq!(map.get("def"), Some(&d));
48
49     assert_eq!(map.get(&B("abc")), Some(&a));
50     assert_eq!(map.get(&B("bcd")), Some(&b));
51     assert_eq!(map.get(&B("cde")), Some(&c));
52     assert_eq!(map.get(&B("def")), Some(&d));
53 }