From 45ef9f63f384b869cddfde68fa5803b3af1e5349 Mon Sep 17 00:00:00 2001 From: Pure White Date: Thu, 4 Jan 2024 00:01:36 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=9F=E9=9A=8F=E4=B8=8A=E6=B8=B8=20PR=20#43?= =?UTF-8?q?8=20=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/intro.md | 2 +- src/subtyping.md | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/intro.md b/src/intro.md index 9b31428..7e9fab0 100644 --- a/src/intro.md +++ b/src/intro.md @@ -15,7 +15,7 @@ > > 如果大家对于翻译有更好的建议或者想法,欢迎直接 PR~ > -> 目前翻译基于 commit:f6bd083c4ccfc4ce6699b8b4154e3c45c5a27a8c,基于时间:2023/12/18 +> 目前翻译基于 commit:6bc2415218d4dd0cb01433d8320f5ccf79c343a1,基于时间:2024/1/4 > > Q:为什么不基于之前已有的中文版进行改进? > diff --git a/src/subtyping.md b/src/subtyping.md index 07ef5b2..01983a1 100644 --- a/src/subtyping.md +++ b/src/subtyping.md @@ -268,9 +268,7 @@ thread_local! { /// 将给定的输入保存到一个thread local的 `Vec<&'static str>` fn store(input: &'static str) { - StaticVecs.with(|v| { - v.borrow_mut().push(input); - }) + StaticVecs.with_borrow_mut(|v| v.push(input)); } /// 用有着相同生命周期的参数 `input` 去调用给定的函数 @@ -291,9 +289,8 @@ fn main() { demo(&smuggle, store); } - StaticVecs.with(|v| { - println!("{:?}", v.borrow()); // 使用在被释放后的值 😿 - }); + // use after free 😿 + StaticVecs.with_borrow(|v| println!("{v:?}")); } ```