File tree Expand file tree Collapse file tree 4 files changed +18
-3
lines changed Expand file tree Collapse file tree 4 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ r[items.extern]
5
5
r[ items.extern.syntax]
6
6
> ** <sup >Syntax</sup >** \
7
7
> _ ExternBlock_ :\
8
- >   ;  ; ` unsafe ` <sup >?</sup > ` extern ` [ _ Abi_ ] <sup >?</sup > ` { ` \
8
+ >   ;  ; ` unsafe ` <sup >?</sup >[ ^ unsafe-2024 ] ` extern ` [ _ Abi_ ] <sup >?</sup > ` { ` \
9
9
>   ;  ;   ;  ; [ _ InnerAttribute_ ] <sup >\* </sup >\
10
10
>   ;  ;   ;  ; _ ExternalItem_ <sup >\* </sup >\
11
11
>   ;  ; ` } `
@@ -15,6 +15,8 @@ r[items.extern.syntax]
15
15
>   ;  ;   ;  ;   ;  ; [ _ MacroInvocationSemi_ ] \
16
16
>   ;  ;   ;  ; | ( [ _ Visibility_ ] <sup >?</sup > ( [ _ StaticItem_ ] | [ _ Function_ ] ) )\
17
17
>   ;  ; )
18
+ >
19
+ > [ ^ unsafe-2024 ] : Starting with the 2024 Edition, the ` unsafe ` keyword is required semantically.
18
20
19
21
r[ items.extern.intro]
20
22
External blocks provide _ declarations_ of items that are not _ defined_ in the
@@ -31,6 +33,11 @@ Calling functions or accessing statics that are declared in external blocks is o
31
33
r[ items.extern.namespace]
32
34
The external block defines its functions and statics in the [ value namespace] of the module or block where it is located.
33
35
36
+ ** Edition differences** : Starting in the 2024 edition, the ` unsafe ` keyword is
37
+ required to appear before the ` extern ` keyword on external blocks. In previous
38
+ editions, it is accepted but not required. The ` safe ` and ` unsafe ` item qualifiers
39
+ are only allowed if the external block itself is marked as ` unsafe ` .
40
+
34
41
## Functions
35
42
36
43
r[ items.extern.fn]
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ r[items.fn.syntax]
11
11
>   ;  ;   ;  ; ( [ _ BlockExpression_ ] | ` ; ` )
12
12
>
13
13
> _ FunctionQualifiers_ :\
14
- >   ;  ; ` const ` <sup >?</sup > ` async ` [ ^ async-edition ] <sup >?</sup > _ ItemSafety_ <sup >?</sup > (` extern ` _ Abi_ <sup >?</sup >)<sup >?</sup >
14
+ >   ;  ; ` const ` <sup >?</sup > ` async ` [ ^ async-edition ] <sup >?</sup > _ ItemSafety_ <sup >?</sup >[ ^ extern-qualifiers ] (` extern ` _ Abi_ <sup >?</sup >)<sup >?</sup >
15
15
>
16
16
> _ ItemSafety_ :\
17
17
>   ;  ; ` safe ` [ ^ extern-safe ] | ` unsafe `
@@ -48,6 +48,10 @@ r[items.fn.syntax]
48
48
> [ ^ extern-safe ] : The ` safe ` function qualifier is only allowed semantically within
49
49
> ` extern ` blocks.
50
50
>
51
+ > [ ^ extern-qualifiers ] : * Relevant to editions earlier than Rust 2024* : Within
52
+ > ` extern ` blocks, the ` safe ` or ` unsafe ` function qualifier is only allowed
53
+ > when the ` extern ` is qualified as ` unsafe ` .
54
+ >
51
55
> [ ^ fn-param-2015 ] : Function parameters with only a type are only allowed
52
56
> in an associated function of a [ trait item] in the 2015 edition.
53
57
Original file line number Diff line number Diff line change @@ -81,6 +81,8 @@ r[unsafe.extern]
81
81
82
82
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 ` .
83
83
84
+ ** Edition differences** : Prior to edition 2024, ` extern ` blocks were allowed without being qualified as ` unsafe ` .
85
+
84
86
[ external block ] : items/external-blocks.md
85
87
86
88
## Unsafe attributes (` #[unsafe(attr)] ` )
Original file line number Diff line number Diff line change @@ -26,11 +26,13 @@ r[safety.unsafe-impl]
26
26
- Implementing an [ unsafe trait] .
27
27
28
28
r[ safety.unsafe-extern]
29
- - Declaring an [ ` extern ` ] block.
29
+ - Declaring an [ ` extern ` ] block[ ^ extern-2024 ] .
30
30
31
31
r[ safety.unsafe-attribute]
32
32
- Applying an [ unsafe attribute] to an item.
33
33
34
+ [ ^ extern-2024 ] : Prior to the 2024 edition, extern blocks were allowed to be declared without ` unsafe ` .
35
+
34
36
[ `extern` ] : items/external-blocks.md
35
37
[ `union` ] : items/unions.md
36
38
[ mutable ] : items/static-items.md#mutable-statics
You can’t perform that action at this time.
0 commit comments