1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Allow the unused structs
//! Compile fail tests
//!
//! Implemented in a minimal way, as doc tests in a hidden module.
/// ```compile_fail
/// use std::rc::Rc;
///
/// use contrie::ConMap;
/// use crossbeam_utils::thread;
///
/// let map: ConMap<usize, Rc<usize>> = ConMap::new();
///
/// thread::scope(|s| {
/// s.spawn(|_| {
/// drop(map);
/// });
/// }).unwrap();
/// ```
///
/// Similar one, but with Arc should work fine, though.
///
/// ```
/// use std::sync::Arc;
///
/// use contrie::ConMap;
/// use crossbeam_utils::thread;
///
/// let map: ConMap<usize, Arc<usize>> = ConMap::new();
///
/// thread::scope(|s| {
/// s.spawn(|_| {
/// drop(map);
/// });
/// }).unwrap();
/// ```
;
/// ```compile_fail
/// use std::rc::Rc;
///
/// use contrie::ConMap;
/// use crossbeam_utils::thread;
///
/// let map: ConMap<usize, Rc<usize>> = ConMap::new();
///
/// thread::scope(|s| {
/// s.spawn(|_| {
/// map.get(&42);
/// });
/// }).unwrap();
/// ```
///
/// Similar one, but with Arc should work fine, though.
///
/// ```
/// use std::sync::Arc;
///
/// use contrie::ConMap;
/// use crossbeam_utils::thread;
///
/// let map: ConMap<usize, Arc<usize>> = ConMap::new();
///
/// thread::scope(|s| {
/// s.spawn(|_| {
/// map.get(&42);
/// });
/// }).unwrap();
/// ```
;
/// ```compile_fail
/// use std::collections::hash_map::RandomState;
///
/// use contrie::raw::config::Trivial;
/// use contrie::raw::Raw;
///
/// let map: Raw<Trivial<usize>, RandomState> = Raw::with_hasher(RandomState::default());
/// let pin = crossbeam_epoch::pin();
/// let element = map.get(&42, &pin);
/// drop(map);
/// // Must not outlive the map
/// assert!(element.is_none());
/// ```
///
/// This one should be fine, as we don't drop the map.
///
/// ```
/// use std::collections::hash_map::RandomState;
///
/// use contrie::raw::config::Trivial;
/// use contrie::raw::Raw;
///
/// let map: Raw<Trivial<usize>, RandomState> = Raw::with_hasher(RandomState::default());
/// let pin = crossbeam_epoch::pin();
/// let element = map.get(&42, &pin);
/// assert!(element.is_none());
/// ```
;
/// Dropping map makes it impossible to borrow.
///
/// ```compile_fail
/// use std::collections::hash_map::RandomState;
///
/// use contrie::raw::config::Trivial;
/// use contrie::raw::iterator::Iter;
/// use contrie::raw::Raw;
///
/// let map: Raw<Trivial<usize>, RandomState> = Raw::with_hasher(RandomState::default());
/// let mut iter = Iter::new(&map);
/// let element = iter.next();
/// drop(map);
/// // Must not outlive the map
/// assert!(element.is_none());
/// ```
///
/// We are not allowed to drop the iterator either.
///
/// ```compile_fail
/// use std::collections::hash_map::RandomState;
///
/// use contrie::raw::config::Trivial;
/// use contrie::raw::iterator::Iter;
/// use contrie::raw::Raw;
///
/// let map: Raw<Trivial<usize>, RandomState> = Raw::with_hasher(RandomState::default());
/// let mut iter = Iter::new(&map);
/// let element = iter.next();
/// drop(iter);
/// // Must not outlive the iterator
/// assert!(element.is_none());
/// ```
///
/// But if we don't drop anything, everything is fine.
/// ```
/// use std::collections::hash_map::RandomState;
///
/// use contrie::raw::config::Trivial;
/// use contrie::raw::iterator::Iter;
/// use contrie::raw::Raw;
///
/// let map: Raw<Trivial<usize>, RandomState> = Raw::with_hasher(RandomState::default());
/// let mut iter = Iter::new(&map);
/// let element = iter.next();
/// assert!(element.is_none());
/// ```
;