Skip to content

Commit 2713fef

Browse files
petrochenkovbrson
authored andcommitted
Stabilize unions with Copy fields and no destructor
1 parent 0308c98 commit 2713fef

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
@@ -64,7 +64,6 @@
6464
#![feature(trusted_len)]
6565
#![feature(unicode)]
6666
#![feature(unique)]
67-
#![feature(untagged_unions)]
6867
#![cfg_attr(not(test), feature(str_checked_slicing))]
6968
#![cfg_attr(test, feature(rand, test))]
7069
#![feature(offset_to)]

src/librustc/middle/stability.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,27 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
590590
}
591591
}
592592

593+
// There's no good place to insert stability check for non-Copy unions,
594+
// so semi-randomly perform it here in stability.rs
595+
hir::ItemUnion(..) if !self.tcx.sess.features.borrow().untagged_unions => {
596+
let def_id = self.tcx.hir.local_def_id(item.id);
597+
let adt_def = self.tcx.adt_def(def_id);
598+
let ty = self.tcx.type_of(def_id);
599+
600+
if adt_def.has_dtor(self.tcx) {
601+
emit_feature_err(&self.tcx.sess.parse_sess,
602+
"untagged_unions", item.span, GateIssue::Language,
603+
"unions with `Drop` implementations are unstable");
604+
} else {
605+
let param_env = self.tcx.param_env(def_id);
606+
if !param_env.can_type_implement_copy(self.tcx, ty, item.span).is_ok() {
607+
emit_feature_err(&self.tcx.sess.parse_sess,
608+
"untagged_unions", item.span, GateIssue::Language,
609+
"unions with non-`Copy` fields are unstable");
610+
}
611+
}
612+
}
613+
593614
_ => (/* pass */)
594615
}
595616
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
@@ -32,7 +32,6 @@
3232
#![feature(staged_api)]
3333
#![feature(unboxed_closures)]
3434
#![feature(fn_traits)]
35-
#![feature(untagged_unions)]
3635
#![feature(associated_consts)]
3736
#![feature(unsize)]
3837
#![feature(i128_type)]

src/libsyntax/feature_gate.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,12 +1202,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
12021202
}
12031203
}
12041204

1205-
ast::ItemKind::Union(..) => {
1206-
gate_feature_post!(&self, untagged_unions,
1207-
i.span,
1208-
"unions are unstable and possibly buggy");
1209-
}
1210-
12111205
ast::ItemKind::DefaultImpl(..) => {
12121206
gate_feature_post!(&self, optin_builtin_traits,
12131207
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)