File tree 4 files changed +18
-3
lines changed
4 files changed +18
-3
lines changed Original file line number Diff line number Diff line change 2
2
3
3
> ** <sup >Syntax</sup >** \
4
4
> _ ExternBlock_ :\
5
- >   ;  ; ` unsafe ` <sup >?</sup > ` extern ` [ _ Abi_ ] <sup >?</sup > ` { ` \
5
+ >   ;  ; ` unsafe ` <sup >?</sup >[ ^ unsafe-2024 ] ` extern ` [ _ Abi_ ] <sup >?</sup > ` { ` \
6
6
>   ;  ;   ;  ; [ _ InnerAttribute_ ] <sup >\* </sup >\
7
7
>   ;  ;   ;  ; _ ExternalItem_ <sup >\* </sup >\
8
8
>   ;  ; ` } `
12
12
>   ;  ;   ;  ;   ;  ; [ _ MacroInvocationSemi_ ] \
13
13
>   ;  ;   ;  ; | ( [ _ Visibility_ ] <sup >?</sup > ( [ _ StaticItem_ ] | [ _ Function_ ] ) )\
14
14
>   ;  ; )
15
+ >
16
+ > [ ^ unsafe-2024 ] : Starting with the 2024 Edition, the ` unsafe ` keyword is required semantically.
15
17
16
18
External blocks provide _ declarations_ of items that are not _ defined_ in the
17
19
current crate and are the basis of Rust's foreign function interface. These are
@@ -23,6 +25,11 @@ blocks is only allowed in an `unsafe` context.
23
25
24
26
The external block defines its functions and statics in the [ value namespace] of the module or block where it is located.
25
27
28
+ ** Edition differences** : Starting in the 2024 edition, the ` unsafe ` keyword is
29
+ required to appear before the ` extern ` keyword on external blocks. In previous
30
+ editions, it is accepted but not required. The ` safe ` and ` unsafe ` item qualifiers
31
+ are only allowed if the external block itself is marked as ` unsafe ` .
32
+
26
33
## Functions
27
34
28
35
Functions within external blocks are declared in the same way as other Rust
Original file line number Diff line number Diff line change 8
8
>   ;  ;   ;  ; ( [ _ BlockExpression_ ] | ` ; ` )
9
9
>
10
10
> _ FunctionQualifiers_ :\
11
- >   ;  ; ` const ` <sup >?</sup > ` async ` [ ^ async-edition ] <sup >?</sup > _ ItemSafety_ <sup >?</sup > (` extern ` _ Abi_ <sup >?</sup >)<sup >?</sup >
11
+ >   ;  ; ` const ` <sup >?</sup > ` async ` [ ^ async-edition ] <sup >?</sup > _ ItemSafety_ <sup >?</sup >[ ^ extern-qualifiers ] (` extern ` _ Abi_ <sup >?</sup >)<sup >?</sup >
12
12
>
13
13
> _ ItemSafety_ :\
14
14
>   ;  ; ` safe ` [ ^ extern-safe ] | ` unsafe `
45
45
> [ ^ extern-safe ] : The ` safe ` function qualifier is only allowed semantically within
46
46
> ` extern ` blocks.
47
47
>
48
+ > [ ^ extern-qualifiers ] : * Relevant to editions earlier than Rust 2024* : Within
49
+ > ` extern ` blocks, the ` safe ` or ` unsafe ` function qualifier is only allowed
50
+ > when the ` extern ` is qualified as ` unsafe ` .
51
+ >
48
52
> [ ^ fn-param-2015 ] : Function parameters with only a type are only allowed
49
53
> in an associated function of a [ trait item] in the 2015 edition.
50
54
Original file line number Diff line number Diff line change @@ -61,6 +61,8 @@ Unsafe trait implementations are the logical dual to unsafe traits: where unsafe
61
61
62
62
The programmer who declares an [ external block] must assure that the signatures of the items contained within are correct. Failing to do so may lead to undefined behavior. That this obligation has been met is indicated by writing ` unsafe extern ` .
63
63
64
+ ** Edition differences** : Prior to edition 2024, ` extern ` blocks were allowed without being qualified as ` unsafe ` .
65
+
64
66
[ external block ] : items/external-blocks.md
65
67
66
68
## Unsafe attributes (` #[unsafe(attr)] ` )
Original file line number Diff line number Diff line change 11
11
- Accessing a field of a [ ` union ` ] , other than to assign to it.
12
12
- Calling an unsafe function (including an intrinsic or foreign function).
13
13
- Implementing an [ unsafe trait] .
14
- - Declaring an [ ` extern ` ] block.
14
+ - Declaring an [ ` extern ` ] block[ ^ extern-2024 ] .
15
15
- Applying an [ unsafe attribute] to an item.
16
16
17
+ [ ^ extern-2024 ] : Prior to the 2024 edition, extern blocks were allowed to be declared without ` unsafe ` .
18
+
17
19
[ `extern` ] : items/external-blocks.md
18
20
[ `union` ] : items/unions.md
19
21
[ mutable ] : items/static-items.md#mutable-statics
You can’t perform that action at this time.
0 commit comments