-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Document that "extern blocks must be unsafe" in Rust 2024 #140216
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
Conversation
r? @ibraheemdev rustbot has assigned @ibraheemdev. Use |
This comment has been minimized.
This comment has been minimized.
Since this is There is more at https://github.com/rust-lang/rfcs/blob/master/text/3484-unsafe-extern-blocks.md but mainly you have to assert that the function exists with that signature, since the compiler has no way to verify it. |
It's probably actually okay to drop the mention of edition differences. |
Sure, thank you for your feedback. I came up with two possible options. Option 1 (more compact):
Option 2 (more verbose):
Do you mean something like that? |
I think the first option is fine, the reference has more details about the caveats here. The safety comment should be adjusted though, it's describing what needs to be done rather than that we have done it. Something like "SAFETY: below function definitions match the headers for |
Got it, I just committed a possible wording. For consistency with the corresponding Reference item, I went for the term "function declarations" rather than "function signatures" or "function definitions". Please let me know if there is something to improve. Otherwise, the PR is complete from my side. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Please squash
Thanks for adding this clarification. @bors r+ rollup |
Document that "extern blocks must be unsafe" in Rust 2024 The [documentation on `extern`](https://doc.rust-lang.org/std/keyword.extern.html) contains the following code sample: ```rust #[link(name = "my_c_library")] extern "C" { fn my_c_function(x: i32) -> bool; } ``` Due to rust-lang#123743, attempting to compile such code with the 2024 edition of Rust fails: ``` error: extern blocks must be unsafe ``` This PR extends the `extern` documentation with a brief explanation of the new requirement. It also adds the missing `unsafe` keyword to the code sample, which should be compatible with rustc since v1.82. **Related docs:** - https://doc.rust-lang.org/reference/items/external-blocks.html - https://doc.rust-lang.org/edition-guide/rust-2024/unsafe-extern.html
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#139865 (Stabilize proc_macro::Span::{start,end,line,column}.) - rust-lang#140086 (If creating a temporary directory fails with permission denied then retry with backoff) - rust-lang#140216 (Document that "extern blocks must be unsafe" in Rust 2024) - rust-lang#140220 (Fix detection of main function if there are expressions around it) - rust-lang#140253 (Add XtensaAsmPrinter) - rust-lang#140272 (Improve error message for `||` (or) in let chains) - rust-lang#140305 (Track per-obligation recursion depth only if there is inference in the new solver) - rust-lang#140306 (handle specialization in the new trait solver) - rust-lang#140308 (stall generator witness obligations: add regression test) r? `@ghost` `@rustbot` modify labels: rollup
Document that "extern blocks must be unsafe" in Rust 2024 The [documentation on `extern`](https://doc.rust-lang.org/std/keyword.extern.html) contains the following code sample: ```rust #[link(name = "my_c_library")] extern "C" { fn my_c_function(x: i32) -> bool; } ``` Due to rust-lang#123743, attempting to compile such code with the 2024 edition of Rust fails: ``` error: extern blocks must be unsafe ``` This PR extends the `extern` documentation with a brief explanation of the new requirement. It also adds the missing `unsafe` keyword to the code sample, which should be compatible with rustc since v1.82. **Related docs:** - https://doc.rust-lang.org/reference/items/external-blocks.html - https://doc.rust-lang.org/edition-guide/rust-2024/unsafe-extern.html
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#139865 (Stabilize proc_macro::Span::{start,end,line,column}.) - rust-lang#140086 (If creating a temporary directory fails with permission denied then retry with backoff) - rust-lang#140216 (Document that "extern blocks must be unsafe" in Rust 2024) - rust-lang#140253 (Add XtensaAsmPrinter) - rust-lang#140272 (Improve error message for `||` (or) in let chains) - rust-lang#140305 (Track per-obligation recursion depth only if there is inference in the new solver) - rust-lang#140306 (handle specialization in the new trait solver) - rust-lang#140308 (stall generator witness obligations: add regression test) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#140216 - t5kd:master, r=tgross35 Document that "extern blocks must be unsafe" in Rust 2024 The [documentation on `extern`](https://doc.rust-lang.org/std/keyword.extern.html) contains the following code sample: ```rust #[link(name = "my_c_library")] extern "C" { fn my_c_function(x: i32) -> bool; } ``` Due to rust-lang#123743, attempting to compile such code with the 2024 edition of Rust fails: ``` error: extern blocks must be unsafe ``` This PR extends the `extern` documentation with a brief explanation of the new requirement. It also adds the missing `unsafe` keyword to the code sample, which should be compatible with rustc since v1.82. **Related docs:** - https://doc.rust-lang.org/reference/items/external-blocks.html - https://doc.rust-lang.org/edition-guide/rust-2024/unsafe-extern.html
The documentation on
extern
contains the following code sample:Due to #123743, attempting to compile such code with the 2024 edition of Rust fails:
This PR extends the
extern
documentation with a brief explanation of the new requirement. It also adds the missingunsafe
keyword to the code sample, which should be compatible with rustc since v1.82.Related docs: