Recently I have been working with the generativity crate. I want to better understand the notion of an "untrusted carrier" mentioned in its crates.io documentation.
fn scope<F>(f: F)
where F: for<'id> FnOnce(Guard<'id>)
{
make_guard!(guard);
f(guard);
}
fn unify<'a>(_: &'a (), _: &Guard<'a>) {
// here, you have two `'a` which are equivalent to `guard`'s `'id`
}
fn main() {
let place = ();
make_guard!(guard);
unify(&place, &guard);
scope(|guard| {
unify(&place, &guard);
})
}
This doesn't even compile. Even then, I don't understand the problem. Sure, you might be able to create an &'id reference to a random thing without having an Id
, but why does that even matter? I don't care about the 'id
lifetime unless it is inside a Guard<'id>
or an Id<'id>
which are the structures actually being used. I have been tinkering around to try to get an actual working example of unexpected behavior using an "untrusted carrier", but I have not been able to get anything to compile. Any further help would be much appreciated.