diff options
| author | Ulrik Sverdrup <bluss@users.noreply.github.com> | 2015-12-11 18:23:31 +0100 |
|---|---|---|
| committer | Ulrik Sverdrup <bluss@users.noreply.github.com> | 2015-12-12 06:14:06 +0100 |
| commit | 2a30f0ea41ce593b5da66d0973a5716401b2c9ba (patch) | |
| tree | 0280d1a253d9242011560430cb104a1a970c680a /src | |
| parent | a0101624ade4e8335837c8f0578a6364dd09d08d (diff) | |
| download | rust-2a30f0ea41ce593b5da66d0973a5716401b2c9ba.tar.gz rust-2a30f0ea41ce593b5da66d0973a5716401b2c9ba.zip | |
nomicon: Mention contravariance
Diffstat (limited to 'src')
| -rw-r--r-- | src/doc/nomicon/subtyping.md | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/doc/nomicon/subtyping.md b/src/doc/nomicon/subtyping.md index 0253a1fb035..5def5c39033 100644 --- a/src/doc/nomicon/subtyping.md +++ b/src/doc/nomicon/subtyping.md @@ -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: |
