diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index d8314bd6c2aedc29cdc7b050ea18ad8bc4a65309..81eec25762b3da63c48033046b4506ab7153d11f 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3261,13 +3261,6 @@ pub fn check_struct_path(&self, }; if let Some((variant, did, substs)) = variant { - if variant.ctor_kind == CtorKind::Fn && - !self.tcx.sess.features.borrow().relaxed_adts { - emit_feature_err(&self.tcx.sess.parse_sess, - "relaxed_adts", path.span, GateIssue::Language, - "tuple structs and variants in struct patterns are unstable"); - } - // Check bounds on type arguments used in the path. let type_predicates = self.tcx.lookup_predicates(did); let bounds = self.instantiate_bounds(path.span, substs, &type_predicates); diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index c5fae9f3236d76935dd4044ab9f7c05d024662a0..8ac3f9e5e54c74305614c9d89af6b7e1a9d2a84c 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -271,7 +271,6 @@ pub fn new() -> Features { // Allows `impl Trait` in function return types. (active, conservative_impl_trait, "1.12.0", Some(34511)), - // Allows tuple structs and variants in more contexts, // Permits numeric fields in struct expressions and patterns. (active, relaxed_adts, "1.12.0", Some(35626)), @@ -996,6 +995,10 @@ fn contains_novel_literal(item: &ast::MetaItem) -> bool { } } +fn starts_with_digit(s: &str) -> bool { + s.as_bytes().first().cloned().map_or(false, |b| b >= b'0' && b <= b'9') +} + impl<'a> Visitor for PostExpansionVisitor<'a> { fn visit_attribute(&mut self, attr: &ast::Attribute) { if !self.context.cm.span_allows_unstable(attr.span) { @@ -1175,6 +1178,11 @@ fn visit_expr(&mut self, e: &ast::Expr) { gate_feature_post!(&self, field_init_shorthand, field.span, "struct field shorthands are unstable"); } + if starts_with_digit(&field.ident.node.name.as_str()) { + gate_feature_post!(&self, relaxed_adts, + field.span, + "numeric fields in struct expressions are unstable"); + } } } _ => {} @@ -1201,10 +1209,14 @@ fn visit_pat(&mut self, pattern: &ast::Pat) { pattern.span, "box pattern syntax is experimental"); } - PatKind::TupleStruct(_, ref fields, ddpos) - if ddpos.is_none() && fields.is_empty() => { - gate_feature_post!(&self, relaxed_adts, pattern.span, - "empty tuple structs patterns are unstable"); + PatKind::Struct(_, ref fields, _) => { + for field in fields { + if starts_with_digit(&field.node.ident.name.as_str()) { + gate_feature_post!(&self, relaxed_adts, + field.span, + "numeric fields in struct patterns are unstable"); + } + } } _ => {} } @@ -1287,19 +1299,6 @@ fn visit_impl_item(&mut self, ii: &ast::ImplItem) { visit::walk_impl_item(self, ii); } - fn visit_variant_data(&mut self, vdata: &ast::VariantData, _: ast::Ident, - _: &ast::Generics, _: NodeId, span: Span) { - if vdata.fields().is_empty() { - if vdata.is_tuple() { - gate_feature_post!(&self, relaxed_adts, span, - "empty tuple structs and enum variants are unstable, \ - use unit structs and enum variants instead"); - } - } - - visit::walk_struct_def(self, vdata) - } - fn visit_vis(&mut self, vis: &ast::Visibility) { let span = match *vis { ast::Visibility::Crate(span) => span, diff --git a/src/test/compile-fail/auxiliary/empty-struct.rs b/src/test/compile-fail/auxiliary/empty-struct.rs index dcbb0ce178bd8c487df447ee0124c0e535de5a6a..4a302865634224b5f541664e70f1fe5921c17f2e 100644 --- a/src/test/compile-fail/auxiliary/empty-struct.rs +++ b/src/test/compile-fail/auxiliary/empty-struct.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(relaxed_adts)] - pub struct XEmpty1 {} pub struct XEmpty2; pub struct XEmpty6(); diff --git a/src/test/compile-fail/auxiliary/namespace-mix-new.rs b/src/test/compile-fail/auxiliary/namespace-mix-new.rs index 88e8b0d56fe3d4ab3e94bcdafe6b957794859851..d42c0ee1a4da5c14ecd7a8b6f9caed0a7991b446 100644 --- a/src/test/compile-fail/auxiliary/namespace-mix-new.rs +++ b/src/test/compile-fail/auxiliary/namespace-mix-new.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(item_like_imports, relaxed_adts)] +#![feature(item_like_imports)] pub mod c { pub struct S {} diff --git a/src/test/compile-fail/auxiliary/namespace-mix-old.rs b/src/test/compile-fail/auxiliary/namespace-mix-old.rs index 7bbba7163b5570c98ad5e56235f1b2fd0746cdcf..29b139d771b0deebe0fa6054f8059831bee9fc3b 100644 --- a/src/test/compile-fail/auxiliary/namespace-mix-old.rs +++ b/src/test/compile-fail/auxiliary/namespace-mix-old.rs @@ -10,8 +10,6 @@ // FIXME: Remove when `item_like_imports` is stabilized. -#![feature(relaxed_adts)] - pub mod c { pub struct S {} pub struct TS(); diff --git a/src/test/compile-fail/empty-struct-braces-pat-2.rs b/src/test/compile-fail/empty-struct-braces-pat-2.rs index 58e3ca6b3ac5cb3c8cdd216f38c602efc800804b..4349e72c5d73be4af2d24c2a54ba9232bbbfd518 100644 --- a/src/test/compile-fail/empty-struct-braces-pat-2.rs +++ b/src/test/compile-fail/empty-struct-braces-pat-2.rs @@ -12,8 +12,6 @@ // aux-build:empty-struct.rs -#![feature(relaxed_adts)] - extern crate empty_struct; use empty_struct::*; diff --git a/src/test/compile-fail/empty-struct-braces-pat-3.rs b/src/test/compile-fail/empty-struct-braces-pat-3.rs index 1960eca9f80281a3c1f22a69c5b1d4035520b505..d6c5b95349211e75e9c18eef9c96ec7597020c93 100644 --- a/src/test/compile-fail/empty-struct-braces-pat-3.rs +++ b/src/test/compile-fail/empty-struct-braces-pat-3.rs @@ -12,8 +12,6 @@ // aux-build:empty-struct.rs -#![feature(relaxed_adts)] - extern crate empty_struct; use empty_struct::*; diff --git a/src/test/compile-fail/empty-struct-tuple-pat.rs b/src/test/compile-fail/empty-struct-tuple-pat.rs index f15c126a1260837128a297fe03b4a3707300ce37..5e683eafade8a311ed292becb5a7b63251ebc40d 100644 --- a/src/test/compile-fail/empty-struct-tuple-pat.rs +++ b/src/test/compile-fail/empty-struct-tuple-pat.rs @@ -12,8 +12,6 @@ // aux-build:empty-struct.rs -#![feature(relaxed_adts)] - extern crate empty_struct; use empty_struct::*; diff --git a/src/test/compile-fail/empty-struct-unit-pat.rs b/src/test/compile-fail/empty-struct-unit-pat.rs index 90f6ae5755f81403f0ae45380bca414796f262f2..532c2d85053f6b4d56ac6b7d1d8bdf37dcb527c1 100644 --- a/src/test/compile-fail/empty-struct-unit-pat.rs +++ b/src/test/compile-fail/empty-struct-unit-pat.rs @@ -12,8 +12,6 @@ // aux-build:empty-struct.rs -#![feature(relaxed_adts)] - extern crate empty_struct; use empty_struct::*; diff --git a/src/test/compile-fail/feature-gate-relaxed-adts-2.rs b/src/test/compile-fail/feature-gate-relaxed-adts-2.rs deleted file mode 100644 index a75f2647f49a4d3fd324c84700c127629819f927..0000000000000000000000000000000000000000 --- a/src/test/compile-fail/feature-gate-relaxed-adts-2.rs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -struct Z(u8, u8); - -enum E { - U(u8, u8), -} - -fn main() { - match Z(0, 1) { - Z{..} => {} //~ ERROR tuple structs and variants in struct patterns are unstable - } - match E::U(0, 1) { - E::U{..} => {} //~ ERROR tuple structs and variants in struct patterns are unstable - } - - let z1 = Z(0, 1); - let z2 = Z { ..z1 }; //~ ERROR tuple structs and variants in struct patterns are unstable -} diff --git a/src/test/compile-fail/issue-16819.rs b/src/test/compile-fail/issue-16819.rs deleted file mode 100644 index 4301b47f2e9b29ce956f8450d3d69c4fc543bccf..0000000000000000000000000000000000000000 --- a/src/test/compile-fail/issue-16819.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -struct TS ( //~ ERROR empty tuple structs and enum variants are unstable - #[cfg(untrue)] - i32, -); - -enum E { - TV ( //~ ERROR empty tuple structs and enum variants are unstable - #[cfg(untrue)] - i32, - ) -} - -fn main() { - let s = TS; - let tv = E::TV; -} diff --git a/src/test/compile-fail/issue-17800.rs b/src/test/compile-fail/issue-17800.rs index d5f1614c14d2d0d8b1bfe7d73f6228159d885c9a..f7cae91aa93a43e334e5812f19499aff4aae6897 100644 --- a/src/test/compile-fail/issue-17800.rs +++ b/src/test/compile-fail/issue-17800.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(relaxed_adts)] - enum MyOption { MySome(T), MyNone, diff --git a/src/test/compile-fail/issue-4736.rs b/src/test/compile-fail/issue-4736.rs index c93e75042dd1752c352cb4d88265baae9405afba..19803079d022493a9569996064f3d0d4ca4bc2f4 100644 --- a/src/test/compile-fail/issue-4736.rs +++ b/src/test/compile-fail/issue-4736.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(relaxed_adts)] - struct NonCopyable(()); fn main() { diff --git a/src/test/compile-fail/namespace-mix-new.rs b/src/test/compile-fail/namespace-mix-new.rs index 0abe8bd4390935dc64a9135cdd9edaecde373cc2..59592e3d737d8f6478b4c10a9c865054c8826da4 100644 --- a/src/test/compile-fail/namespace-mix-new.rs +++ b/src/test/compile-fail/namespace-mix-new.rs @@ -10,7 +10,7 @@ // aux-build:namespace-mix-new.rs -#![feature(item_like_imports, relaxed_adts)] +#![feature(item_like_imports)] extern crate namespace_mix_new; use namespace_mix_new::*; diff --git a/src/test/compile-fail/namespace-mix-old.rs b/src/test/compile-fail/namespace-mix-old.rs index ad6766441961b2375027922e42b22096e95a0927..8cd82050814a001674d250edccb542fddc0e3b18 100644 --- a/src/test/compile-fail/namespace-mix-old.rs +++ b/src/test/compile-fail/namespace-mix-old.rs @@ -12,8 +12,6 @@ // aux-build:namespace-mix-old.rs -#![feature(relaxed_adts)] - extern crate namespace_mix_old; use namespace_mix_old::{xm1, xm2, xm3, xm4, xm5, xm6, xm7, xm8, xm9, xmA, xmB, xmC}; diff --git a/src/test/compile-fail/feature-gate-relaxed-adts.rs b/src/test/compile-fail/numeric-fields-feature-gate.rs similarity index 56% rename from src/test/compile-fail/feature-gate-relaxed-adts.rs rename to src/test/compile-fail/numeric-fields-feature-gate.rs index dc5e347aadf3074a9d3b4b8927a48452afc47d9d..3ce85813a9b519a9d351c1db38528c3145c01fde 100644 --- a/src/test/compile-fail/feature-gate-relaxed-adts.rs +++ b/src/test/compile-fail/numeric-fields-feature-gate.rs @@ -8,19 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct S(); //~ ERROR empty tuple structs and enum variants are unstable -struct Z(u8, u8); - -enum E { - V(), //~ ERROR empty tuple structs and enum variants are unstable - U(u8, u8), -} +struct S(u8); fn main() { - match S() { - S() => {} //~ ERROR empty tuple structs patterns are unstable - } - match E::V() { - E::V() => {} //~ ERROR empty tuple structs patterns are unstable + let s = S{0: 10}; //~ ERROR numeric fields in struct expressions are unstable + match s { + S{0: a, ..} => {} //~ ERROR numeric fields in struct patterns are unstable } } diff --git a/src/test/run-pass-fulldeps/empty-struct-braces-derive.rs b/src/test/run-pass-fulldeps/empty-struct-braces-derive.rs index 66ffff94333e9fe19ed869c3739e105f6852c96f..79ce3cb68d4be7e1bbdac925fa2b879f64089ef7 100644 --- a/src/test/run-pass-fulldeps/empty-struct-braces-derive.rs +++ b/src/test/run-pass-fulldeps/empty-struct-braces-derive.rs @@ -10,7 +10,6 @@ // `#[derive(Trait)]` works for empty structs/variants with braces or parens. -#![feature(relaxed_adts)] #![feature(rustc_private)] extern crate serialize as rustc_serialize; diff --git a/src/test/run-pass/auxiliary/empty-struct.rs b/src/test/run-pass/auxiliary/empty-struct.rs index b599d7bee73defca8eb7261063c7ebcde99bf465..734e57a774d87935a50b08162effe599960a69e0 100644 --- a/src/test/run-pass/auxiliary/empty-struct.rs +++ b/src/test/run-pass/auxiliary/empty-struct.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(relaxed_adts)] - pub struct XEmpty1 {} pub struct XEmpty2; pub struct XEmpty7(); diff --git a/src/test/run-pass/empty-struct-braces.rs b/src/test/run-pass/empty-struct-braces.rs index 48966f24a2e5eca4afead2914955c92cf5ed0a94..7c161ba8dd96e71c84e6eab12aac3680ba05c58d 100644 --- a/src/test/run-pass/empty-struct-braces.rs +++ b/src/test/run-pass/empty-struct-braces.rs @@ -13,8 +13,6 @@ // aux-build:empty-struct.rs -#![feature(relaxed_adts)] - extern crate empty_struct; use empty_struct::*;