Skip to content

Commit

Permalink
Specify #[repr(transparent)]
Browse files Browse the repository at this point in the history
  • Loading branch information
nox committed Sep 26, 2016
1 parent 1f5d3a9 commit 4056178
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions text/0000-repr-transparent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
- Feature Name: `repr_transparent`
- Start Date: 2016-09-26
- RFC PR: (leave this empty)
- Rust Issue: (leave this empty)

# Summary
[summary]: #summary

Extend the existing `#[repr]` attribute on newtypes with a `transparent` option
specifying that the type representation is the representation of its only field.

# Motivation
[motivation]: #motivation

On some ABIs, structures with one field aren't handled the same way as values of
the same type as the single field. For example on ARM64, functions returning
a structure with a single `f64` field return nothing and take a pointer to be
filled with the return value, whereas functions returning a `f64` return the
floating-point number directly.

# Detailed design
[design]: #detailed-design

The `#[repr]` attribute on newtypess will be extended to include a form such as:

```rust
#[repr(transparent)]
struct TransparentNewtype(f64);
```

This structure will still have the same representation as a raw `f64` value.

Syntactically, the `repr` meta list will be extended to accept a meta item
with the name "transparent". This attribute can be placed only on newtypes,
which means structures (and structure tuples) with a single field.

Some examples of `#[repr(transparent)]` are:

```rust
// Transparent struct tuple.
#[repr(transparent)]
struct TransparentStructTuple(i32);

// Transparent structure.
#[repr(transparent)]
struct TransparentStructure { only_field: f64 }
```

# Drawbacks
[drawbacks]: #drawbacks

None.

# Alternatives
[alternatives]: #alternatives

None.

# Unresolved questions
[unresolved]: #unresolved-questions

None.

0 comments on commit 4056178

Please sign in to comment.