forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#122253 - MasterAwesome:master, r=davidtwco
Support Result<T, E> across FFI when niche optimization can be used Allow allow enums like `Result<T, E>` to be used across FFI if the T/E can be niche optimized and the non-niche-optimized type is FFI safe. Implementation of rust-lang/rfcs#3391 Tracking issue: rust-lang#110503 Additional ABI and codegen tests were added in rust-lang#115372
- Loading branch information
Showing
8 changed files
with
826 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/doc/unstable-book/src/language-features/result-ffi-guarantees.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# `result_ffi_guarantees` | ||
|
||
The tracking issue for this feature is: [#110503] | ||
|
||
[#110503]: https://github.com/rust-lang/rust/issues/110503 | ||
|
||
------------------------ | ||
|
||
This feature adds the possibility of using `Result<T, E>` in FFI if T's niche | ||
value can be used to describe E or vise-versa. | ||
|
||
See [RFC 3391] for more information. | ||
|
||
[RFC 3391]: https://github.com/rust-lang/rfcs/blob/master/text/3391-result_ffi_guarantees.md |
99 changes: 99 additions & 0 deletions
99
tests/ui/feature-gates/feature-gate-result_ffi_guarantees.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#![allow(dead_code)] | ||
#![deny(improper_ctypes)] | ||
#![feature(ptr_internals)] | ||
|
||
use std::num; | ||
|
||
enum Z {} | ||
|
||
#[repr(transparent)] | ||
struct TransparentStruct<T>(T, std::marker::PhantomData<Z>); | ||
|
||
#[repr(transparent)] | ||
enum TransparentEnum<T> { | ||
Variant(T, std::marker::PhantomData<Z>), | ||
} | ||
|
||
struct NoField; | ||
|
||
extern "C" { | ||
fn result_ref_t(x: Result<&'static u8, ()>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_fn_t(x: Result<extern "C" fn(), ()>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_nonnull_t(x: Result<std::ptr::NonNull<u8>, ()>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_unique_t(x: Result<std::ptr::Unique<u8>, ()>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_nonzero_u8_t(x: Result<num::NonZero<u8>, ()>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_nonzero_u16_t(x: Result<num::NonZero<u16>, ()>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_nonzero_u32_t(x: Result<num::NonZero<u32>, ()>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_nonzero_u64_t(x: Result<num::NonZero<u64>, ()>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_nonzero_usize_t(x: Result<num::NonZero<usize>, ()>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_nonzero_i8_t(x: Result<num::NonZero<i8>, ()>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_nonzero_i16_t(x: Result<num::NonZero<i16>, ()>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_nonzero_i32_t(x: Result<num::NonZero<i32>, ()>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_nonzero_i64_t(x: Result<num::NonZero<i64>, ()>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_nonzero_isize_t(x: Result<num::NonZero<isize>, ()>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_transparent_struct_t(x: Result<TransparentStruct<num::NonZero<u8>>, ()>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_transparent_enum_t(x: Result<TransparentEnum<num::NonZero<u8>>, ()>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_phantom_t(x: Result<num::NonZero<u8>, std::marker::PhantomData<()>>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_1zst_exhaustive_no_variant_t(x: Result<num::NonZero<u8>, Z>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_1zst_exhaustive_no_field_t(x: Result<num::NonZero<u8>, NoField>); | ||
//~^ ERROR `extern` block uses type `Result | ||
|
||
fn result_ref_e(x: Result<(), &'static u8>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_fn_e(x: Result<(), extern "C" fn()>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_nonnull_e(x: Result<(), std::ptr::NonNull<u8>>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_unique_e(x: Result<(), std::ptr::Unique<u8>>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_nonzero_u8_e(x: Result<(), num::NonZero<u8>>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_nonzero_u16_e(x: Result<(), num::NonZero<u16>>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_nonzero_u32_e(x: Result<(), num::NonZero<u32>>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_nonzero_u64_e(x: Result<(), num::NonZero<u64>>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_nonzero_usize_e(x: Result<(), num::NonZero<usize>>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_nonzero_i8_e(x: Result<(), num::NonZero<i8>>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_nonzero_i16_e(x: Result<(), num::NonZero<i16>>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_nonzero_i32_e(x: Result<(), num::NonZero<i32>>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_nonzero_i64_e(x: Result<(), num::NonZero<i64>>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_nonzero_isize_e(x: Result<(), num::NonZero<isize>>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_transparent_struct_e(x: Result<(), TransparentStruct<num::NonZero<u8>>>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_transparent_enum_e(x: Result<(), TransparentEnum<num::NonZero<u8>>>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_phantom_e(x: Result<num::NonZero<u8>, std::marker::PhantomData<()>>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_1zst_exhaustive_no_variant_e(x: Result<Z, num::NonZero<u8>>); | ||
//~^ ERROR `extern` block uses type `Result | ||
fn result_1zst_exhaustive_no_field_e(x: Result<NoField, num::NonZero<u8>>); | ||
//~^ ERROR `extern` block uses type `Result | ||
} | ||
|
||
pub fn main() {} |
Oops, something went wrong.