Subtyping in Rust and Clarke's Third Law
summary
Claim: Rust’s subtyping lives in lifetimes and coercions not in object-like inheritance. Demonstrations use the compiler, the playground examples and macros: a hand-built unsafe cell that writes with pointers proves unsound and yields a dangling-pointer run showing garbage, while the real UnsafeCell plus the compiler’s inferred variance prevents it. The method/receiver coercions and the try macro conversions explain surprising behaviour: a nine-case grid of value/reference/mutable combos compiles except for one cell.
AI-written summary · about
chapters (20)
- 0:00Intro
- 4:42Subtyping
- 12:11Sanity Check
- 13:51What is Subtyping
- 17:05Integer to Integer Examples
- 18:20Integer to Ceiling Examples
- 19:17Java
- 20:08Deduction Rules
- 20:36Contravariance
- 22:44Does Rust have variants
- 24:07A magic trick
- 30:08Rust Subtyping
- 34:36mutable references
- 40:31unsafe cell
- 42:30duck subtyping
- 43:17coercion
- 44:16automatic borrowing
- 45:58dereferences
- 50:16pop quiz
- 50:59variance
related talks
19mType Theory for the Working Rustacean
15mNon-binary Rust: Between Safe and Unsafe
41mFunctional Rust - An Exploration
33mRust and Haskell, sitting in a tree
26mThe Freedom of Static Typing
38mType-level interfaces in Haskell & Rust: pragmatic type-level programming
35mLet’s Talk About Rust
54mMemory Safety with Rust
