Skip to content

Commit 2a30f0e

Browse files
committed
nomicon: Mention contravariance
1 parent a010162 commit 2a30f0e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/doc/nomicon/subtyping.md

Lines changed: 5 additions & 4 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

0 commit comments

Comments
 (0)