#Covariance rules with mutable stuff is KILLING ME

5 messages · Page 1 of 1 (latest)

drowsy copper
#
let c1: Cell<Smth<'short>> = ...;
let c2: Cell<Smth<'long>> = ...;

c1.set(c2);

Why can't I do this?

#

Shouldn't it be just fine to set c1 to a more useful internal type?

sick sigil
#

it doesn't depend only on Cell

#

?play ```rs
use std::cell::Cell;
#[derive(Clone, Copy)]
struct Smth<'a>(&'a i32);
fn foo<'a>(c: &Cell<Smth<'a>>, c2: Cell<Smth<'static>>) {
c.set(c2.get());
}