Skip to content

Commit

Permalink
Merge PR #313: Stabilize unsafe extern blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
traviscross committed Aug 6, 2024
2 parents 69ea9b6 + f646cd4 commit aeeb287
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
- [Macro fragment specifiers](rust-2024/macro-fragment-specifiers.md)
- [Missing macro fragment specifiers](rust-2024/missing-macro-fragment-specifiers.md)
- [Never type fallback change](rust-2024/never-type-fallback.md)
- [`unsafe extern` blocks](rust-2024/unsafe-extern.md)
- [Unsafe `extern` blocks](rust-2024/unsafe-extern.md)
- [Unsafe attributes](rust-2024/unsafe-attributes.md)
6 changes: 2 additions & 4 deletions src/rust-2024/unsafe-extern.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `unsafe extern` blocks
# Unsafe `extern` blocks

🚧 The 2024 Edition has not yet been released and hence this section is still "under construction".
More information may be found in the tracking issue at <https://github.com/rust-lang/rust/issues/123743>.
Expand All @@ -11,13 +11,11 @@ More information may be found in the tracking issue at <https://github.com/rust-

## Details

Rust 1.xx <!--TODO--> added the ability in all editions to mark [`extern` blocks] with the `unsafe` keyword.[^RFC3484] Adding the `unsafe` keyword helps to emphasize that it is the responsibility of the author of the `extern` block to ensure that the signatures are correct. If the signatures are not correct, then it may result in undefined behavior.
Rust 1.82 added the ability in all editions to mark [`extern` blocks] with the `unsafe` keyword.[^RFC3484] Adding the `unsafe` keyword helps to emphasize that it is the responsibility of the author of the `extern` block to ensure that the signatures are correct. If the signatures are not correct, then it may result in undefined behavior.

The syntax for an unsafe `extern` block looks like this:

```rust
# #![feature(unsafe_extern_blocks)]

unsafe extern "C" {
// sqrt (from libm) may be called with any `f64`
pub safe fn sqrt(x: f64) -> f64;
Expand Down

0 comments on commit aeeb287

Please sign in to comment.