Update checked-uninit.md

pull/464/head
nomicon-kr 7 months ago committed by GitHub
parent 4ec6eedf71
commit fb20c1884f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -71,42 +71,40 @@ fn main() {
let x: i32; let x: i32;
loop { loop {
// Rust doesn't understand that this branch will be taken unconditionally, // 러스트는 이 경우가 조건 없이 실행될 거라는 것을 알지 못합니다
// because it relies on actual values. // 이 경우는 실제 값에 의존하기 때문이죠
if true { if true {
// But it does understand that it will only be taken once because // 하지만 러스트는 이 경우가 정확히 한 번 실행될 거라는 것을 압니다
// we unconditionally break out of it. Therefore `x` doesn't // 우리가 조건 없이 이 경우를 `break`하기 때문이죠.
// need to be marked as mutable. // 따라서 `x`는 가변일 필요가 없습니다.
x = 0; x = 0;
break; break;
} }
} }
// It also knows that it's impossible to get here without reaching the break. // 또한 러스트는 `break`에 닿지 않고서는 여기에 도달할 수 없다는 것을 압니다.
// And therefore that `x` must be initialized here! // 그리고 따라서 여기의 `x`는 반드시 초기화된 상태라는 것도요!
println!("{}", x); println!("{}", x);
``` ```
If a value is moved out of a variable, that variable becomes logically 만약 어떤 변수에서 값이 이동한다면, 그 타입이 `Copy`가 아닐 경우 그 변수는 논리적으로 미초기화된 상태가 됩니다. 즉:
uninitialized if the type of the value isn't Copy. That is:
```rust ```rust
fn main() { fn main() {
let x = 0; let x = 0;
let y = Box::new(0); let y = Box::new(0);
let z1 = x; // x is still valid because i32 is Copy let z1 = x; // `i32``Copy`이므로 `x`는 여전히 유효합니다
let z2 = y; // y is now logically uninitialized because Box isn't Copy let z2 = y; // `Box``Copy`가 아니므로 `y`는 이제 논리적으로 미초기화 되었습니다
} }
``` ```
However reassigning `y` in this example *would* require `y` to be marked as 하지만 이 예제에서 `y`에 값을 다시 할당하려면 `y`가 가변이어야 *할 겁니다*, 안전한 러스트에서 프로그램이 `y`의 값이 변했다는 것을 볼 수 있을 테니까요:
mutable, as a Safe Rust program could observe that the value of `y` changed:
```rust ```rust
fn main() { fn main() {
let mut y = Box::new(0); let mut y = Box::new(0);
let z = y; // y is now logically uninitialized because Box isn't Copy let z = y; // `Box``Copy`가 아니므로 `y`는 이제 논리적으로 미초기화 되었습니다
y = Box::new(1); // reinitialize y y = Box::new(1); // `y`를 재초기화 합니다
} }
``` ```
Otherwise it's like `y` is a brand new variable. 그게 아니라면 마치 `y`가 새로운 변수처럼 보일 테니까요.

Loading…
Cancel
Save