Variance - Rust Compiler Development Guide
During type checking we must infer the variance of type and lifetime parameters. The algorithm is taken from Section 4 of the paper "Taming the Wildcards: Combining Definition- and Use-Site Variance" published in PLDI'11 and written by Altidor et al., and hereafter referred to as The Paper. This inference is explicitly designed not to consider the uses of types within code. To determine the variance of type parameters defined on type X, we only consider the definition of the type X and the definitions of any types it references. We only infer variance for type parameters found on data types like structs and enums. In these cases, there is a fairly straightforward explanation for what variance means. The variance of the type or lifetime parameters defines whether T<A> is a subtype of T<B> (resp. T<'a> and T<'b>) based on the relationship of A and B (resp. 'a and 'b). We do not infer variance for type parameters found on traits, functions, or impls. Variance on trait parameters can indee
Variance - Rust Compiler Development Guide Keyboard shortcuts Press ← or → to navigate between chapters Press S or / to search in the book Press ? to show this help Press Esc to hide this help Auto Light Rust Coal Navy Ayu Rust Compiler Development Guide Variance of type and lifetime parameters For a more general background on variance, see the background appendix. During type checking we must infer the variance of type and lifetime parameters. The algorithm is taken from Section 4 of the paper “Taming the Wildcards: Combining Definition- and Use-Site Variance” published in PLDI’11 and written
Explore this link on the map →saved by
related reading
- 21. Variance - CS2030S Programming Methodology IInus-cs2030s.github.io
- A half-hour to learn Rustfasterthanli.me
- Validating References with Lifetimes - The Rust Programming Languagedoc.rust-lang.org
- Generics: in, out, where | Kotlin Documentationkotlinlang.org
- TypeScript: Documentation - Genericstypescriptlang.org
- Rust Language Cheat Sheetcheats.rs
- Everything is Fertilenickcammarata.com
- The Better Alternative to Lifetime GATs - Sabrina Jewsonsabrinajewson.org
- Defining Shared Behavior with Traits - The Rust Programming Languagedoc.rust-lang.org
- Generic Data Types - The Rust Programming Languagedoc.rust-lang.org
- Pyrefly vs. ty: Comparing Python’s Two New Rust-Based Type Checkers | Edward Li's Blogblog.edward-li.com
- Patterns for Defensive Programming in Rust | corrode Rust Consultingcorrode.dev