Skip to content

Recommend against treating unsafe fns as unsafe blocks. #4147

@matthias-t

Description

@matthias-t
  • I have searched open and closed issues and pull requests for duplicates, using these search terms:
    • "unsafe fn"
  • I have checked the latest main branch to see if this has already been fixed, in this file:
    • src/ch20-01-unsafe-rust.md

URL to the section(s) of the book with this problem:

Bodies of unsafe functions are effectively `unsafe` blocks, so to perform other
unsafe operations within an unsafe function, we don’t need to add another
`unsafe` block.

Description of the problem: Since RFC 2585, use of unsafe language features in unsafe fns outside of unsafe blocks is being gradually deprecated. They are currently a lint that will become a warning in the 2024 edition and may become an error in the future.

Suggested fix: Remove this paragraph altogether? Or clarify, such as: "Bodies of unsafe functions used to be trated as unsafe blocks by the compiler, but this feature is being gradually removed in newer editions of Rust. Just as in a regular function, we can use unsafe blocks inside an unsafe function to gain access to unsafe superpowers." The latter would help avoid surprises when working with older code, and there might be some value in showing that the language is changing.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions