Skip to content

yoke soundness issue with non-'static and contravariant cart, using Yoke::attach_to_cart + Yoke::get. #2926

Closed
@steffahn

Description

@steffahn

Here’s a repro, in small steps with useful type annotations

use yoke::Yoke;

type F<'a> = fn(&'a ());

fn main() {
    let n = String::from("Hello World!");
    let x: Yoke<&'static str, Box<F<'_>>> = Yoke::attach_to_cart(Box::new((|_| {}) as _), |_| &n[..]);
    let y: Yoke<&'static str, Box<F<'static>>> = x;
    let s: &'static Yoke<&'static str, Box<F<'static>>> = Box::leak(Box::new(y));
    let r: &'static str = s.get();

    println!("pre-drop: {r}");
    drop(n);
    println!("post-drop: {r}");
}

Run Online in Rust Explorer

pre-drop: Hello World!
post-drop: �[YU��Es

Metadata

Metadata

Assignees

Labels

C-zerovecComponent: Yoke, ZeroVec, DataBake

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions