Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize #[repr(transparent)] on enums in Rust 1.42.0 #68122

Merged
merged 2 commits into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 0 additions & 93 deletions src/doc/unstable-book/src/language-features/transparent-enums.md

This file was deleted.

2 changes: 2 additions & 0 deletions src/librustc_feature/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ declare_features! (
/// Allows relaxing the coherence rules such that
/// `impl<T> ForeignTrait<LocalType> for ForeignType<T>` is permitted.
(accepted, re_rebalance_coherence, "1.41.0", Some(55437), None),
/// Allows #[repr(transparent)] on univariant enums (RFC 2645).
(accepted, transparent_enums, "1.42.0", Some(60405), None),
/// Allows using subslice patterns, `[a, .., b]` and `[a, xs @ .., b]`.
(accepted, slice_patterns, "1.42.0", Some(62254), None),

Expand Down
3 changes: 0 additions & 3 deletions src/librustc_feature/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,6 @@ declare_features! (
/// Allows `if/while p && let q = r && ...` chains.
(active, let_chains, "1.37.0", Some(53667), None),

/// Allows #[repr(transparent)] on enums (RFC 2645).
(active, transparent_enums, "1.37.0", Some(60405), None),

/// Allows #[repr(transparent)] on unions (RFC 2645).
(active, transparent_unions, "1.37.0", Some(60405), None),

Expand Down
10 changes: 0 additions & 10 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2433,16 +2433,6 @@ fn check_transparent(tcx: TyCtxt<'_>, sp: Span, def_id: DefId) {
}
let sp = tcx.sess.source_map().def_span(sp);

if adt.is_enum() && !tcx.features().transparent_enums {
feature_err(
&tcx.sess.parse_sess,
sym::transparent_enums,
sp,
"transparent enums are unstable",
)
.emit();
}

if adt.is_union() && !tcx.features().transparent_unions {
feature_err(
&tcx.sess.parse_sess,
Expand Down
2 changes: 1 addition & 1 deletion src/test/codegen/repr-transparent-aggregates-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// ignore-windows
// See repr-transparent.rs

#![feature(transparent_enums, transparent_unions)]
#![feature(transparent_unions)]

#![crate_type="lib"]

Expand Down
2 changes: 1 addition & 1 deletion src/test/codegen/repr-transparent-aggregates-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// ignore-x86_64
// See repr-transparent.rs

#![feature(transparent_enums, transparent_unions)]
#![feature(transparent_unions)]

#![crate_type="lib"]

Expand Down
2 changes: 1 addition & 1 deletion src/test/codegen/repr-transparent-aggregates-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// only-mips64
// See repr-transparent.rs

#![feature(transparent_enums, transparent_unions)]
#![feature(transparent_unions)]

#![crate_type="lib"]

Expand Down
2 changes: 1 addition & 1 deletion src/test/codegen/repr-transparent.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// compile-flags: -C no-prepopulate-passes

#![crate_type="lib"]
#![feature(repr_simd, transparent_enums, transparent_unions)]
#![feature(repr_simd, transparent_unions)]

use std::marker::PhantomData;

Expand Down
6 changes: 0 additions & 6 deletions src/test/ui/feature-gates/feature-gate-transparent_enums.rs

This file was deleted.

12 changes: 0 additions & 12 deletions src/test/ui/feature-gates/feature-gate-transparent_enums.stderr

This file was deleted.

2 changes: 1 addition & 1 deletion src/test/ui/lint/lint-ctypes-enum.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(transparent_enums, transparent_unions)]
#![feature(transparent_unions)]
#![feature(ptr_internals)]
#![deny(improper_ctypes)]
#![allow(dead_code)]
Expand Down
12 changes: 11 additions & 1 deletion src/test/ui/repr/repr-transparent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// - repr-transparent-other-reprs.rs
// - repr-transparent-other-items.rs

#![feature(repr_align, transparent_enums, transparent_unions)]
#![feature(transparent_unions)]

use std::marker::PhantomData;

Expand Down Expand Up @@ -60,6 +60,16 @@ enum TooManyVariants { //~ ERROR transparent enum needs exactly one variant, but
Bar,
}

#[repr(transparent)]
enum NontrivialAlignZstEnum {
Foo(u32, [u16; 0]), //~ ERROR alignment larger than 1
}

#[repr(transparent)]
enum GenericAlignEnum<T> {
Foo { bar: ZstAlign32<T>, baz: u32 } //~ ERROR alignment larger than 1
}

#[repr(transparent)]
union UnitUnion { //~ ERROR transparent union needs exactly one non-zero-sized field, but has 0
u: (),
Expand Down
18 changes: 15 additions & 3 deletions src/test/ui/repr/repr-transparent.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,26 @@ LL | Foo(String),
LL | Bar,
| --- too many variants in `TooManyVariants`

error[E0691]: zero-sized field in transparent enum has alignment larger than 1
--> $DIR/repr-transparent.rs:65:14
|
LL | Foo(u32, [u16; 0]),
| ^^^^^^^^ has alignment larger than 1

error[E0691]: zero-sized field in transparent enum has alignment larger than 1
--> $DIR/repr-transparent.rs:70:11
|
LL | Foo { bar: ZstAlign32<T>, baz: u32 }
| ^^^^^^^^^^^^^^^^^^ has alignment larger than 1

error[E0690]: transparent union needs exactly one non-zero-sized field, but has 0
--> $DIR/repr-transparent.rs:64:1
--> $DIR/repr-transparent.rs:74:1
|
LL | union UnitUnion {
| ^^^^^^^^^^^^^^^ needs exactly one non-zero-sized field, but has 0

error[E0690]: transparent union needs exactly one non-zero-sized field, but has 2
--> $DIR/repr-transparent.rs:69:1
--> $DIR/repr-transparent.rs:79:1
|
LL | union TooManyFields {
| ^^^^^^^^^^^^^^^^^^^ needs exactly one non-zero-sized field, but has 2
Expand All @@ -110,7 +122,7 @@ LL | u: u32,
LL | s: i32
| ------ this field is non-zero-sized

error: aborting due to 15 previous errors
error: aborting due to 17 previous errors

Some errors have detailed explanations: E0084, E0690, E0691, E0731.
For more information about an error, try `rustc --explain E0084`.