Skip to content

Commit 4c18439

Browse files
committed
Merge pull request #30 from blaenk/stack-overflow
(fix) deref box to avoid stack overflow
2 parents 5dcd6be + b21769f commit 4c18439

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/internals.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,19 @@ impl<T: Any + Clone> CloneAny for T {
5454
}
5555

5656
impl Clone for Box<CloneAny> {
57-
fn clone(&self) -> Box<CloneAny> { self.clone_any() }
57+
fn clone(&self) -> Box<CloneAny> { (**self).clone_any() }
5858
}
5959

6060
impl Clone for Box<CloneAny + Send> {
61-
fn clone(&self) -> Box<CloneAny + Send> { self.clone_any_send() }
61+
fn clone(&self) -> Box<CloneAny + Send> { (**self).clone_any_send() }
6262
}
6363

6464
impl Clone for Box<CloneAny + Sync> {
65-
fn clone(&self) -> Box<CloneAny + Sync> { self.clone_any_sync() }
65+
fn clone(&self) -> Box<CloneAny + Sync> { (**self).clone_any_sync() }
6666
}
6767

6868
impl Clone for Box<CloneAny + Send + Sync> {
69-
fn clone(&self) -> Box<CloneAny + Send + Sync> { self.clone_any_send_sync() }
69+
fn clone(&self) -> Box<CloneAny + Send + Sync> { (**self).clone_any_send_sync() }
7070
}
7171

7272
unsafe impl UnsafeAnyExt for CloneAny {}

src/lib.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,13 @@ mod internals;
250250

251251
#[cfg(test)]
252252
mod test {
253-
use super::{TypeMap, SendMap, Key};
253+
use super::{TypeMap, CloneMap, SendMap, Key};
254254
use super::Entry::{Occupied, Vacant};
255255

256256
#[derive(Debug, PartialEq)]
257257
struct KeyType;
258258

259-
#[derive(Debug, PartialEq)]
259+
#[derive(Clone, Debug, PartialEq)]
260260
struct Value(u8);
261261

262262
impl Key for KeyType { type Value = Value; }
@@ -303,4 +303,12 @@ mod test {
303303
map.remove::<KeyType>();
304304
assert!(!map.contains::<KeyType>());
305305
}
306+
307+
#[test] fn test_clonemap() {
308+
let mut map: CloneMap = TypeMap::custom();
309+
map.insert::<KeyType>(Value(10));
310+
assert!(map.contains::<KeyType>());
311+
let cloned = map.clone();
312+
assert_eq!(map.get::<KeyType>(), cloned.get::<KeyType>());
313+
}
306314
}

0 commit comments

Comments
 (0)