book icon indicating copy to clipboard operation
book copied to clipboard

Chapter 19.1 unclear unsafe traits

Open L4nterns opened this issue 3 years ago • 0 comments
trafficstars

  • [x] I have checked the latest main branch to see if this has already been fixed
  • [x] I have searched existing issues and pull requests for duplicates

URL to the section(s) of the book with this problem: https://github.com/rust-lang/book/blob/main/src/ch19-01-unsafe-rust.md#implementing-an-unsafe-trait

Description of the problem: Quote from the book: A trait is unsafe when at least one of its methods has some invariant that the compiler can't verify. But through testing, I found that the following code can be compiled:

unsafe trait SomeTrait {
    fn some_fn();
}
unsafe trait SomeTrait {}

I also consulted the following information: https://users.rust-lang.org/t/what-is-unsafe-trait/64225/4 In my opinion, there should be no relationship between whether trait is insecure or not and whether the method of trait is insecure or not.

Suggested fix: If I am right, please remove this passage from the book: A trait is unsafe when at least one of its methods has some invariant that the compiler can't verify.

L4nterns avatar Oct 22 '22 10:10 L4nterns