From 8339d71f3948522a9cfc5431fddc1179931668d9 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 18 May 2017 13:40:15 +0300 Subject: [PATCH 1/4] Make assignments to `Copy` union fields safe --- src/librustc/middle/effect.rs | 18 ++++++++ src/test/compile-fail/union/union-unsafe.rs | 46 +++++++++++++++++---- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/src/librustc/middle/effect.rs b/src/librustc/middle/effect.rs index d2b8ed8c29707..b09ff8e6d7616 100644 --- a/src/librustc/middle/effect.rs +++ b/src/librustc/middle/effect.rs @@ -218,6 +218,24 @@ impl<'a, 'tcx> Visitor<'tcx> for EffectCheckVisitor<'a, 'tcx> { } } } + hir::ExprAssign(ref lhs, ref rhs) => { + if let hir::ExprField(ref base_expr, field) = lhs.node { + if let ty::TyAdt(adt, ..) = self.tables.expr_ty_adjusted(base_expr).sty { + if adt.is_union() { + let field_ty = self.tables.expr_ty_adjusted(lhs); + let param_env = self.tcx.parameter_environment(adt.did); + if field_ty.moves_by_default(self.tcx, ¶m_env, field.span) { + self.require_unsafe(field.span, + "assignment to non-`Copy` union field"); + } + // Do not walk the field expr again. + intravisit::walk_expr(self, base_expr); + intravisit::walk_expr(self, rhs); + return + } + } + } + } _ => {} } diff --git a/src/test/compile-fail/union/union-unsafe.rs b/src/test/compile-fail/union/union-unsafe.rs index 97e1ec2cba865..a67603675f175 100644 --- a/src/test/compile-fail/union/union-unsafe.rs +++ b/src/test/compile-fail/union/union-unsafe.rs @@ -10,15 +10,47 @@ #![feature(untagged_unions)] -union U { +union U1 { a: u8 } +union U2 { + a: String +} + +union U3 { + a: T +} + +union U4 { + a: T +} + +fn generic_noncopy() { + let mut u3 = U3 { a: T::default() }; + u3.a = T::default(); //~ ERROR assignment to non-`Copy` union field requires unsafe +} + +fn generic_copy() { + let mut u3 = U3 { a: T::default() }; + // FIXME: it should be known here that `T: Copy`, need to use correct "parameter environment" + u3.a = T::default(); //~ ERROR assignment to non-`Copy` union field requires unsafe + let mut u4 = U4 { a: T::default() }; + u4.a = T::default(); // OK +} + fn main() { - let mut u = U { a: 10 }; // OK - let a = u.a; //~ ERROR access to union field requires unsafe function or block - u.a = 11; //~ ERROR access to union field requires unsafe function or block - let U { a } = u; //~ ERROR matching on union field requires unsafe function or block - if let U { a: 12 } = u {} //~ ERROR matching on union field requires unsafe function or block - // let U { .. } = u; // OK + let mut u1 = U1 { a: 10 }; // OK + let a = u1.a; //~ ERROR access to union field requires unsafe + u1.a = 11; // OK + let U1 { a } = u1; //~ ERROR matching on union field requires unsafe + if let U1 { a: 12 } = u1 {} //~ ERROR matching on union field requires unsafe + // let U1 { .. } = u1; // OK + + let mut u2 = U2 { a: String::from("old") }; // OK + u2.a = String::from("new"); //~ ERROR assignment to non-`Copy` union field requires unsafe + let mut u3 = U3 { a: 0 }; // OK + u3.a = 1; // OK + let mut u3 = U3 { a: String::from("old") }; // OK + u3.a = String::from("new"); //~ ERROR assignment to non-`Copy` union field requires unsafe } From 16ca2841dd247abf2ef020920d6050179cf6b91e Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 18 May 2017 14:28:40 +0300 Subject: [PATCH 2/4] Use parameter environment associated with field use, not field definition --- src/librustc/middle/effect.rs | 10 ++++++++-- src/test/compile-fail/union/union-unsafe.rs | 3 +-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/librustc/middle/effect.rs b/src/librustc/middle/effect.rs index b09ff8e6d7616..a9bb174470982 100644 --- a/src/librustc/middle/effect.rs +++ b/src/librustc/middle/effect.rs @@ -52,6 +52,7 @@ fn type_is_unsafe_function(ty: Ty) -> bool { struct EffectCheckVisitor<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx>, tables: &'a ty::TypeckTables<'tcx>, + body_id: hir::BodyId, /// Whether we're in an unsafe context. unsafe_context: UnsafeContext, @@ -99,10 +100,13 @@ impl<'a, 'tcx> Visitor<'tcx> for EffectCheckVisitor<'a, 'tcx> { fn visit_nested_body(&mut self, body: hir::BodyId) { let old_tables = self.tables; + let old_body_id = self.body_id; self.tables = self.tcx.body_tables(body); + self.body_id = body; let body = self.tcx.hir.body(body); self.visit_body(body); self.tables = old_tables; + self.body_id = old_body_id; } fn visit_fn(&mut self, fn_kind: FnKind<'tcx>, fn_decl: &'tcx hir::FnDecl, @@ -223,8 +227,9 @@ impl<'a, 'tcx> Visitor<'tcx> for EffectCheckVisitor<'a, 'tcx> { if let ty::TyAdt(adt, ..) = self.tables.expr_ty_adjusted(base_expr).sty { if adt.is_union() { let field_ty = self.tables.expr_ty_adjusted(lhs); - let param_env = self.tcx.parameter_environment(adt.did); - if field_ty.moves_by_default(self.tcx, ¶m_env, field.span) { + let owner_def_id = self.tcx.hir.body_owner_def_id(self.body_id); + let param_env = self.tcx.param_env(owner_def_id); + if field_ty.moves_by_default(self.tcx, param_env, field.span) { self.require_unsafe(field.span, "assignment to non-`Copy` union field"); } @@ -261,6 +266,7 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { let mut visitor = EffectCheckVisitor { tcx: tcx, tables: &ty::TypeckTables::empty(), + body_id: hir::BodyId { node_id: ast::CRATE_NODE_ID }, unsafe_context: UnsafeContext::new(SafeContext), }; diff --git a/src/test/compile-fail/union/union-unsafe.rs b/src/test/compile-fail/union/union-unsafe.rs index a67603675f175..2e018e696a415 100644 --- a/src/test/compile-fail/union/union-unsafe.rs +++ b/src/test/compile-fail/union/union-unsafe.rs @@ -33,8 +33,7 @@ fn generic_noncopy() { fn generic_copy() { let mut u3 = U3 { a: T::default() }; - // FIXME: it should be known here that `T: Copy`, need to use correct "parameter environment" - u3.a = T::default(); //~ ERROR assignment to non-`Copy` union field requires unsafe + u3.a = T::default(); // OK let mut u4 = U4 { a: T::default() }; u4.a = T::default(); // OK } From 7e623796b05966034a8c446c2224ddfe437aa537 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 18 May 2017 00:22:52 +0300 Subject: [PATCH 3/4] Stabilize unions with `Copy` fields and no destructor --- src/libcollections/lib.rs | 1 - src/librustc/middle/stability.rs | 21 ++++++++++++++++++ src/librustc_data_structures/lib.rs | 1 - src/libsyntax/feature_gate.rs | 6 ----- .../borrowck/borrowck-union-borrow-nested.rs | 4 ---- .../borrowck/borrowck-union-borrow.rs | 2 -- .../borrowck/borrowck-union-uninitialized.rs | 2 -- .../privacy/union-field-privacy-1.rs | 2 -- .../privacy/union-field-privacy-2.rs | 2 -- .../compile-fail/union/union-const-eval.rs | 2 -- .../compile-fail/union/union-const-pat.rs | 2 -- src/test/compile-fail/union/union-derive.rs | 2 -- src/test/compile-fail/union/union-empty.rs | 2 -- .../compile-fail/union/union-feature-gate.rs | 22 ++++++++++++++++++- src/test/compile-fail/union/union-fields.rs | 2 -- src/test/compile-fail/union/union-generic.rs | 2 -- .../union/union-lint-dead-code.rs | 1 - src/test/compile-fail/union/union-repr-c.rs | 1 - .../compile-fail/union/union-suggest-field.rs | 2 -- src/test/debuginfo/union-smoke.rs | 1 - src/test/run-pass/union/auxiliary/union.rs | 2 -- src/test/run-pass/union/union-backcomp.rs | 2 -- src/test/run-pass/union/union-basic.rs | 2 -- src/test/run-pass/union/union-c-interop.rs | 2 -- src/test/run-pass/union/union-const-trans.rs | 2 -- .../run-pass/union/union-inherent-method.rs | 2 -- src/test/run-pass/union/union-macro.rs | 2 -- .../run-pass/union/union-pat-refutability.rs | 2 -- src/test/run-pass/union/union-trait-impl.rs | 2 -- src/test/run-pass/union/union-transmute.rs | 2 -- src/test/rustdoc/union.rs | 2 -- src/test/ui/print_type_sizes/packed.rs | 2 -- 32 files changed, 42 insertions(+), 62 deletions(-) diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index 8d056afdb571a..064ba1802dea6 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -64,7 +64,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)] diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 1e856f6716ef7..aa3aec4e66271 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -590,6 +590,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 */) } intravisit::walk_item(self, item); diff --git a/src/librustc_data_structures/lib.rs b/src/librustc_data_structures/lib.rs index 00c46d992bfd5..e438fb370b1c6 100644 --- a/src/librustc_data_structures/lib.rs +++ b/src/librustc_data_structures/lib.rs @@ -32,7 +32,6 @@ #![feature(staged_api)] #![feature(unboxed_closures)] #![feature(fn_traits)] -#![feature(untagged_unions)] #![feature(associated_consts)] #![feature(unsize)] #![feature(i128_type)] diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 9b55a860b3595..7c69234f44388 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -1202,12 +1202,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(..) => { gate_feature_post!(&self, optin_builtin_traits, i.span, diff --git a/src/test/compile-fail/borrowck/borrowck-union-borrow-nested.rs b/src/test/compile-fail/borrowck/borrowck-union-borrow-nested.rs index 8b6b8d9ecb08e..6298c87453ca6 100644 --- a/src/test/compile-fail/borrowck/borrowck-union-borrow-nested.rs +++ b/src/test/compile-fail/borrowck/borrowck-union-borrow-nested.rs @@ -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, diff --git a/src/test/compile-fail/borrowck/borrowck-union-borrow.rs b/src/test/compile-fail/borrowck/borrowck-union-borrow.rs index ecc698acc317f..20b882e1f807c 100644 --- a/src/test/compile-fail/borrowck/borrowck-union-borrow.rs +++ b/src/test/compile-fail/borrowck/borrowck-union-borrow.rs @@ -10,8 +10,6 @@ // ignore-tidy-linelength -#![feature(untagged_unions)] - #[derive(Clone, Copy)] union U { a: u8, diff --git a/src/test/compile-fail/borrowck/borrowck-union-uninitialized.rs b/src/test/compile-fail/borrowck/borrowck-union-uninitialized.rs index 36e062f8464e9..81376a1a169d4 100644 --- a/src/test/compile-fail/borrowck/borrowck-union-uninitialized.rs +++ b/src/test/compile-fail/borrowck/borrowck-union-uninitialized.rs @@ -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, } diff --git a/src/test/compile-fail/privacy/union-field-privacy-1.rs b/src/test/compile-fail/privacy/union-field-privacy-1.rs index bddcd391b205d..c716cba10c7bf 100644 --- a/src/test/compile-fail/privacy/union-field-privacy-1.rs +++ b/src/test/compile-fail/privacy/union-field-privacy-1.rs @@ -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, diff --git a/src/test/compile-fail/privacy/union-field-privacy-2.rs b/src/test/compile-fail/privacy/union-field-privacy-2.rs index e26b5e99ec1a5..d6bb765202da5 100644 --- a/src/test/compile-fail/privacy/union-field-privacy-2.rs +++ b/src/test/compile-fail/privacy/union-field-privacy-2.rs @@ -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, diff --git a/src/test/compile-fail/union/union-const-eval.rs b/src/test/compile-fail/union/union-const-eval.rs index b2bf173c59c86..ee4d9fe99eeb8 100644 --- a/src/test/compile-fail/union/union-const-eval.rs +++ b/src/test/compile-fail/union/union-const-eval.rs @@ -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, diff --git a/src/test/compile-fail/union/union-const-pat.rs b/src/test/compile-fail/union/union-const-pat.rs index 3d168980ed246..5f75e3cc4a2d6 100644 --- a/src/test/compile-fail/union/union-const-pat.rs +++ b/src/test/compile-fail/union/union-const-pat.rs @@ -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, diff --git a/src/test/compile-fail/union/union-derive.rs b/src/test/compile-fail/union/union-derive.rs index 26dbdfd0b4118..ffd290fb073db 100644 --- a/src/test/compile-fail/union/union-derive.rs +++ b/src/test/compile-fail/union/union-derive.rs @@ -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 diff --git a/src/test/compile-fail/union/union-empty.rs b/src/test/compile-fail/union/union-empty.rs index ce5bbf60fee25..1f499c49a6870 100644 --- a/src/test/compile-fail/union/union-empty.rs +++ b/src/test/compile-fail/union/union-empty.rs @@ -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() {} diff --git a/src/test/compile-fail/union/union-feature-gate.rs b/src/test/compile-fail/union/union-feature-gate.rs index 0c2165871f6db..8a0490cdc6b6d 100644 --- a/src/test/compile-fail/union/union-feature-gate.rs +++ b/src/test/compile-fail/union/union-feature-gate.rs @@ -10,8 +10,28 @@ // gate-test-untagged_unions -union U { //~ ERROR unions are unstable and possibly buggy +union U1 { // OK a: u8, } +union U2 { // OK + a: T, +} + +union U3 { //~ ERROR unions with non-`Copy` fields are unstable + a: String, +} + +union U4 { //~ 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() {} diff --git a/src/test/compile-fail/union/union-fields.rs b/src/test/compile-fail/union/union-fields.rs index 3ee95c2ef4258..b5d582a5746f7 100644 --- a/src/test/compile-fail/union/union-fields.rs +++ b/src/test/compile-fail/union/union-fields.rs @@ -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, diff --git a/src/test/compile-fail/union/union-generic.rs b/src/test/compile-fail/union/union-generic.rs index e6586b0fb7f6a..8bd422b42d879 100644 --- a/src/test/compile-fail/union/union-generic.rs +++ b/src/test/compile-fail/union/union-generic.rs @@ -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 { diff --git a/src/test/compile-fail/union/union-lint-dead-code.rs b/src/test/compile-fail/union/union-lint-dead-code.rs index 7a552c8f8b76a..a64187c5f2344 100644 --- a/src/test/compile-fail/union/union-lint-dead-code.rs +++ b/src/test/compile-fail/union/union-lint-dead-code.rs @@ -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 { diff --git a/src/test/compile-fail/union/union-repr-c.rs b/src/test/compile-fail/union/union-repr-c.rs index d7dfb126c9324..15a4197fe94c9 100644 --- a/src/test/compile-fail/union/union-repr-c.rs +++ b/src/test/compile-fail/union/union-repr-c.rs @@ -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)] diff --git a/src/test/compile-fail/union/union-suggest-field.rs b/src/test/compile-fail/union/union-suggest-field.rs index 3c355989b82f0..65c7c980b8ac2 100644 --- a/src/test/compile-fail/union/union-suggest-field.rs +++ b/src/test/compile-fail/union/union-suggest-field.rs @@ -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, } diff --git a/src/test/debuginfo/union-smoke.rs b/src/test/debuginfo/union-smoke.rs index 0b2544151fd32..433196b526c5c 100644 --- a/src/test/debuginfo/union-smoke.rs +++ b/src/test/debuginfo/union-smoke.rs @@ -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), diff --git a/src/test/run-pass/union/auxiliary/union.rs b/src/test/run-pass/union/auxiliary/union.rs index 0231e38a729b7..2c4945622abdc 100644 --- a/src/test/run-pass/union/auxiliary/union.rs +++ b/src/test/run-pass/union/auxiliary/union.rs @@ -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, diff --git a/src/test/run-pass/union/union-backcomp.rs b/src/test/run-pass/union/union-backcomp.rs index 0f8c996bebda8..b706a81850ce8 100644 --- a/src/test/run-pass/union/union-backcomp.rs +++ b/src/test/run-pass/union/union-backcomp.rs @@ -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;) } diff --git a/src/test/run-pass/union/union-basic.rs b/src/test/run-pass/union/union-basic.rs index dc14c12b6a22e..5e5b2d4d7ce7b 100644 --- a/src/test/run-pass/union/union-basic.rs +++ b/src/test/run-pass/union/union-basic.rs @@ -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}; diff --git a/src/test/run-pass/union/union-c-interop.rs b/src/test/run-pass/union/union-c-interop.rs index 13dfd414615c5..b3df7d658b15f 100644 --- a/src/test/run-pass/union/union-c-interop.rs +++ b/src/test/run-pass/union/union-c-interop.rs @@ -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 { diff --git a/src/test/run-pass/union/union-const-trans.rs b/src/test/run-pass/union/union-const-trans.rs index bdae1a0eaf88f..77270364bb5e9 100644 --- a/src/test/run-pass/union/union-const-trans.rs +++ b/src/test/run-pass/union/union-const-trans.rs @@ -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, diff --git a/src/test/run-pass/union/union-inherent-method.rs b/src/test/run-pass/union/union-inherent-method.rs index adea27bd25462..a88fdc57a3ef4 100644 --- a/src/test/run-pass/union/union-inherent-method.rs +++ b/src/test/run-pass/union/union-inherent-method.rs @@ -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, } diff --git a/src/test/run-pass/union/union-macro.rs b/src/test/run-pass/union/union-macro.rs index a23fbc3be9e2c..b6141ae82c371 100644 --- a/src/test/run-pass/union/union-macro.rs +++ b/src/test/run-pass/union/union-macro.rs @@ -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 { diff --git a/src/test/run-pass/union/union-pat-refutability.rs b/src/test/run-pass/union/union-pat-refutability.rs index e6144f35f1d54..81607236c9ecd 100644 --- a/src/test/run-pass/union/union-pat-refutability.rs +++ b/src/test/run-pass/union/union-pat-refutability.rs @@ -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 } diff --git a/src/test/run-pass/union/union-trait-impl.rs b/src/test/run-pass/union/union-trait-impl.rs index a5a2be0133aba..1cdaff2cab7c8 100644 --- a/src/test/run-pass/union/union-trait-impl.rs +++ b/src/test/run-pass/union/union-trait-impl.rs @@ -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 { diff --git a/src/test/run-pass/union/union-transmute.rs b/src/test/run-pass/union/union-transmute.rs index 7a0b4c6aaca49..7233687aaab53 100644 --- a/src/test/run-pass/union/union-transmute.rs +++ b/src/test/run-pass/union/union-transmute.rs @@ -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; diff --git a/src/test/rustdoc/union.rs b/src/test/rustdoc/union.rs index 0dcc9098ad75c..2eb25d9b7ddac 100644 --- a/src/test/rustdoc/union.rs +++ b/src/test/rustdoc/union.rs @@ -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" diff --git a/src/test/ui/print_type_sizes/packed.rs b/src/test/ui/print_type_sizes/packed.rs index cd7ef86d70ee3..7f278e71b21c6 100644 --- a/src/test/ui/print_type_sizes/packed.rs +++ b/src/test/ui/print_type_sizes/packed.rs @@ -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)] From 5fa129f17bbb693b905d705ef3ef46ec0723000f Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 31 May 2017 11:58:12 +0300 Subject: [PATCH 4/4] Fix the build + Bump prerelease version --- src/bootstrap/channel.rs | 2 +- src/librustc/middle/effect.rs | 6 +++--- src/librustc/middle/stability.rs | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/bootstrap/channel.rs b/src/bootstrap/channel.rs index 966bb4dbfb870..088513a76bde1 100644 --- a/src/bootstrap/channel.rs +++ b/src/bootstrap/channel.rs @@ -28,7 +28,7 @@ pub const CFG_RELEASE_NUM: &'static str = "1.18.0"; // An optional number to put after the label, e.g. '.2' -> '-beta.2' // Be sure to make this starts with a dot to conform to semver pre-release // versions (section 9) -pub const CFG_PRERELEASE_VERSION: &'static str = ".4"; +pub const CFG_PRERELEASE_VERSION: &'static str = ".5"; pub struct GitInfo { inner: Option, diff --git a/src/librustc/middle/effect.rs b/src/librustc/middle/effect.rs index a9bb174470982..a95f20ab58ee3 100644 --- a/src/librustc/middle/effect.rs +++ b/src/librustc/middle/effect.rs @@ -227,9 +227,9 @@ impl<'a, 'tcx> Visitor<'tcx> for EffectCheckVisitor<'a, 'tcx> { if let ty::TyAdt(adt, ..) = self.tables.expr_ty_adjusted(base_expr).sty { if adt.is_union() { let field_ty = self.tables.expr_ty_adjusted(lhs); - let owner_def_id = self.tcx.hir.body_owner_def_id(self.body_id); - let param_env = self.tcx.param_env(owner_def_id); - if field_ty.moves_by_default(self.tcx, param_env, field.span) { + let owner_id = self.tcx.hir.body_owner(self.body_id); + let param_env = ty::ParameterEnvironment::for_item(self.tcx, owner_id); + if field_ty.moves_by_default(self.tcx, ¶m_env, field.span) { self.require_unsafe(field.span, "assignment to non-`Copy` union field"); } diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index aa3aec4e66271..342d27ccce323 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -594,15 +594,15 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> { // 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); + let adt_def = self.tcx.lookup_adt_def(def_id); + let ty = self.tcx.item_type(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); + let param_env = ty::ParameterEnvironment::for_item(self.tcx, item.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,