Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardRustvariance co contra invariantSingle-choice MCQ

Why does this code fail to compile, citing variance, even though intuitively a longer-lived reference should be usable where a shorter one is needed?

fn store<'a>(slot: &mut &'a str, val: &'a str) { *slot = val; } fn main() { let mut s: &'static str = "hi"; let local = String::from("bye"); store(&mut s, &local); // error here }