Covariant, invariant and PhantomData; Why does this compile?
⚓ Rust 📅 2026-06-23 👤 surdeus 👁️ 1use std::sync::atomic::{AtomicBool, AtomicPtr};
use std::marker::PhantomData;
#[allow(unused)]
#[derive(Default)]
struct Node<'b> {
locked: AtomicBool,
next: AtomicPtr<Node<'b>>,
// _marker: PhantomData<*const ()>,
}
fn accept<'a, 'b>(_: &'a Node<'b>) {}
fn main() {
let node: &'static Node<'static> = Box::leak(Box::new(Node::default()));
accept(node);
}
hi, without this marker shouldn't the entire struct Node be invariant in T as AtomicPtr is placed inside the struct? the code still compiles tho, with the _marker field commented as it is currently shown...
3 posts - 3 participants
🏷️ Rust_feed