An interesting wrinkle: with view types, Rust might get more than one kind of variance.
struct Example {
foo: usize,
bar: usize,
}
If the view type Example { foo }
is a supertype of Example
, then &mut (Example { foo })
should be a supertype of &mut Example
. The latter is strictly more powerful than the former. And one of the major motivations behind view types is to allow replacing fn(&mut Example)
with fn(&mut (Example { foo }))
, which requires &mut
to be covariant with respect to view types.