From cbb626add76de42a548daa1b28aa5ceba4e0c617 Mon Sep 17 00:00:00 2001 From: Emmanuel Amoah <42612171+emamoah@users.noreply.github.com> Date: Tue, 30 Dec 2025 16:58:26 +0000 Subject: [PATCH 1/3] Clarify parameter and argument compatibility Although this is unambiguous after understanding it, I feel it could use a bit more clarity. The first time I read this, I was mostly confused. Many times, without even knowing. Since there was an assignment going on (`*input = val;`), I thought the compatibility was referring to THAT assignment. This proposal makes it clear, especially to new readers, where exactly this compatibility lies. --- src/subtyping.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/subtyping.md b/src/subtyping.md index cdb8c51..2d41eb6 100644 --- a/src/subtyping.md +++ b/src/subtyping.md @@ -118,7 +118,7 @@ This is a classic use-after-free bug! Our first instinct might be to blame the `assign` impl, but there's really nothing wrong here. It shouldn't be surprising that we might want to assign a `T` into a `T`. -The problem is that we cannot assume that `&mut &'static str` and `&mut &'b str` are compatible. +The problem is that we cannot assume that `&mut &'static str` (the `&mut hello` argument) and `&mut &'b str` (the `input` parameter) are compatible. This means that `&mut &'static str` **cannot** be a *subtype* of `&mut &'b str`, even if `'static` is a subtype of `'b`. From 95fa2429af7e12cd068b845faea80d7d1d40ede1 Mon Sep 17 00:00:00 2001 From: Emmanuel Amoah <42612171+emamoah@users.noreply.github.com> Date: Wed, 31 Dec 2025 07:06:47 +0000 Subject: [PATCH 2/3] Clarify parameter and argument compatibility --- src/subtyping.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/subtyping.md b/src/subtyping.md index 2d41eb6..e1864ea 100644 --- a/src/subtyping.md +++ b/src/subtyping.md @@ -118,9 +118,7 @@ This is a classic use-after-free bug! Our first instinct might be to blame the `assign` impl, but there's really nothing wrong here. It shouldn't be surprising that we might want to assign a `T` into a `T`. -The problem is that we cannot assume that `&mut &'static str` (the `&mut hello` argument) and `&mut &'b str` (the `input` parameter) are compatible. -This means that `&mut &'static str` **cannot** be a *subtype* of `&mut &'b str`, -even if `'static` is a subtype of `'b`. +The problem is that we cannot assume `&'static str` can still be downgraded into `&'world str` to satisfy `T`, once it's behind a `&mut` reference. This means that `&mut &'static str` **cannot** be a *subtype* of `&mut &'world str`, even if `'static` is a subtype of `'world`. Variance is the concept that Rust borrows to define relationships about subtypes through their generic parameters. From b646f1a5aa17ae7eabe2ad744c21e5a741d2b28e Mon Sep 17 00:00:00 2001 From: Emmanuel Amoah <42612171+emamoah@users.noreply.github.com> Date: Wed, 31 Dec 2025 07:19:19 +0000 Subject: [PATCH 3/3] Clarify parameter and argument compatibility --- src/subtyping.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/subtyping.md b/src/subtyping.md index e1864ea..eb0feac 100644 --- a/src/subtyping.md +++ b/src/subtyping.md @@ -118,7 +118,9 @@ This is a classic use-after-free bug! Our first instinct might be to blame the `assign` impl, but there's really nothing wrong here. It shouldn't be surprising that we might want to assign a `T` into a `T`. -The problem is that we cannot assume `&'static str` can still be downgraded into `&'world str` to satisfy `T`, once it's behind a `&mut` reference. This means that `&mut &'static str` **cannot** be a *subtype* of `&mut &'world str`, even if `'static` is a subtype of `'world`. +The problem is that we cannot assume `&'static str` can still be downgraded into `&'world str` to satisfy `T`, once it's behind a `&mut` reference. +This means that `&mut &'static str` **cannot** be a *subtype* of `&mut &'world str`, +even if `'static` is a subtype of `'world`. Variance is the concept that Rust borrows to define relationships about subtypes through their generic parameters.