When I was reading rfcs-0738-variance, I was confused about "Option is invariant with respect to its argument type". I think it should be covariant. Moreover, there are no compilation errors in the codes in the rfcs, but the rfcs states that there should be "ERROR: Cannot infer an appropriate lifetime".
I'm confused. Thanks for the help.
#[derive(Debug)]
struct List<'l> {
field1: &'l i32,
field2: Option<&'l i32>,
}
fn foo<'a>(field1: &i32, field2: Option<&i32>) {
let list = List { field1: field1, field2: field2 };
// ERROR: Cannot infer an appropriate lifetime
println!("{:?}", list);
}
fn main() {
}