Generativity: what is an "untrusted lifetime carrier"

⚓ Rust    📅 2025-06-26    👤 surdeus    👁️ 6      

surdeus

Warning

This post was published 47 days ago. The information described in this article may have changed.

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.

1 post - 1 participant

Read full topic

🏷️ rust_feed