Skip to content

Commit 5a10456

Browse files
committed
Auto merge of #30332 - bluss:nomicon-variance, r=gankro
Update nomicon for variance typo & contravariance Fixes #28704 Fixes #28100
2 parents 5de242f + 2a30f0e commit 5a10456

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/doc/nomicon/subtyping.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ subtyping of its outputs. There are two kinds of variance in Rust:
4444
* F is *invariant* over `T` otherwise (no subtyping relation can be derived)
4545

4646
(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`).
5152

5253
Some important variances:
5354

@@ -200,7 +201,7 @@ use std::cell::Cell;
200201

201202
struct Foo<'a, 'b, A: 'a, B: 'b, C, D, E, F, G, H> {
202203
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
204205
c: *const C, // variant over C
205206
d: *mut D, // invariant over D
206207
e: Vec<E>, // variant over E

0 commit comments

Comments
 (0)