Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partially stabilize RFC 1506 "Clarify relationships between ADTs" #36868

Merged
merged 1 commit into from
Nov 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
35 changes: 17 additions & 18 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
}
}
}
_ => {}
Expand All @@ -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");
}
}
}
_ => {}
}
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions src/test/compile-fail/auxiliary/empty-struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/auxiliary/namespace-mix-new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
2 changes: 0 additions & 2 deletions src/test/compile-fail/auxiliary/namespace-mix-old.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

// FIXME: Remove when `item_like_imports` is stabilized.

#![feature(relaxed_adts)]

pub mod c {
pub struct S {}
pub struct TS();
Expand Down
2 changes: 0 additions & 2 deletions src/test/compile-fail/empty-struct-braces-pat-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

// aux-build:empty-struct.rs

#![feature(relaxed_adts)]

extern crate empty_struct;
use empty_struct::*;

Expand Down
2 changes: 0 additions & 2 deletions src/test/compile-fail/empty-struct-braces-pat-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

// aux-build:empty-struct.rs

#![feature(relaxed_adts)]

extern crate empty_struct;
use empty_struct::*;

Expand Down
2 changes: 0 additions & 2 deletions src/test/compile-fail/empty-struct-tuple-pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

// aux-build:empty-struct.rs

#![feature(relaxed_adts)]

extern crate empty_struct;
use empty_struct::*;

Expand Down
2 changes: 0 additions & 2 deletions src/test/compile-fail/empty-struct-unit-pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

// aux-build:empty-struct.rs

#![feature(relaxed_adts)]

extern crate empty_struct;
use empty_struct::*;

Expand Down
27 changes: 0 additions & 27 deletions src/test/compile-fail/feature-gate-relaxed-adts-2.rs

This file was deleted.

26 changes: 0 additions & 26 deletions src/test/compile-fail/issue-16819.rs

This file was deleted.

2 changes: 0 additions & 2 deletions src/test/compile-fail/issue-17800.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(relaxed_adts)]

enum MyOption<T> {
MySome(T),
MyNone,
Expand Down
2 changes: 0 additions & 2 deletions src/test/compile-fail/issue-4736.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/namespace-mix-new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
2 changes: 0 additions & 2 deletions src/test/compile-fail/namespace-mix-old.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
1 change: 0 additions & 1 deletion src/test/run-pass-fulldeps/empty-struct-braces-derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/test/run-pass/auxiliary/empty-struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 0 additions & 2 deletions src/test/run-pass/empty-struct-braces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

// aux-build:empty-struct.rs

#![feature(relaxed_adts)]

extern crate empty_struct;
use empty_struct::*;

Expand Down