Skip to content

Commit cc72a67

Browse files
committed
Add test custom_deref_target
1 parent cd8d911 commit cc72a67

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

tests/for_deref.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,30 @@ fn gat() {
117117
impls_gat(S);
118118
impls_gat(Box::new(S));
119119
}
120+
121+
#[test]
122+
fn custom_deref_target() {
123+
#[autoimpl(Deref<Target = T>, DerefMut using self.0)]
124+
struct BoxingWrapper<T: ?Sized>(Box<T>);
125+
126+
#[autoimpl(for<T: trait + ?Sized> BoxingWrapper<T>)]
127+
trait Increment {
128+
fn increment(&mut self);
129+
}
130+
131+
impl Increment for i32 {
132+
fn increment(&mut self) {
133+
*self += 1;
134+
}
135+
}
136+
137+
let mut x = BoxingWrapper(Box::new(0));
138+
x.increment();
139+
assert_eq!(*x.0, 1);
140+
141+
let mut y = 10;
142+
y.increment();
143+
let mut z = BoxingWrapper(Box::new(&mut y as &mut dyn Increment));
144+
z.increment();
145+
assert_eq!(y, 12);
146+
}

0 commit comments

Comments
 (0)