Stabilize unions with `Copy` fields and no destructor

This commit is contained in:
Vadim Petrochenkov 2017-05-18 00:22:52 +03:00
parent 557967766b
commit 73c73e4a95
32 changed files with 42 additions and 62 deletions

View File

@ -65,7 +65,6 @@
#![feature(trusted_len)] #![feature(trusted_len)]
#![feature(unicode)] #![feature(unicode)]
#![feature(unique)] #![feature(unique)]
#![feature(untagged_unions)]
#![cfg_attr(not(test), feature(str_checked_slicing))] #![cfg_attr(not(test), feature(str_checked_slicing))]
#![cfg_attr(test, feature(rand, test))] #![cfg_attr(test, feature(rand, test))]
#![feature(offset_to)] #![feature(offset_to)]

View File

@ -625,6 +625,27 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
} }
} }
// 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 */) _ => (/* pass */)
} }
intravisit::walk_item(self, item); intravisit::walk_item(self, item);

View File

@ -29,7 +29,6 @@
#![feature(nonzero)] #![feature(nonzero)]
#![feature(unboxed_closures)] #![feature(unboxed_closures)]
#![feature(fn_traits)] #![feature(fn_traits)]
#![feature(untagged_unions)]
#![feature(associated_consts)] #![feature(associated_consts)]
#![feature(unsize)] #![feature(unsize)]
#![feature(i128_type)] #![feature(i128_type)]

View File

@ -1207,12 +1207,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
} }
} }
ast::ItemKind::Union(..) => {
gate_feature_post!(&self, untagged_unions,
i.span,
"unions are unstable and possibly buggy");
}
ast::ItemKind::DefaultImpl(..) => { ast::ItemKind::DefaultImpl(..) => {
gate_feature_post!(&self, optin_builtin_traits, gate_feature_post!(&self, optin_builtin_traits,
i.span, i.span,

View File

@ -8,10 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
// ignore-tidy-linelength
#![feature(untagged_unions)]
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
struct S { struct S {
a: u8, a: u8,

View File

@ -10,8 +10,6 @@
// ignore-tidy-linelength // ignore-tidy-linelength
#![feature(untagged_unions)]
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
union U { union U {
a: u8, a: u8,

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(untagged_unions)]
struct S { struct S {
a: u8, a: u8,
} }

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(untagged_unions)]
mod m { mod m {
pub union U { pub union U {
pub a: u8, pub a: u8,

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(untagged_unions)]
mod m { mod m {
pub union U { pub union U {
pub a: u8, pub a: u8,

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(untagged_unions)]
union U { union U {
a: usize, a: usize,
b: usize, b: usize,

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(untagged_unions)]
union U { union U {
a: usize, a: usize,
b: usize, b: usize,

View File

@ -10,8 +10,6 @@
// Most traits cannot be derived for unions. // Most traits cannot be derived for unions.
#![feature(untagged_unions)]
#[derive( #[derive(
PartialEq, //~ ERROR this trait cannot be derived for unions PartialEq, //~ ERROR this trait cannot be derived for unions
PartialOrd, //~ ERROR this trait cannot be derived for unions PartialOrd, //~ ERROR this trait cannot be derived for unions

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(untagged_unions)]
union U {} //~ ERROR unions cannot have zero fields union U {} //~ ERROR unions cannot have zero fields
fn main() {} fn main() {}

View File

@ -10,8 +10,28 @@
// gate-test-untagged_unions // gate-test-untagged_unions
union U { //~ ERROR unions are unstable and possibly buggy union U1 { // OK
a: u8, 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() {} fn main() {}

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(untagged_unions)]
union U { union U {
a: u8, a: u8,
b: u16, b: u16,

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(untagged_unions)]
use std::rc::Rc; use std::rc::Rc;
union U<T: Copy> { union U<T: Copy> {

View File

@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(untagged_unions)]
#![deny(dead_code)] #![deny(dead_code)]
union Foo { union Foo {

View File

@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(untagged_unions)]
#![allow(unused)] #![allow(unused)]
#![deny(improper_ctypes)] #![deny(improper_ctypes)]

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(untagged_unions)]
union U { union U {
principal: u8, principal: u8,
} }

View File

@ -34,7 +34,6 @@
#![allow(unused)] #![allow(unused)]
#![feature(omit_gdb_pretty_printer_section)] #![feature(omit_gdb_pretty_printer_section)]
#![omit_gdb_pretty_printer_section] #![omit_gdb_pretty_printer_section]
#![feature(untagged_unions)]
union U { union U {
a: (u8, u8), a: (u8, u8),

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(untagged_unions)]
pub union U { pub union U {
pub a: u8, pub a: u8,
pub b: u16, pub b: u16,

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(untagged_unions)]
macro_rules! union { macro_rules! union {
() => (struct S;) () => (struct S;)
} }

View File

@ -13,8 +13,6 @@
// FIXME: This test case makes little-endian assumptions. // FIXME: This test case makes little-endian assumptions.
// ignore-s390x // ignore-s390x
#![feature(untagged_unions)]
extern crate union; extern crate union;
use std::mem::{size_of, align_of, zeroed}; use std::mem::{size_of, align_of, zeroed};

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(untagged_unions)]
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
#[repr(C)] #[repr(C)]
struct LARGE_INTEGER_U { struct LARGE_INTEGER_U {

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(untagged_unions)]
union U { union U {
a: u64, a: u64,
b: u64, b: u64,

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(untagged_unions)]
union U { union U {
a: u8, a: u8,
} }

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(untagged_unions)]
macro_rules! duplicate { macro_rules! duplicate {
($i: item) => { ($i: item) => {
mod m1 { mod m1 {

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(untagged_unions)]
#[repr(u32)] #[repr(u32)]
enum Tag { I, F } enum Tag { I, F }

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(untagged_unions)]
use std::fmt; use std::fmt;
union U { union U {

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(untagged_unions)]
extern crate core; extern crate core;
use core::f32; use core::f32;

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(untagged_unions)]
// @has union/union.U.html // @has union/union.U.html
pub union U { pub union U {
// @has - //pre "pub a: u8" // @has - //pre "pub a: u8"

View File

@ -18,8 +18,6 @@
// aligned (while on most it is 8-byte aligned) and so the resulting // aligned (while on most it is 8-byte aligned) and so the resulting
// padding and overall computed sizes can be quite different. // padding and overall computed sizes can be quite different.
#![feature(untagged_unions)]
#![allow(dead_code)] #![allow(dead_code)]
#[derive(Default)] #[derive(Default)]