unsafe impl<#[may_dangle] 'a> Drop for Inspector<'a> {
unsafe impl<#[may_dangle] 'a> Drop for Inspector<'a> {
fn drop(&mut self) {
fn drop(&mut self) {
println!("Inspector(_, {}) knows when *not* to inspect.", self.1);
println!("Inspector(_, {})는 보지 *않아야* 할 때를 압니다.", self.1);
}
}
}
}
@ -214,15 +205,9 @@ fn main() {
}
}
```
```
Use of this attribute requires the `Drop` impl to be marked `unsafe` because the
이 속성을 사용하려면 `Drop` 구현을 `unsafe`로 수식해야 하는데, 이는 수명이 다했을 수 있는 데이터(예를 들어 위의 `self.0`)를 접근하지 않는다는 보장을 컴파일러가 검사하지 않기 때문입니다.
compiler is not checking the implicit assertion that no potentially expired data
(e.g. `self.0` above) is accessed.
The attribute can be applied to any number of lifetime and type parameters. In
이 속성은 어느 숫자의 수명이나 타입 매개변수에도 적용할 수 있습니다. 다음의 예제에서 우리는 `'b`의 수명을 갖는 레퍼런스를 접근하지 않고, `T`는 오직 이동 혹은 해제만 할 것이라고 컴파일러에게 알립니다. 하지만 `'a`와 `U`에 대해서는 이 속성을 쓰지 않음으로써 우리가 이 수명과 이 타입의 데이터를 접근할 것이라고 알립니다:
the following example, we assert that we access no data behind a reference of
lifetime `'b` and that the only uses of `T` will be moves or drops, but omit
the attribute from `'a` and `U`, because we do access data with that lifetime
and that type:
```rust
```rust
#![feature(dropck_eyepatch)]
#![feature(dropck_eyepatch)]
@ -237,6 +222,8 @@ unsafe impl<'a, #[may_dangle] 'b, #[may_dangle] T, U: Display> Drop for Inspecto
}
}
```
```
It is sometimes obvious that no such access can occur, like the case above.
It is sometimes obvious that no such access can occur, like the case above.
However, when dealing with a generic type parameter, such access can
However, when dealing with a generic type parameter, such access can
occur indirectly. Examples of such indirect access are:
occur indirectly. Examples of such indirect access are: