From 8ce3484fcf49624094dee0dc807577335bca74b9 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Wed, 14 Aug 2019 19:47:03 +0200 Subject: [PATCH 01/15] Correct errors in the reference of extern functions definitions --- src/items/functions.md | 64 +++++++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 14 deletions(-) diff --git a/src/items/functions.md b/src/items/functions.md index bae5b8eff..6f068ebf6 100644 --- a/src/items/functions.md +++ b/src/items/functions.md @@ -109,34 +109,70 @@ sufficient context to determine the type parameters. For example, ## Extern functions -Extern functions are part of Rust's foreign function interface, providing the -opposite functionality to [external blocks]. Whereas external -blocks allow Rust code to call foreign code, extern functions with bodies -defined in Rust code _can be called by foreign code_. They are defined in the -same way as any other Rust function, except that they have the `extern` -qualifier. +Extern function _definitions_ allow defining functions that can be called +with a particular ABI: + +```rust,norun +extern "ABI" fn foo() { ... } +``` + +An extern function _declaration_ via an [external block] can be used to +provide an item for these functions that can be called by Rust code without +providing their definition. + +The default ABI of Rust functions like `fn foo() {}` is `"Rust"`. While we +abbreviate the type of Rust functions like `foo` as `fn()`, this is actually a +synonym for `extern "Rust" fn()`. That is, this: ```rust -// Declares an extern fn, the ABI defaults to "C" -extern fn new_i32() -> i32 { 0 } +fn foo() {} +``` + +is identical to + +```rust +extern "Rust" fn foo() {} +``` -// Declares an extern fn with "stdcall" ABI +Functions in Rust can be called by foreign code, and using an ABI that +differs from Rust allows, for example, to provide functions that can be +called from other programming languages like C: + +```rust +// Declares a function with the "C" ABI +extern "C" fn new_i32() -> i32 { 0 } + +// Declares a function with the "stdcall" ABI # #[cfg(target_arch = "x86_64")] extern "stdcall" fn new_i32_stdcall() -> i32 { 0 } ``` -Unlike normal functions, extern fns have type `extern "ABI" fn()`. This is the -same type as the functions declared in an extern block. +Just as with [external block], when the `extern` keyword is used and the `"ABI` +is omitted, the ABI used defaults to `"C"`. That is, this + +```rust +extern fn new_i32() -> i32 { 0 } +let fptr: extern fn() -> i32 = new_i32; +``` + +is identical to ```rust -# extern fn new_i32() -> i32 { 0 } +extern "C" fn new_i32() -> i32 { 0 } let fptr: extern "C" fn() -> i32 = new_i32; ``` -As non-Rust calling conventions do not support unwinding, unwinding past the end -of an extern function will cause the process to abort. In LLVM, this is +Since functions with an ABI that differs from `"Rust"` do not support +unwinding in the exact same way that Rust does, unwinding past the end +of functions with such ABIs causes the process to abort. In LLVM, this is implemented by executing an illegal instruction. +Some ABIs that are identical to `"Rust"` are: + +* `"rust-call"` +* `"platform-intrinsic"` +* `"rust-intrinsic"` + ## Const functions Functions qualified with the `const` keyword are const functions. _Const From a3b91c098441baa1e842774c58cded9ca077486a Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 15 Aug 2019 03:42:52 +0200 Subject: [PATCH 02/15] Incorporate initial feedback from Centril and Ehuss Co-Authored-By: Mazdak Farrokhzad --- src/items/functions.md | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/items/functions.md b/src/items/functions.md index 6f068ebf6..96bc74a30 100644 --- a/src/items/functions.md +++ b/src/items/functions.md @@ -112,7 +112,7 @@ sufficient context to determine the type parameters. For example, Extern function _definitions_ allow defining functions that can be called with a particular ABI: -```rust,norun +```rust,no_run extern "ABI" fn foo() { ... } ``` @@ -120,15 +120,14 @@ An extern function _declaration_ via an [external block] can be used to provide an item for these functions that can be called by Rust code without providing their definition. -The default ABI of Rust functions like `fn foo() {}` is `"Rust"`. While we -abbreviate the type of Rust functions like `foo` as `fn()`, this is actually a -synonym for `extern "Rust" fn()`. That is, this: +When `"extern" Abi?*` is omitted from `FunctionQualifiers`, the ABI `"Rust"` is +assigned. For example: ```rust fn foo() {} ``` -is identical to +is equivalent to: ```rust extern "Rust" fn foo() {} @@ -148,30 +147,34 @@ extern "stdcall" fn new_i32_stdcall() -> i32 { 0 } ``` Just as with [external block], when the `extern` keyword is used and the `"ABI` -is omitted, the ABI used defaults to `"C"`. That is, this +is omitted, the ABI used defaults to `"C"`. That is, this: ```rust extern fn new_i32() -> i32 { 0 } let fptr: extern fn() -> i32 = new_i32; ``` -is identical to +is equivalent to: ```rust extern "C" fn new_i32() -> i32 { 0 } let fptr: extern "C" fn() -> i32 = new_i32; ``` -Since functions with an ABI that differs from `"Rust"` do not support -unwinding in the exact same way that Rust does, unwinding past the end -of functions with such ABIs causes the process to abort. In LLVM, this is -implemented by executing an illegal instruction. +Functions with an ABI that differs from `"Rust"` do not support unwinding in the +exact same way that Rust does. Therefore, unwinding past the end of functions +with such ABIs causes the process to abort. -Some ABIs that are identical to `"Rust"` are: +**Non-normative note**: The LLVM backend of the current Rust implementation +aborts the process by executing an illegal instruction. -* `"rust-call"` -* `"platform-intrinsic"` -* `"rust-intrinsic"` +**Non-normative note**: There are other ABIs available in unstable Rust that are +equivalent to the `"Rust"` ABI, e.g., +[`"rust-intrinsic"`](https://doc.rust-lang.org/unstable-book/language-features/intrinsics.html?highlight=rust-intrin#intrinsics) +or +[`"platform-intrinsic"`](https://doc.rust-lang.org/unstable-book/language-features/platform-intrinsics.html). +Refer to the [Unstable Book](https://doc.rust-lang.org/unstable-book) for more +information about these. ## Const functions From ea9d02ed175eb410b0edf87642113e1d73ff44bc Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 15 Aug 2019 04:08:36 +0200 Subject: [PATCH 03/15] Fix test and update external-block ABIs --- src/items/external-blocks.md | 10 +++++----- src/items/functions.md | 7 ++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/items/external-blocks.md b/src/items/external-blocks.md index 9c69ad0ed..55bc8c100 100644 --- a/src/items/external-blocks.md +++ b/src/items/external-blocks.md @@ -85,12 +85,12 @@ There are also some platform-specific ABI strings: * `extern "vectorcall"` -- The `vectorcall` ABI -- corresponds to MSVC's `__vectorcall` and clang's `__attribute__((vectorcall))` -Finally, there are some rustc-specific ABI strings: +Finally, there are some unstable rustc-specific ABI strings: -* `extern "rust-intrinsic"` -- The ABI of rustc intrinsics. -* `extern "rust-call"` -- The ABI of the Fn::call trait functions. -* `extern "platform-intrinsic"` -- Specific platform intrinsics -- like, for - example, `sqrt` -- have this ABI. You should never have to deal with it. +* `extern "rust-intrinsic"` -- The ABI of rustc intrinsics, equivalent to `"Rust"`. +* `extern "rust-call"` -- The ABI of the Fn::call trait functions, equivalent to `"Rust"`. +* `extern "platform-intrinsic"` -- The ABI of Specific platform intrinsics, equivalent to `"Rust"` -- like, for + example, `sqrt` -- equivalent to `"Rust"`. You should never have to deal with it. ## Variadic functions diff --git a/src/items/functions.md b/src/items/functions.md index 96bc74a30..66884f273 100644 --- a/src/items/functions.md +++ b/src/items/functions.md @@ -112,7 +112,7 @@ sufficient context to determine the type parameters. For example, Extern function _definitions_ allow defining functions that can be called with a particular ABI: -```rust,no_run +```rust,ignore extern "ABI" fn foo() { ... } ``` @@ -173,8 +173,9 @@ equivalent to the `"Rust"` ABI, e.g., [`"rust-intrinsic"`](https://doc.rust-lang.org/unstable-book/language-features/intrinsics.html?highlight=rust-intrin#intrinsics) or [`"platform-intrinsic"`](https://doc.rust-lang.org/unstable-book/language-features/platform-intrinsics.html). -Refer to the [Unstable Book](https://doc.rust-lang.org/unstable-book) for more -information about these. +For more information about these refer to the [ABI section of external block +items][external-blocks.md#ABI] and the [Unstable +Book](https://doc.rust-lang.org/unstable-book). ## Const functions From 5aac8794f17e0001fd6d4029add0a3fc07961676 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 15 Aug 2019 04:25:19 +0200 Subject: [PATCH 04/15] Try to be more clear about definitions and declarations --- src/items/functions.md | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/items/functions.md b/src/items/functions.md index 66884f273..2c3778be1 100644 --- a/src/items/functions.md +++ b/src/items/functions.md @@ -107,21 +107,28 @@ component after the function name. This might be necessary if there is not sufficient context to determine the type parameters. For example, `mem::size_of::() == 4`. -## Extern functions +## Extern function qualifier -Extern function _definitions_ allow defining functions that can be called -with a particular ABI: +The `extern` function qualifier allows providing function _definitions_ that can +be called with a particular ABI: ```rust,ignore extern "ABI" fn foo() { ... } ``` -An extern function _declaration_ via an [external block] can be used to -provide an item for these functions that can be called by Rust code without -providing their definition. +These are often used in combination with [external block] items which provide +function _declarations_ that can be used to call functions without providing +their _definition_: -When `"extern" Abi?*` is omitted from `FunctionQualifiers`, the ABI `"Rust"` is -assigned. For example: +```rust,ignore +extern "ABI" { + fn foo(); /* no body */ +} +unsafe { foo() } +``` + +When `"extern" Abi?*` is omitted from `FunctionQualifiers` in function items, +the ABI `"Rust"` is assigned. For example: ```rust fn foo() {} From 7ebfe255288d22b74c8e4d999b5d723e584aed03 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 15 Aug 2019 04:25:48 +0200 Subject: [PATCH 05/15] External blocks can be used to call Rust functions --- src/items/external-blocks.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/items/external-blocks.md b/src/items/external-blocks.md index 55bc8c100..53feb9d63 100644 --- a/src/items/external-blocks.md +++ b/src/items/external-blocks.md @@ -30,8 +30,7 @@ >    ( _NamedFunctionParam_ `,` )\* _NamedFunctionParam_ `,` `...` External blocks form the basis for Rust's foreign function interface. -Declarations in an external block describe symbols in external, non-Rust -libraries. +Declarations in an external block describe symbols in external libraries. Functions within external blocks are declared in the same way as other Rust functions, with the exception that they may not have a body and are instead From 3d0237b361156c2b8e19ab7d5cfbe3dcadf73246 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 15 Aug 2019 04:45:41 +0200 Subject: [PATCH 06/15] Extend external block section with statics --- src/items/external-blocks.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/items/external-blocks.md b/src/items/external-blocks.md index 53feb9d63..4a60964c0 100644 --- a/src/items/external-blocks.md +++ b/src/items/external-blocks.md @@ -29,8 +29,12 @@ > _NamedFunctionParametersWithVariadics_ :\ >    ( _NamedFunctionParam_ `,` )\* _NamedFunctionParam_ `,` `...` -External blocks form the basis for Rust's foreign function interface. -Declarations in an external block describe symbols in external libraries. +External blocks provide _declarations_ of items that are not _defined_ in the +current crate and are the basis of Rust's foreign function interface. Using +items declared in external blocks is `unsafe`. + +Two kind of item _declarations_ are allowed in external blocks: +[functions](function.md) and [statics](static-items.md). Functions within external blocks are declared in the same way as other Rust functions, with the exception that they may not have a body and are instead @@ -47,6 +51,8 @@ extern "abi" for<'l1, ..., 'lm> fn(A1, ..., An) -> R`, where `'l1`, ... `'lm` are its lifetime parameters, `A1`, ..., `An` are the declared types of its parameters and `R` is the declared return type. +Statics within external blocks are declared in the same way as other Rust statics, +with the exception that they may not have an expression initializing their value. It is `unsafe` to access a static item declared in an extern block, whether or not it's mutable. From 1f023ccc22b4fc3bbe4b64e03e53be911889416d Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 15 Aug 2019 04:51:05 +0200 Subject: [PATCH 07/15] Tidy links --- src/abi.md | 2 +- src/items/external-blocks.md | 4 +++- src/items/functions.md | 15 ++++++++------- src/types/function-pointer.md | 2 +- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/abi.md b/src/abi.md index f244ead5d..2e9e969ac 100644 --- a/src/abi.md +++ b/src/abi.md @@ -88,7 +88,7 @@ pub fn name_in_rust() { } [_MetaNameValueStr_]: attributes.md#meta-item-attribute-syntax [`static` items]: items/static-items.md [attribute]: attributes.md -[extern functions]: items/functions.md#extern-functions +[extern functions]: items/functions.md#extern-function-qualifier [external blocks]: items/external-blocks.md [function]: items/functions.md [item]: items.md diff --git a/src/items/external-blocks.md b/src/items/external-blocks.md index 4a60964c0..1b7cb0cf0 100644 --- a/src/items/external-blocks.md +++ b/src/items/external-blocks.md @@ -34,7 +34,7 @@ current crate and are the basis of Rust's foreign function interface. Using items declared in external blocks is `unsafe`. Two kind of item _declarations_ are allowed in external blocks: -[functions](function.md) and [statics](static-items.md). +[functions] and [statics]. Functions within external blocks are declared in the same way as other Rust functions, with the exception that they may not have a body and are instead @@ -170,6 +170,8 @@ extern { [IDENTIFIER]: ../identifiers.md [WebAssembly module]: https://webassembly.github.io/spec/core/syntax/modules.html +[functions]: functions.md +[statics]: static-items.md [_Abi_]: functions.md [_FunctionReturnType_]: functions.md [_Generics_]: generics.md diff --git a/src/items/functions.md b/src/items/functions.md index 2c3778be1..8cf1d4e4e 100644 --- a/src/items/functions.md +++ b/src/items/functions.md @@ -176,13 +176,10 @@ with such ABIs causes the process to abort. aborts the process by executing an illegal instruction. **Non-normative note**: There are other ABIs available in unstable Rust that are -equivalent to the `"Rust"` ABI, e.g., -[`"rust-intrinsic"`](https://doc.rust-lang.org/unstable-book/language-features/intrinsics.html?highlight=rust-intrin#intrinsics) -or -[`"platform-intrinsic"`](https://doc.rust-lang.org/unstable-book/language-features/platform-intrinsics.html). -For more information about these refer to the [ABI section of external block -items][external-blocks.md#ABI] and the [Unstable -Book](https://doc.rust-lang.org/unstable-book). +equivalent to the `"Rust"` ABI, e.g., [`"rust-intrinsic"`][rust_intrinsic] or +[`"platform-intrinsic"`][platform_intrinsic]. For more information about these +refer to the [ABI section of external block items][external_block_abi] and the +[Unstable Book]. ## Const functions @@ -290,3 +287,7 @@ attributes macros. [`export_name`]: ../abi.md#the-export_name-attribute [`link_section`]: ../abi.md#the-link_section-attribute [`no_mangle`]: ../abi.md#the-no_mangle-attribute +[external_block_abi]: external-blocks.md#abi +[Unstable Book]: https://doc.rust-lang.org/unstable-book +[rust_intrinsic]: https://doc.rust-lang.org/unstable-book/language-features/intrinsics.html?highlight=rust-intrin#intrinsics +[platform_intrinsic]: https://doc.rust-lang.org/unstable-book/language-features/platform-intrinsics.html diff --git a/src/types/function-pointer.md b/src/types/function-pointer.md index 44da3ccbd..88ef50c24 100644 --- a/src/types/function-pointer.md +++ b/src/types/function-pointer.md @@ -51,6 +51,6 @@ x = bo(5,7); [_Type_]: ../types.md#type-expressions [`extern`]: ../items/external-blocks.md [closures]: closure.md -[extern function]: ../items/functions.md#extern-functions +[extern function]: ../items/functions.md#extern-function-qualifier [function items]: function-item.md [unsafe function]: ../unsafe-functions.md From ace3935c91b52e1181fb892fc2cf82edf336e963 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 15 Aug 2019 08:50:39 +0200 Subject: [PATCH 08/15] Remove mentions of unstable ABIs --- src/items/external-blocks.md | 7 ------- src/items/functions.md | 6 ------ 2 files changed, 13 deletions(-) diff --git a/src/items/external-blocks.md b/src/items/external-blocks.md index 1b7cb0cf0..35654843d 100644 --- a/src/items/external-blocks.md +++ b/src/items/external-blocks.md @@ -90,13 +90,6 @@ There are also some platform-specific ABI strings: * `extern "vectorcall"` -- The `vectorcall` ABI -- corresponds to MSVC's `__vectorcall` and clang's `__attribute__((vectorcall))` -Finally, there are some unstable rustc-specific ABI strings: - -* `extern "rust-intrinsic"` -- The ABI of rustc intrinsics, equivalent to `"Rust"`. -* `extern "rust-call"` -- The ABI of the Fn::call trait functions, equivalent to `"Rust"`. -* `extern "platform-intrinsic"` -- The ABI of Specific platform intrinsics, equivalent to `"Rust"` -- like, for - example, `sqrt` -- equivalent to `"Rust"`. You should never have to deal with it. - ## Variadic functions Functions within external blocks may be variadic by specifying `...` after one diff --git a/src/items/functions.md b/src/items/functions.md index 8cf1d4e4e..d450711fc 100644 --- a/src/items/functions.md +++ b/src/items/functions.md @@ -175,12 +175,6 @@ with such ABIs causes the process to abort. **Non-normative note**: The LLVM backend of the current Rust implementation aborts the process by executing an illegal instruction. -**Non-normative note**: There are other ABIs available in unstable Rust that are -equivalent to the `"Rust"` ABI, e.g., [`"rust-intrinsic"`][rust_intrinsic] or -[`"platform-intrinsic"`][platform_intrinsic]. For more information about these -refer to the [ABI section of external block items][external_block_abi] and the -[Unstable Book]. - ## Const functions Functions qualified with the `const` keyword are const functions. _Const From 30407d26ee3e54a2600437b65effaf1cda0ad373 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 15 Aug 2019 08:44:08 +0200 Subject: [PATCH 09/15] Update src/items/external-blocks.md Co-Authored-By: Mazdak Farrokhzad --- src/items/external-blocks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/items/external-blocks.md b/src/items/external-blocks.md index 35654843d..05cb1d5ef 100644 --- a/src/items/external-blocks.md +++ b/src/items/external-blocks.md @@ -31,7 +31,7 @@ External blocks provide _declarations_ of items that are not _defined_ in the current crate and are the basis of Rust's foreign function interface. Using -items declared in external blocks is `unsafe`. +items declared in external blocks is only allowed in an `unsafe` context. Two kind of item _declarations_ are allowed in external blocks: [functions] and [statics]. From 8cee694e573bc6b9314a1f03dbd3cd2816b283f0 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 15 Aug 2019 08:45:23 +0200 Subject: [PATCH 10/15] Update src/items/functions.md Co-Authored-By: Mazdak Farrokhzad --- src/items/functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/items/functions.md b/src/items/functions.md index d450711fc..6c2c09e56 100644 --- a/src/items/functions.md +++ b/src/items/functions.md @@ -172,7 +172,7 @@ Functions with an ABI that differs from `"Rust"` do not support unwinding in the exact same way that Rust does. Therefore, unwinding past the end of functions with such ABIs causes the process to abort. -**Non-normative note**: The LLVM backend of the current Rust implementation +> **Note**: The LLVM backend of the `rustc` implementation aborts the process by executing an illegal instruction. ## Const functions From bca3f6c8756ce4827b33a3a37791cdceabff518d Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 15 Aug 2019 11:08:25 +0200 Subject: [PATCH 11/15] Clarify usage of extern declarations from unsafe contex --- src/items/external-blocks.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/items/external-blocks.md b/src/items/external-blocks.md index 05cb1d5ef..8a3e54624 100644 --- a/src/items/external-blocks.md +++ b/src/items/external-blocks.md @@ -30,11 +30,12 @@ >    ( _NamedFunctionParam_ `,` )\* _NamedFunctionParam_ `,` `...` External blocks provide _declarations_ of items that are not _defined_ in the -current crate and are the basis of Rust's foreign function interface. Using -items declared in external blocks is only allowed in an `unsafe` context. +current crate and are the basis of Rust's foreign function interface. These are +sort of like unchecked imports. -Two kind of item _declarations_ are allowed in external blocks: -[functions] and [statics]. +Two kind of item _declarations_ are allowed in external blocks: [functions] and +[statics]. Calling functions or accessing statics that are declared in external +blocks is only allowed in an `unsafe` context. Functions within external blocks are declared in the same way as other Rust functions, with the exception that they may not have a body and are instead From dc93dc456fa0958009090d41e77364e3b50598ad Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 15 Aug 2019 11:19:11 +0200 Subject: [PATCH 12/15] Garbage-collect links --- src/items/functions.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/items/functions.md b/src/items/functions.md index 6c2c09e56..7c93dc423 100644 --- a/src/items/functions.md +++ b/src/items/functions.md @@ -282,6 +282,3 @@ attributes macros. [`link_section`]: ../abi.md#the-link_section-attribute [`no_mangle`]: ../abi.md#the-no_mangle-attribute [external_block_abi]: external-blocks.md#abi -[Unstable Book]: https://doc.rust-lang.org/unstable-book -[rust_intrinsic]: https://doc.rust-lang.org/unstable-book/language-features/intrinsics.html?highlight=rust-intrin#intrinsics -[platform_intrinsic]: https://doc.rust-lang.org/unstable-book/language-features/platform-intrinsics.html From 9c93133f7a39eefe0dcc4f2a7220872d421a481d Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Fri, 16 Aug 2019 14:46:22 +0200 Subject: [PATCH 13/15] Update src/items/external-blocks.md Co-Authored-By: Ryan Scheel --- src/items/external-blocks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/items/external-blocks.md b/src/items/external-blocks.md index 8a3e54624..e822b0b8f 100644 --- a/src/items/external-blocks.md +++ b/src/items/external-blocks.md @@ -52,7 +52,7 @@ extern "abi" for<'l1, ..., 'lm> fn(A1, ..., An) -> R`, where `'l1`, ... `'lm` are its lifetime parameters, `A1`, ..., `An` are the declared types of its parameters and `R` is the declared return type. -Statics within external blocks are declared in the same way as other Rust statics, +Statics within external blocks are declared in the same way as statics outside of external blocks, with the exception that they may not have an expression initializing their value. It is `unsafe` to access a static item declared in an extern block, whether or not it's mutable. From 27e30febb8f7d4ab85b2e400985f56d74b343b2f Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Fri, 16 Aug 2019 14:46:34 +0200 Subject: [PATCH 14/15] Update src/items/external-blocks.md Co-Authored-By: Ryan Scheel --- src/items/external-blocks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/items/external-blocks.md b/src/items/external-blocks.md index e822b0b8f..eae89c3d7 100644 --- a/src/items/external-blocks.md +++ b/src/items/external-blocks.md @@ -53,7 +53,7 @@ are its lifetime parameters, `A1`, ..., `An` are the declared types of its parameters and `R` is the declared return type. Statics within external blocks are declared in the same way as statics outside of external blocks, -with the exception that they may not have an expression initializing their value. +except that they do not have an expression initializing their value. It is `unsafe` to access a static item declared in an extern block, whether or not it's mutable. From c4ef0ee76b9a08ee71e08d8cc1904e05ddb6899e Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 22 Aug 2019 16:28:37 +0200 Subject: [PATCH 15/15] Update src/items/external-blocks.md Co-Authored-By: Mazdak Farrokhzad --- src/items/external-blocks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/items/external-blocks.md b/src/items/external-blocks.md index eae89c3d7..f3e692ac9 100644 --- a/src/items/external-blocks.md +++ b/src/items/external-blocks.md @@ -31,7 +31,7 @@ External blocks provide _declarations_ of items that are not _defined_ in the current crate and are the basis of Rust's foreign function interface. These are -sort of like unchecked imports. +akin to unchecked imports. Two kind of item _declarations_ are allowed in external blocks: [functions] and [statics]. Calling functions or accessing statics that are declared in external