blob: 8c2a59868ca5e4f81346295da16ea77ff91a96c0 (
plain)
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
|
// check-pass
use std::marker::PhantomData;
use std::mem;
trait Container<'a> {
type Root: 'a;
}
type RootOf<'a, T> = <T as Container<'a>>::Root;
struct Test<'a, T> where T: Container<'a> {
pub root: T::Root,
marker: PhantomData<&'a mut &'a mut ()>,
}
impl<'a, 'b> Container<'b> for &'a str {
type Root = &'b str;
}
impl<'a, T> Test<'a, T> where T: for<'b> Container<'b> {
fn new(root: RootOf<'a, T>) -> Test<'a, T> {
Test {
root: root,
marker: PhantomData
}
}
fn with_mut<F, R>(&mut self, f: F) -> R where
F: for<'b> FnOnce(&'b mut RootOf<'b, T>) -> R {
f(unsafe { mem::transmute(&mut self.root) })
}
}
fn main() {
let val = "root";
let mut test: Test<&str> = Test::new(val);
test.with_mut(|_| { });
}
|