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

librustc: Remove common fields and nested enums from the language #5602

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 1 addition & 2 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,7 @@ fn encode_enum_variant_info(ecx: @EncodeContext, ebml_w: writer::Encoder,
if args.len() > 0 && generics.ty_params.len() == 0 => {
encode_symbol(ecx, ebml_w, variant.node.id);
}
ast::tuple_variant_kind(_) | ast::struct_variant_kind(_) |
ast::enum_variant_kind(_) => {}
ast::tuple_variant_kind(_) | ast::struct_variant_kind(_) => {}
}
encode_discriminant(ecx, ebml_w, variant.node.id);
if vi[i].disr_val != disr_val {
Expand Down
12 changes: 1 addition & 11 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use syntax::ast::{expr_binary, expr_break, expr_cast, expr_field};
use syntax::ast::{expr_fn_block, expr_index, expr_method_call, expr_path};
use syntax::ast::{def_prim_ty, def_region, def_self, def_ty, def_ty_param};
use syntax::ast::{def_upvar, def_use, def_variant, div, eq};
use syntax::ast::{enum_variant_kind, expr, expr_again, expr_assign_op};
use syntax::ast::{expr, expr_again, expr_assign_op};
use syntax::ast::{expr_index, expr_loop};
use syntax::ast::{expr_path, expr_struct, expr_unary, fn_decl};
use syntax::ast::{foreign_item, foreign_item_const, foreign_item_fn, ge};
Expand Down Expand Up @@ -1383,16 +1383,6 @@ pub impl Resolver {
variant.span);
self.structs.insert(local_def(variant.node.id));
}
enum_variant_kind(ref enum_definition) => {
child.define_type(privacy,
def_ty(local_def(variant.node.id)),
variant.span);
for (*enum_definition).variants.each |variant| {
self.build_reduced_graph_for_variant(*variant, item_id,
parent_privacy,
parent, visitor);
}
}
}
}

Expand Down
11 changes: 0 additions & 11 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2051,14 +2051,6 @@ pub fn trans_enum_def(ccx: @CrateContext, enum_definition: ast::enum_def,
trans_struct_def(ccx, struct_def, path,
variant.node.id);
}
ast::enum_variant_kind(ref enum_definition) => {
trans_enum_def(ccx,
*enum_definition,
id,
path,
vi,
&mut *i);
}
}
}
}
Expand Down Expand Up @@ -2513,9 +2505,6 @@ pub fn get_item_val(ccx: @CrateContext, id: ast::node_id) -> ValueRef {
ast::struct_variant_kind(_) => {
fail!(~"struct variant kind unexpected in get_item_val")
}
ast::enum_variant_kind(_) => {
fail!(~"enum variant kind unexpected in get_item_val")
}
}
set_inline_hint(llfn);
llfn
Expand Down
2 changes: 0 additions & 2 deletions src/librustc/middle/trans/monomorphize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,6 @@ pub fn monomorphic_fn(ccx: @CrateContext,
}
ast::struct_variant_kind(_) =>
ccx.tcx.sess.bug(~"can't monomorphize struct variants"),
ast::enum_variant_kind(_) =>
ccx.tcx.sess.bug(~"can't monomorphize enum variants")
}
d
}
Expand Down
3 changes: 0 additions & 3 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3873,9 +3873,6 @@ pub fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[VariantInfo] {
ast::struct_variant_kind(_) => {
fail!(~"struct variant kinds unimpl in enum_variants")
}
ast::enum_variant_kind(_) => {
fail!(~"enum variant kinds unimpl in enum_variants")
}
}
})
}
Expand Down
10 changes: 0 additions & 10 deletions src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3066,16 +3066,6 @@ pub fn check_enum_variants(ccx: @mut CrateCtxt,
ccx.tcx, local_def(v.node.id)).map(|cf|
ty::node_id_to_type(ccx.tcx, cf.id.node)));
}
ast::enum_variant_kind(_) => {
arg_tys = None;
do_check(ccx,
sp,
vs,
id,
&mut *disr_vals,
&mut *disr_val,
&mut *variants);
}
}

match arg_tys {
Expand Down
9 changes: 0 additions & 9 deletions src/librustc/middle/typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,6 @@ pub fn get_enum_variant_types(ccx: &CrateCtxt,
|f| ty::node_id_to_type(ccx.tcx, f.node.id));
result_ty = Some(ty::mk_ctor_fn(tcx, input_tys, enum_ty));
}

ast::enum_variant_kind(ref enum_definition) => {
get_enum_variant_types(ccx,
enum_ty,
enum_definition.variants,
generics,
rp);
result_ty = None;
}
};

match result_ty {
Expand Down
2 changes: 0 additions & 2 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1078,15 +1078,13 @@ pub struct variant_arg {
pub enum variant_kind {
tuple_variant_kind(~[variant_arg]),
struct_variant_kind(@struct_def),
enum_variant_kind(enum_def)
}

#[auto_encode]
#[auto_decode]
#[deriving(Eq)]
pub struct enum_def {
variants: ~[variant],
common: Option<@struct_def>,
}

#[auto_encode]
Expand Down
4 changes: 0 additions & 4 deletions src/libsyntax/ext/auto_encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -990,8 +990,6 @@ fn mk_enum_ser_body(
),
ast::struct_variant_kind(*) =>
fail!(~"struct variants unimplemented"),
ast::enum_variant_kind(*) =>
fail!(~"enum variants unimplemented"),
}
};

Expand Down Expand Up @@ -1089,8 +1087,6 @@ fn mk_enum_deser_body(
},
ast::struct_variant_kind(*) =>
fail!(~"struct variants unimplemented"),
ast::enum_variant_kind(*) =>
fail!(~"enum variants unimplemented")
};

let pat = @ast::pat {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/deriving/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use core::prelude::*;

use ast;
use ast::{TraitTyParamBound, Ty, and, bind_by_ref, binop, deref, enum_def};
use ast::{enum_variant_kind, expr, expr_match, ident, impure_fn, item, item_};
use ast::{expr, expr_match, ident, impure_fn, item, item_};
use ast::{item_enum, item_impl, item_struct, Generics};
use ast::{m_imm, meta_item, method};
use ast::{named_field, or, pat, pat_ident, pat_wild, public, pure_fn};
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/deriving/eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use core::prelude::*;

use ast;
use ast::{TraitTyParamBound, Ty, and, bind_by_ref, binop, deref, enum_def};
use ast::{enum_variant_kind, expr, expr_match, ident, impure_fn, item, item_};
use ast::{expr, expr_match, ident, impure_fn, item, item_};
use ast::{item_enum, item_impl, item_struct, Generics};
use ast::{m_imm, meta_item, method};
use ast::{named_field, or, pat, pat_ident, pat_wild, public, pure_fn};
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/deriving/iter_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use core::prelude::*;

use ast;
use ast::{TraitTyParamBound, Ty, and, bind_by_ref, binop, deref, enum_def};
use ast::{enum_variant_kind, expr, expr_match, ident, impure_fn, item, item_};
use ast::{expr, expr_match, ident, impure_fn, item, item_};
use ast::{item_enum, item_impl, item_struct, Generics};
use ast::{m_imm, meta_item, method};
use ast::{named_field, or, pat, pat_ident, pat_wild, public, pure_fn};
Expand Down
8 changes: 1 addition & 7 deletions src/libsyntax/ext/deriving/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use core::prelude::*;

use ast;
use ast::{TraitTyParamBound, Ty, and, bind_by_ref, binop, deref, enum_def};
use ast::{enum_variant_kind, expr, expr_match, ident, impure_fn, item, item_};
use ast::{expr, expr_match, ident, impure_fn, item, item_};
use ast::{item_enum, item_impl, item_struct, Generics};
use ast::{m_imm, meta_item, method};
use ast::{named_field, or, pat, pat_ident, pat_wild, public, pure_fn};
Expand Down Expand Up @@ -283,19 +283,13 @@ pub fn create_enum_variant_pattern(cx: @ext_ctxt,

build::mk_pat_struct(cx, span, matching_path, field_pats)
}
enum_variant_kind(*) => {
cx.span_unimpl(span, ~"enum variants for `deriving`");
}
}
}

pub fn variant_arg_count(cx: @ext_ctxt, span: span, variant: &variant) -> uint {
match variant.node.kind {
tuple_variant_kind(ref args) => args.len(),
struct_variant_kind(ref struct_def) => struct_def.fields.len(),
enum_variant_kind(*) => {
cx.span_bug(span, ~"variant_arg_count: enum variants deprecated")
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/pipes/pipec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl to_type_decls for state {
cx.item_enum_poly(
name,
self.span,
ast::enum_def { variants: items_msg, common: None },
ast::enum_def { variants: items_msg },
cx.strip_bounds(&self.generics)
)
]
Expand Down
14 changes: 0 additions & 14 deletions src/libsyntax/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,6 @@ pub fn noop_fold_item_underscore(i: &item_, fld: @ast_fold) -> item_ {
variants: do enum_definition.variants.map |x| {
fld.fold_variant(x)
},
common: do enum_definition.common.map |x| {
fold_struct_def(*x, fld)
}
},
fold_generics(generics, fld))
}
Expand Down Expand Up @@ -682,17 +679,6 @@ fn noop_fold_variant(v: &variant_, fld: @ast_fold) -> variant_ {
ctor_id: struct_def.ctor_id.map(|c| fld.new_id(*c))
})
}
enum_variant_kind(ref enum_definition) => {
let variants = do (*enum_definition).variants.map |x| {
fld.fold_variant(x)
};
let common = do (*enum_definition).common.map |x| {
fold_struct_def(*x, fld)
};
kind = enum_variant_kind(
ast::enum_def { variants: variants, common: common }
);
}
}

let fold_attribute = |x| fold_attribute_(x, fld);
Expand Down
79 changes: 29 additions & 50 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use ast::{_mod, add, arg, arm, attribute, bind_by_ref, bind_infer};
use ast::{bind_by_copy, bitand, bitor, bitxor, blk};
use ast::{blk_check_mode, box, by_copy, by_ref};
use ast::{crate, crate_cfg, decl, decl_item};
use ast::{decl_local, default_blk, deref, div, enum_def, enum_variant_kind};
use ast::{decl_local, default_blk, deref, div, enum_def};
use ast::{expl, expr, expr_, expr_addr_of, expr_match, expr_again};
use ast::{expr_assign, expr_assign_op, expr_binary, expr_block};
use ast::{expr_break, expr_call, expr_cast, expr_copy, expr_do_body};
Expand Down Expand Up @@ -3788,63 +3788,42 @@ pub impl Parser {
fn parse_enum_def(&self, generics: &ast::Generics) -> enum_def {
let mut variants = ~[];
let mut all_nullary = true, have_disr = false;
let mut common_fields = None;

while *self.token != token::RBRACE {
let variant_attrs = self.parse_outer_attributes();
let vlo = self.span.lo;

// Is this a common field declaration?
if self.eat_keyword(&~"struct") {
if common_fields.is_some() {
self.fatal(~"duplicate declaration of shared fields");
}
self.expect(&token::LBRACE);
common_fields = Some(self.parse_struct_def());
loop;
}

let vis = self.parse_visibility();

// Is this a nested enum declaration?
let ident, needs_comma, kind;
let mut args = ~[], disr_expr = None;
if self.eat_keyword(&~"enum") {
ident = self.parse_ident();
self.expect(&token::LBRACE);
let nested_enum_def = self.parse_enum_def(generics);
kind = enum_variant_kind(nested_enum_def);
needs_comma = false;
} else {
ident = self.parse_ident();
if self.eat(&token::LBRACE) {
// Parse a struct variant.
all_nullary = false;
kind = struct_variant_kind(self.parse_struct_def());
} else if *self.token == token::LPAREN {
all_nullary = false;
let arg_tys = self.parse_unspanned_seq(
&token::LPAREN,
&token::RPAREN,
seq_sep_trailing_disallowed(token::COMMA),
|p| p.parse_ty(false)
);
for arg_tys.each |ty| {
args.push(ast::variant_arg {
ty: *ty,
id: self.get_id(),
});
}
kind = tuple_variant_kind(args);
} else if self.eat(&token::EQ) {
have_disr = true;
disr_expr = Some(self.parse_expr());
kind = tuple_variant_kind(args);
} else {
kind = tuple_variant_kind(~[]);
ident = self.parse_ident();
if self.eat(&token::LBRACE) {
// Parse a struct variant.
all_nullary = false;
kind = struct_variant_kind(self.parse_struct_def());
} else if *self.token == token::LPAREN {
all_nullary = false;
let arg_tys = self.parse_unspanned_seq(
&token::LPAREN,
&token::RPAREN,
seq_sep_trailing_disallowed(token::COMMA),
|p| p.parse_ty(false)
);
for arg_tys.each |ty| {
args.push(ast::variant_arg {
ty: *ty,
id: self.get_id(),
});
}
needs_comma = true;
kind = tuple_variant_kind(args);
} else if self.eat(&token::EQ) {
have_disr = true;
disr_expr = Some(self.parse_expr());
kind = tuple_variant_kind(args);
} else {
kind = tuple_variant_kind(~[]);
}
needs_comma = true;

let vr = ast::variant_ {
name: ident,
Expand All @@ -3864,7 +3843,7 @@ pub impl Parser {
enum");
}

ast::enum_def { variants: variants, common: common_fields }
ast::enum_def { variants: variants }
}

fn parse_item_enum(&self) -> item_info {
Expand Down Expand Up @@ -3892,7 +3871,7 @@ pub impl Parser {
return (
id,
item_enum(
ast::enum_def { variants: ~[variant], common: None },
ast::enum_def { variants: ~[variant] },
generics),
None
);
Expand Down
3 changes: 0 additions & 3 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,9 +785,6 @@ pub fn print_variant(s: @ps, v: ast::variant) {
let generics = ast_util::empty_generics();
print_struct(s, struct_def, &generics, v.node.name, v.span);
}
ast::enum_variant_kind(ref enum_definition) => {
print_variants(s, (*enum_definition).variants, v.span);
}
}
match v.node.disr_expr {
Some(d) => {
Expand Down
3 changes: 0 additions & 3 deletions src/libsyntax/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,6 @@ pub fn visit_enum_def<E>(enum_definition: ast::enum_def,
(v.visit_struct_def)(struct_def, vr.node.name, tps,
vr.node.id, e, v);
}
enum_variant_kind(ref enum_definition) => {
visit_enum_def((*enum_definition), tps, e, v);
}
}
// Visit the disr expr if it exists
for vr.node.disr_expr.each |ex| { (v.visit_expr)(*ex, e, v) }
Expand Down
Loading