Skip to content

Commit 971d500

Browse files
authored
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.
1 parent 90fb49f commit 971d500

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/subtyping.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Variance of types is automatically determined as follows
6161
| `[T]` and `[T; n]` | | covariant |
6262
| `fn() -> T` | | covariant |
6363
| `fn(T) -> ()` | | contravariant |
64+
| `fn(T) -> T` | | invariant |
6465
| `std::cell::UnsafeCell<T>` | | invariant |
6566
| `std::marker::PhantomData<T>` | | covariant |
6667
| `Trait<T> + 'a` | covariant | invariant |

0 commit comments

Comments
 (0)