From 1fb55fe5a0f6ca1bab3d04d71d107849f6870a36 Mon Sep 17 00:00:00 2001 From: nomicon-kr Date: Sun, 23 Jun 2024 20:43:11 +0900 Subject: [PATCH] Update working-with-unsafe.md --- src/working-with-unsafe.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/working-with-unsafe.md b/src/working-with-unsafe.md index ffd63a4..74cc249 100644 --- a/src/working-with-unsafe.md +++ b/src/working-with-unsafe.md @@ -77,12 +77,9 @@ fn make_room(&mut self) { } ``` -이 코드는 100% 안전한 러스트이지만, 동시에 완전히 불건전합니다. 용량을 변경하는 것은 Vec의 불변의 원칙을 파괴합니다. +이 코드는 100% 안전한 러스트이지만, 동시에 완전히 불건전합니다. 용량을 변경하는 것은 Vec의 불문율(`cap` 이 Vec의 할당된 용량을 반영한다는 것)을 파괴합니다. 이것은 Vec의 나머지 코드가 방어할 수 있는 것이 아닙니다. Vec은 `cap` 필드를 검증할 방법이 없기 때문에 믿는 *수밖에 없습니다*. + -This code is 100% Safe Rust but it is also completely unsound. Changing the -capacity violates the invariants of Vec (that `cap` reflects the allocated space -in the Vec). This is not something the rest of Vec can guard against. It *has* -to trust the capacity field because there's no way to verify it. Because it relies on invariants of a struct field, this `unsafe` code does more than pollute a whole function: it pollutes a whole *module*.