//! This test demonstrates that the function pointer UB exploit is now prevented.
//!
//! Before making Peek invariant over 'facet, this code would compile and
//! lead to use-after-free when run under miri.
//!
//! See: https://github.com/facet-rs/facet/issues/1168

use facet::Facet;
use facet_reflect::Peek;

#[derive(Debug, Facet)]
struct FnWrapper<'a> {
    f: fn(&'a str),
}

fn main() {
    // This function tries to launder lifetimes via Peek
    // With Peek being invariant over 'facet, this should fail to compile
    fn scope<'l, 'a>(token: &'l FnWrapper<'static>) -> &'l FnWrapper<'a> {
        Peek::new(token).get::<FnWrapper<'a>>().unwrap()
    }

    scope(&FnWrapper {
        f: |s| println!("{s}"),
    });
}
