You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: text/0000-unsafe-extern-blocks.md
+10-7Lines changed: 10 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,19 +23,22 @@ The up-side to this change is that in the new style it will be possible to decla
23
23
Rust can utilize functions and statics from foreign code that are provided during linking, though it is `unsafe` to do so.
24
24
25
25
An `extern` block can be placed anywhere a function declaration could appear (generally at the top level of a module).
26
-
* You can always write `unsafe extern { ... }`.
27
-
*If the `unsafe_code` lint is denied or forbidden at a particular scope it will cause the `unsafe extern` block to be a compilation error within that scope.
28
-
* On editions >= 2024, you must write all `extern`blocks as `unsafeextern`.
29
-
*On editions < 2024, it is allowed to write an `extern`block *without* the `unsafe` keyword, but this generates a compatibility warning that you should use the `unsafe` keyword.
26
+
27
+
*On editions >= 2024, you *must* write all `extern` blocks as `unsafe extern`.
28
+
* On editions < 2024, you *may* write `unsafe extern`, or you can write an `extern`block without the `unsafe` keyword. Writing an `extern` block without the `unsafe` keyword is provided for compatibility only, and will generate a warning.
29
+
*`unsafe extern`interacts with the `unsafe_code` lint, and a `deny` or `forbid` with that lint will deny or forbid the unsafe external block.
30
30
31
31
Within an `extern` block is zero or more declarations of external functions and/or external static values.
32
32
An extern function is declared with a `;` instead of a function body (similar to a method of a trait).
33
33
An extern static value is also declared with a `;` instead of an expression (similar to an associated const of a trait).
34
34
In both cases, the actual function body or value is provided by whatever external source (which is probably not even written in Rust).
35
35
36
-
When an `extern` block is used (with or without `unsafe` in front of it), all declarations within that `extern` block should have the `unsafe` or `safe` keywords as part of their signature.
37
-
If one of the two keywords is not explicitly provided, the declaration is assumed to be `unsafe`.
38
-
The `safe` keyword is a contextual keyword, only used within `extern` blocks.
36
+
When an `unsafe extern` block is used, all declarations within that `extern` block *should* have the `unsafe` or `safe` keywords as part of their signature.
37
+
If one of the two keywords is not explicitly provided, the declaration is assumed to be `unsafe`, and also a warning is generated.
38
+
The `safe` keyword is a contextual keyword, it is currently only used within `extern` blocks.
39
+
40
+
If an `extern` block is used in an older edition without the `unsafe` keyword, declarations *cannot* specify `safe` or `unsafe`.
41
+
Code must update to `unsafe extern` style blocks if it wants to make `safe` declarations.
0 commit comments