]> git.lizzy.rs Git - rust.git/commitdiff
Stabilize unions with `Copy` fields and no destructor
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Wed, 17 May 2017 21:22:52 +0000 (00:22 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Fri, 26 May 2017 21:52:20 +0000 (00:52 +0300)
32 files changed:
src/libcollections/lib.rs
src/librustc/middle/stability.rs
src/librustc_data_structures/lib.rs
src/libsyntax/feature_gate.rs
src/test/compile-fail/borrowck/borrowck-union-borrow-nested.rs
src/test/compile-fail/borrowck/borrowck-union-borrow.rs
src/test/compile-fail/borrowck/borrowck-union-uninitialized.rs
src/test/compile-fail/privacy/union-field-privacy-1.rs
src/test/compile-fail/privacy/union-field-privacy-2.rs
src/test/compile-fail/union/union-const-eval.rs
src/test/compile-fail/union/union-const-pat.rs
src/test/compile-fail/union/union-derive.rs
src/test/compile-fail/union/union-empty.rs
src/test/compile-fail/union/union-feature-gate.rs
src/test/compile-fail/union/union-fields.rs
src/test/compile-fail/union/union-generic.rs
src/test/compile-fail/union/union-lint-dead-code.rs
src/test/compile-fail/union/union-repr-c.rs
src/test/compile-fail/union/union-suggest-field.rs
src/test/debuginfo/union-smoke.rs
src/test/run-pass/union/auxiliary/union.rs
src/test/run-pass/union/union-backcomp.rs
src/test/run-pass/union/union-basic.rs
src/test/run-pass/union/union-c-interop.rs
src/test/run-pass/union/union-const-trans.rs
src/test/run-pass/union/union-inherent-method.rs
src/test/run-pass/union/union-macro.rs
src/test/run-pass/union/union-pat-refutability.rs
src/test/run-pass/union/union-trait-impl.rs
src/test/run-pass/union/union-transmute.rs
src/test/rustdoc/union.rs
src/test/ui/print_type_sizes/packed.rs

index 842f2f44fff9e8166652695f93e50fdfdf96ca9c..72ff6575ca13725bc230059c04b0a6645119ae9e 100644 (file)
@@ -65,7 +65,6 @@
 #![feature(trusted_len)]
 #![feature(unicode)]
 #![feature(unique)]
-#![feature(untagged_unions)]
 #![cfg_attr(not(test), feature(str_checked_slicing))]
 #![cfg_attr(test, feature(rand, test))]
 #![feature(offset_to)]
index d74877e355a7946c0d1bed885a397e2ce9b68908..e27990c29cf9ea370a2eea5cb1ad1a7fcb41d826 100644 (file)
@@ -625,6 +625,27 @@ fn visit_item(&mut self, item: &'tcx hir::Item) {
                 }
             }
 
+            // There's no good place to insert stability check for non-Copy unions,
+            // so semi-randomly perform it here in stability.rs
+            hir::ItemUnion(..) if !self.tcx.sess.features.borrow().untagged_unions => {
+                let def_id = self.tcx.hir.local_def_id(item.id);
+                let adt_def = self.tcx.adt_def(def_id);
+                let ty = self.tcx.type_of(def_id);
+
+                if adt_def.has_dtor(self.tcx) {
+                    emit_feature_err(&self.tcx.sess.parse_sess,
+                                     "untagged_unions", item.span, GateIssue::Language,
+                                     "unions with `Drop` implementations are unstable");
+                } else {
+                    let param_env = self.tcx.param_env(def_id);
+                    if !param_env.can_type_implement_copy(self.tcx, ty, item.span).is_ok() {
+                        emit_feature_err(&self.tcx.sess.parse_sess,
+                                        "untagged_unions", item.span, GateIssue::Language,
+                                        "unions with non-`Copy` fields are unstable");
+                    }
+                }
+            }
+
             _ => (/* pass */)
         }
         intravisit::walk_item(self, item);
index c254dfc48d22549da834a03de2cbb999e479bb53..83cd5cef00cfec147211d52a8eef8dc1a3cda0a2 100644 (file)
@@ -29,7 +29,6 @@
 #![feature(nonzero)]
 #![feature(unboxed_closures)]
 #![feature(fn_traits)]
-#![feature(untagged_unions)]
 #![feature(associated_consts)]
 #![feature(unsize)]
 #![feature(i128_type)]
index ca579409be430d62e0e26a70380f925348b22b2d..c119fad1b736e599d7d1a969df5a9356000d529b 100644 (file)
@@ -1207,12 +1207,6 @@ fn visit_item(&mut self, i: &'a ast::Item) {
                 }
             }
 
-            ast::ItemKind::Union(..) => {
-                gate_feature_post!(&self, untagged_unions,
-                                   i.span,
-                                   "unions are unstable and possibly buggy");
-            }
-
             ast::ItemKind::DefaultImpl(..) => {
                 gate_feature_post!(&self, optin_builtin_traits,
                                    i.span,
index 8b6b8d9ecb08ed08c098bf2f2284a569a4df238a..6298c87453ca6cdf66a242a175772a8c33367cb8 100644 (file)
@@ -8,10 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// ignore-tidy-linelength
-
-#![feature(untagged_unions)]
-
 #[derive(Clone, Copy)]
 struct S {
     a: u8,
index ecc698acc317f7f09b7223757a83b74a87f5f433..20b882e1f807c82dc24b78b5f9e0534cac176f61 100644 (file)
@@ -10,8 +10,6 @@
 
 // ignore-tidy-linelength
 
-#![feature(untagged_unions)]
-
 #[derive(Clone, Copy)]
 union U {
     a: u8,
index 36e062f8464e9962a0024a5555ac0b468f2496ec..81376a1a169d49ad2aea6e68ac097764844dc909 100644 (file)
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(untagged_unions)]
-
 struct S {
     a: u8,
 }
index 807be619f6c5f6ee71bfac6ffe4076ea7198d3b3..eeebb1b737a943cefe3c16c37abc35daa178e07e 100644 (file)
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(untagged_unions)]
-
 mod m {
     pub union U {
         pub a: u8,
index e26b5e99ec1a5f62167df2846561ebeec0b7c43d..d6bb765202da53a3732b543d00b6dbb5cc356438 100644 (file)
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(untagged_unions)]
-
 mod m {
     pub union U {
         pub a: u8,
index b2bf173c59c8667dd1363d5f036a6374b8cf2f26..ee4d9fe99eeb80c6c24aa9a3148bbffec0c3494f 100644 (file)
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(untagged_unions)]
-
 union U {
     a: usize,
     b: usize,
index 3d168980ed246b957bb7804ecca23989f555d6d7..5f75e3cc4a2d60fd8ba7d4bbe40d8e39950d6cfa 100644 (file)
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(untagged_unions)]
-
 union U {
     a: usize,
     b: usize,
index 26dbdfd0b411847a26b1855813b7119a1568d0fa..ffd290fb073db18c67a41b580e585cbe00c5016b 100644 (file)
@@ -10,8 +10,6 @@
 
 // Most traits cannot be derived for unions.
 
-#![feature(untagged_unions)]
-
 #[derive(
     PartialEq, //~ ERROR this trait cannot be derived for unions
     PartialOrd, //~ ERROR this trait cannot be derived for unions
index ce5bbf60fee2547eeb9a6ccdfca8e4f2d9efb3be..1f499c49a6870b3b94f67420a689478b59424610 100644 (file)
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(untagged_unions)]
-
 union U {} //~ ERROR unions cannot have zero fields
 
 fn main() {}
index 0c2165871f6dbfcf8e45829ff0e82cada3e43640..8a0490cdc6b6dd7b6519972652a6cf37f44d0990 100644 (file)
 
 // gate-test-untagged_unions
 
-union U { //~ ERROR unions are unstable and possibly buggy
+union U1 { // OK
     a: u8,
 }
 
+union U2<T: Copy> { // OK
+    a: T,
+}
+
+union U3 { //~ ERROR unions with non-`Copy` fields are unstable
+    a: String,
+}
+
+union U4<T> { //~ ERROR unions with non-`Copy` fields are unstable
+    a: T,
+}
+
+union U5 { //~ ERROR unions with `Drop` implementations are unstable
+    a: u8,
+}
+
+impl Drop for U5 {
+    fn drop(&mut self) {}
+}
+
 fn main() {}
index 3ee95c2ef4258b2e7834d506646da569f5f5292e..b5d582a5746f729d6bed5d74d2987ae8a6a608c1 100644 (file)
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(untagged_unions)]
-
 union U {
     a: u8,
     b: u16,
index e6586b0fb7f6adeb00e24b75b6c789210bda2d3a..8bd422b42d879d65438ad90c01f92ee233d579de 100644 (file)
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(untagged_unions)]
-
 use std::rc::Rc;
 
 union U<T: Copy> {
index 7a552c8f8b76a0a45734eb683580cb9afc7f7a93..a64187c5f2344d3de2cc0fe98d056c1bf3d25bd2 100644 (file)
@@ -8,7 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(untagged_unions)]
 #![deny(dead_code)]
 
 union Foo {
index d7dfb126c93248d70d10c25c72f70956683cf664..15a4197fe94c97804f74a5d764cf9a7ce013db5e 100644 (file)
@@ -8,7 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(untagged_unions)]
 #![allow(unused)]
 #![deny(improper_ctypes)]
 
index 3c355989b82f09127301e7f264b7ac10778f9430..65c7c980b8ac25fccb7edf1656fffaf8a6c15675 100644 (file)
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(untagged_unions)]
-
 union U {
     principal: u8,
 }
index 0b2544151fd323b0d6a6c38d4ce1ac43d2fba107..433196b526c5cfadc4ab3bdd0fb05873846f84ee 100644 (file)
@@ -34,7 +34,6 @@
 #![allow(unused)]
 #![feature(omit_gdb_pretty_printer_section)]
 #![omit_gdb_pretty_printer_section]
-#![feature(untagged_unions)]
 
 union U {
     a: (u8, u8),
index 0231e38a729b731827cf3e3f5d03ac7d3bb54cc6..2c4945622abdce2d3dec7fefe7e40b7abd354bcc 100644 (file)
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(untagged_unions)]
-
 pub union U {
     pub a: u8,
     pub b: u16,
index 0f8c996bebda8bec170b9709a6ab0f6b711d6c82..b706a81850ce8e89fa0017a279f374980af21945 100644 (file)
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(untagged_unions)]
-
 macro_rules! union {
     () => (struct S;)
 }
index dc14c12b6a22e778aef7caf90fdcabf8b85fae68..5e5b2d4d7ce7b111fac70eae0c7fb03c1243ff9b 100644 (file)
@@ -13,8 +13,6 @@
 // FIXME: This test case makes little-endian assumptions.
 // ignore-s390x
 
-#![feature(untagged_unions)]
-
 extern crate union;
 use std::mem::{size_of, align_of, zeroed};
 
index 13dfd414615c5db642239597ea8adac9a6e40408..b3df7d658b15f34ef7d8c5b81bf3cbc07651535e 100644 (file)
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(untagged_unions)]
-
 #[derive(Clone, Copy)]
 #[repr(C)]
 struct LARGE_INTEGER_U {
index bdae1a0eaf88f8accb505083de6303e4ff31abb3..77270364bb5e969ff480721a7409dd6ec0915c4d 100644 (file)
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(untagged_unions)]
-
 union U {
     a: u64,
     b: u64,
index adea27bd25462a58a737b5dfaef42a92fe61080a..a88fdc57a3ef40eaceb83a1da3c7c930b78eaead 100644 (file)
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(untagged_unions)]
-
 union U {
     a: u8,
 }
index a23fbc3be9e2c8be22c0d715c774da7269311570..b6141ae82c37139d3700569cb3fac5d7ac6ab4eb 100644 (file)
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(untagged_unions)]
-
 macro_rules! duplicate {
    ($i: item) => {
         mod m1 {
index e6144f35f1d549056d4da1f98579fa6004ff1146..81607236c9ecd295fd45e722d301fd57ae310977 100644 (file)
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(untagged_unions)]
-
 #[repr(u32)]
 enum Tag { I, F }
 
index a5a2be0133abaf55e13fef61a7086371d2403e46..1cdaff2cab7c8c7e25efe55464f7744d03fdf8d3 100644 (file)
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(untagged_unions)]
-
 use std::fmt;
 
 union U {
index 7a0b4c6aaca4922b62eddf73c0ab65a0096b2fca..7233687aaab532677de571dfdd7b7eab10b485b5 100644 (file)
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(untagged_unions)]
-
 extern crate core;
 use core::f32;
 
index 0dcc9098ad75cbe54c87fe7fa6bbd7d9ced64cd2..2eb25d9b7ddac34228f0689ea8ecf038d048121b 100644 (file)
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(untagged_unions)]
-
 // @has union/union.U.html
 pub union U {
     // @has - //pre "pub a: u8"
index cd7ef86d70ee3f4892fb0c66181af1c09eb7f367..7f278e71b21c6118a3e8e524aa492dac622c3018 100644 (file)
@@ -18,8 +18,6 @@
 // aligned (while on most it is 8-byte aligned) and so the resulting
 // padding and overall computed sizes can be quite different.
 
-#![feature(untagged_unions)]
-
 #![allow(dead_code)]
 
 #[derive(Default)]