From 971d500a60c30cd92f915b3630ab787e1d8751f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20L=C3=B6bel?= Date: Tue, 11 Aug 2020 18:23:00 +0200 Subject: [PATCH] Add an extra fn() entry to the variance table in the subtyping chapter While discussing variance on a Rust help channel, I noticed that the subtyping chapter does not specifically mention the special case where a type parameter is used both in the input and output of a function, which, as far as I know, would make it be treated as invariant because its the intersection of both contravariance and covariance. In case I'm not totally wrong with this, I propose adding that case to the table to make it a bit more clear. --- src/subtyping.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/subtyping.md b/src/subtyping.md index 00764425a..43cd2b1f1 100644 --- a/src/subtyping.md +++ b/src/subtyping.md @@ -61,6 +61,7 @@ Variance of types is automatically determined as follows | `[T]` and `[T; n]` | | covariant | | `fn() -> T` | | covariant | | `fn(T) -> ()` | | contravariant | +| `fn(T) -> T` | | invariant | | `std::cell::UnsafeCell` | | invariant | | `std::marker::PhantomData` | | covariant | | `Trait + 'a` | covariant | invariant |