Skip to content

Commit 73c73e4

Browse files
committed
Stabilize unions with Copy fields and no destructor
1 parent 5579677 commit 73c73e4

32 files changed

+42
-62
lines changed

src/libcollections/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
#![feature(trusted_len)]
6666
#![feature(unicode)]
6767
#![feature(unique)]
68-
#![feature(untagged_unions)]
6968
#![cfg_attr(not(test), feature(str_checked_slicing))]
7069
#![cfg_attr(test, feature(rand, test))]
7170
#![feature(offset_to)]

src/librustc/middle/stability.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,27 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
625625
}
626626
}
627627

628+
// There's no good place to insert stability check for non-Copy unions,
629+
// so semi-randomly perform it here in stability.rs
630+
hir::ItemUnion(..) if !self.tcx.sess.features.borrow().untagged_unions => {
631+
let def_id = self.tcx.hir.local_def_id(item.id);
632+
let adt_def = self.tcx.adt_def(def_id);
633+
let ty = self.tcx.type_of(def_id);
634+
635+
if adt_def.has_dtor(self.tcx) {
636+
emit_feature_err(&self.tcx.sess.parse_sess,
637+
"untagged_unions", item.span, GateIssue::Language,
638+
"unions with `Drop` implementations are unstable");
639+
} else {
640+
let param_env = self.tcx.param_env(def_id);
641+
if !param_env.can_type_implement_copy(self.tcx, ty, item.span).is_ok() {
642+
emit_feature_err(&self.tcx.sess.parse_sess,
643+
"untagged_unions", item.span, GateIssue::Language,
644+
"unions with non-`Copy` fields are unstable");
645+
}
646+
}
647+
}
648+
628649
_ => (/* pass */)
629650
}
630651
intravisit::walk_item(self, item);

src/librustc_data_structures/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#![feature(nonzero)]
3030
#![feature(unboxed_closures)]
3131
#![feature(fn_traits)]
32-
#![feature(untagged_unions)]
3332
#![feature(associated_consts)]
3433
#![feature(unsize)]
3534
#![feature(i128_type)]

src/libsyntax/feature_gate.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,12 +1207,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
12071207
}
12081208
}
12091209

1210-
ast::ItemKind::Union(..) => {
1211-
gate_feature_post!(&self, untagged_unions,
1212-
i.span,
1213-
"unions are unstable and possibly buggy");
1214-
}
1215-
12161210
ast::ItemKind::DefaultImpl(..) => {
12171211
gate_feature_post!(&self, optin_builtin_traits,
12181212
i.span,

src/test/compile-fail/borrowck/borrowck-union-borrow-nested.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// ignore-tidy-linelength
12-
13-
#![feature(untagged_unions)]
14-
1511
#[derive(Clone, Copy)]
1612
struct S {
1713
a: u8,

src/test/compile-fail/borrowck/borrowck-union-borrow.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
// ignore-tidy-linelength
1212

13-
#![feature(untagged_unions)]
14-
1513
#[derive(Clone, Copy)]
1614
union U {
1715
a: u8,

src/test/compile-fail/borrowck/borrowck-union-uninitialized.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(untagged_unions)]
12-
1311
struct S {
1412
a: u8,
1513
}

src/test/compile-fail/privacy/union-field-privacy-1.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(untagged_unions)]
12-
1311
mod m {
1412
pub union U {
1513
pub a: u8,

src/test/compile-fail/privacy/union-field-privacy-2.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(untagged_unions)]
12-
1311
mod m {
1412
pub union U {
1513
pub a: u8,

src/test/compile-fail/union/union-const-eval.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(untagged_unions)]
12-
1311
union U {
1412
a: usize,
1513
b: usize,

0 commit comments

Comments
 (0)