Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recommend against treating unsafe fns as unsafe blocks. #4147

Closed
matthias-t opened this issue Dec 9, 2024 · 1 comment · Fixed by #4148
Closed

Recommend against treating unsafe fns as unsafe blocks. #4147

matthias-t opened this issue Dec 9, 2024 · 1 comment · Fixed by #4148

Comments

@matthias-t
Copy link

  • 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.

@chriskrycho
Copy link
Contributor

Ah, excellent. I’ll figure out how to wordsmith this a bit, but (a) I am really glad this is happening and (b) I am really glad you flagged it up here so we can get it tweaked going forward! I have a change landed this week for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants