Skip to content

Commit

Permalink
nomicon: Mention contravariance
Browse files Browse the repository at this point in the history
  • Loading branch information
bluss committed Dec 12, 2015
1 parent a010162 commit 2a30f0e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/doc/nomicon/subtyping.md
Expand Up @@ -44,10 +44,11 @@ subtyping of its outputs. There are two kinds of variance in Rust:
* F is *invariant* over `T` otherwise (no subtyping relation can be derived)

(For those of you who are familiar with variance from other languages, what we
refer to as "just" variance is in fact *covariance*. Rust does not have
contravariance. Historically Rust did have some contravariance but it was
scrapped due to poor interactions with other features. If you experience
contravariance in Rust call your local compiler developer for medical advice.)
refer to as "just" variance is in fact *covariance*. Rust has *contravariance*
for functions. The future of contravariance is uncertain and it may be
scrapped. For now, `fn(T)` is contravariant in `T`, which is used in matching
methods in trait implementations to the trait definition. Traits don't have
inferred variance, so `Fn(T)` is invariant in `T`).

Some important variances:

Expand Down

0 comments on commit 2a30f0e

Please sign in to comment.