From ab5ba049bcf38f7bc7bde43d0acbd3869a9c7683 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 15 Sep 2016 00:51:46 +0300 Subject: [PATCH] Partially stabilize RFC 1506 "Clarify relationships between ADTs" --- src/librustc_typeck/check/mod.rs | 7 ---- src/libsyntax/feature_gate.rs | 35 +++++++++---------- .../compile-fail/auxiliary/empty-struct.rs | 2 -- .../auxiliary/namespace-mix-new.rs | 2 +- .../auxiliary/namespace-mix-old.rs | 2 -- .../compile-fail/empty-struct-braces-pat-2.rs | 2 -- .../compile-fail/empty-struct-braces-pat-3.rs | 2 -- .../compile-fail/empty-struct-tuple-pat.rs | 2 -- .../compile-fail/empty-struct-unit-pat.rs | 2 -- .../feature-gate-relaxed-adts-2.rs | 27 -------------- src/test/compile-fail/issue-16819.rs | 26 -------------- src/test/compile-fail/issue-17800.rs | 2 -- src/test/compile-fail/issue-4736.rs | 2 -- src/test/compile-fail/namespace-mix-new.rs | 2 +- src/test/compile-fail/namespace-mix-old.rs | 2 -- ...adts.rs => numeric-fields-feature-gate.rs} | 16 +++------ .../empty-struct-braces-derive.rs | 1 - src/test/run-pass/auxiliary/empty-struct.rs | 2 -- src/test/run-pass/empty-struct-braces.rs | 2 -- 19 files changed, 23 insertions(+), 115 deletions(-) delete mode 100644 src/test/compile-fail/feature-gate-relaxed-adts-2.rs delete mode 100644 src/test/compile-fail/issue-16819.rs rename src/test/compile-fail/{feature-gate-relaxed-adts.rs => numeric-fields-feature-gate.rs} (56%) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index d8314bd6c2aed..81eec25762b3d 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3261,13 +3261,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { }; 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 c5fae9f3236d7..8ac3f9e5e54c7 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -271,7 +271,6 @@ declare_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 @@ impl<'a> Visitor for PostExpansionVisitor<'a> { 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 @@ impl<'a> Visitor for PostExpansionVisitor<'a> { 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 @@ impl<'a> Visitor for PostExpansionVisitor<'a> { 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 dcbb0ce178bd8..4a30286563422 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 88e8b0d56fe3d..d42c0ee1a4da5 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 7bbba7163b557..29b139d771b0d 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 58e3ca6b3ac5c..4349e72c5d73b 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 1960eca9f8028..d6c5b95349211 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 f15c126a12608..5e683eafade8a 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 90f6ae5755f81..532c2d85053f6 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 a75f2647f49a4..0000000000000 --- 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 4301b47f2e9b2..0000000000000 --- 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 d5f1614c14d2d..f7cae91aa93a4 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 c93e75042dd17..19803079d0224 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 0abe8bd439093..59592e3d737d8 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 ad6766441961b..8cd82050814a0 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 dc5e347aadf30..3ce85813a9b51 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 66ffff94333e9..79ce3cb68d4be 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 b599d7bee73de..734e57a774d87 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 48966f24a2e5e..7c161ba8dd96e 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::*;