@@ -44,10 +44,11 @@ subtyping of its outputs. There are two kinds of variance in Rust:
44
44
* F is * invariant* over ` T ` otherwise (no subtyping relation can be derived)
45
45
46
46
(For those of you who are familiar with variance from other languages, what we
47
- refer to as "just" variance is in fact * covariance* . Rust does not have
48
- contravariance. Historically Rust did have some contravariance but it was
49
- scrapped due to poor interactions with other features. If you experience
50
- contravariance in Rust call your local compiler developer for medical advice.)
47
+ refer to as "just" variance is in fact * covariance* . Rust has * contravariance*
48
+ for functions. The future of contravariance is uncertain and it may be
49
+ scrapped. For now, ` fn(T) ` is contravariant in ` T ` , which is used in matching
50
+ methods in trait implementations to the trait definition. Traits don't have
51
+ inferred variance, so ` Fn(T) ` is invariant in ` T ` ).
51
52
52
53
Some important variances:
53
54
@@ -200,7 +201,7 @@ use std::cell::Cell;
200
201
201
202
struct Foo <'a , 'b , A : 'a , B : 'b , C , D , E , F , G , H > {
202
203
a : & 'a A , // variant over 'a and A
203
- b : & 'b mut B , // invariant over 'b and B
204
+ b : & 'b mut B , // variant over 'b and invariant over B
204
205
c : * const C , // variant over C
205
206
d : * mut D , // invariant over D
206
207
e : Vec <E >, // variant over E
0 commit comments