Support Result<T, E> across FFI when niche optimization can be used (v2) by dtolnay · Pull Request #124747 · rust-lang/rust

added 9 commits

April 23, 2024 21:15
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.
Fields are disallowed so checking the top attribute is enough.
Tests both `T` and `E` for niche variant optimization lints
Couldn't find documentation supporting that single-variant
`#[repr(Rust)]` enums with RHS assigned work as expected with this
change.

```rust
enum Variants {
  A = 17,
} // Would this be zero sized optimized guaranteed?
```

@rustbot rustbot added S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

T-compiler

Relevant to the compiler team, which will review and decide on the PR/issue.

labels

May 5, 2024

@bors bors added S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

and removed S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

labels

May 5, 2024

fmease added a commit to fmease/rust that referenced this pull request

May 5, 2024

bors added a commit to rust-lang-ci/rust that referenced this pull request

May 5, 2024
Rollup of 6 pull requests

Successful merges:

 - rust-lang#124146 (Triagebot: Rename `macos` ping group to `apple`)
 - rust-lang#124742 (Add `rustfmt` cfg to well known cfgs list)
 - rust-lang#124745 (Implement lldb formattter for "clang encoded" enums (LLDB 18.1+) (v2))
 - rust-lang#124747 (Support Result<T, E> across FFI when niche optimization can be used (v2))
 - rust-lang#124765 ([rustdoc] Fix bad color for setting cog in ayu theme)
 - rust-lang#124768 ([resubmission] Meta: Enable the brand new triagebot transfer command)

r? `@ghost`
`@rustbot` modify labels: rollup

fmease added a commit to fmease/rust that referenced this pull request

May 5, 2024

bors added a commit to rust-lang-ci/rust that referenced this pull request

May 6, 2024
Rollup of 5 pull requests

Successful merges:

 - rust-lang#124742 (Add `rustfmt` cfg to well known cfgs list)
 - rust-lang#124747 (Support Result<T, E> across FFI when niche optimization can be used (v2))
 - rust-lang#124753 (Migrate `run-make/rustdoc-error-lines` to new `rmake.rs`)
 - rust-lang#124765 ([rustdoc] Fix bad color for setting cog in ayu theme)
 - rust-lang#124768 ([resubmission] Meta: Enable the brand new triagebot transfer command)

r? `@ghost`
`@rustbot` modify labels: rollup

@dtolnay dtolnay removed the S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

label

Jan 14, 2025

@dtolnay dtolnay added the A-FFI

Area: Foreign function interface (FFI)

label

Jan 14, 2025