libsyntax: Remove struct literal expressions from the compiler
This commit is contained in:
parent
4e3dbfe052
commit
954ae9c975
@ -162,8 +162,7 @@ pub fn check_expr(sess: Session,
|
||||
expr_field(*) |
|
||||
expr_index(*) |
|
||||
expr_tup(*) |
|
||||
expr_struct(_, _, None) |
|
||||
expr_rec(_, None) => { }
|
||||
expr_struct(_, _, None) => { }
|
||||
expr_addr_of(*) => {
|
||||
sess.span_err(
|
||||
e.span,
|
||||
|
@ -117,8 +117,7 @@ pub fn classify(e: @expr,
|
||||
}
|
||||
}
|
||||
|
||||
ast::expr_struct(_, ref fs, None) |
|
||||
ast::expr_rec(ref fs, None) => {
|
||||
ast::expr_struct(_, ref fs, None) => {
|
||||
let cs = do vec::map((*fs)) |f| {
|
||||
if f.node.mutbl == ast::m_imm {
|
||||
classify(f.node.expr, def_map, tcx)
|
||||
|
@ -73,7 +73,6 @@ pub enum lint {
|
||||
deprecated_mode,
|
||||
deprecated_pattern,
|
||||
non_camel_case_types,
|
||||
structural_records,
|
||||
type_limits,
|
||||
default_methods,
|
||||
deprecated_self,
|
||||
@ -217,13 +216,6 @@ pub fn get_lint_dict() -> LintDict {
|
||||
default: allow
|
||||
}),
|
||||
|
||||
(@~"structural_records",
|
||||
@LintSpec {
|
||||
lint: structural_records,
|
||||
desc: "use of any structural records",
|
||||
default: deny
|
||||
}),
|
||||
|
||||
(@~"legacy modes",
|
||||
@LintSpec {
|
||||
lint: legacy_modes,
|
||||
@ -486,7 +478,6 @@ fn check_item(i: @ast::item, cx: ty::ctxt) {
|
||||
check_item_path_statement(cx, i);
|
||||
check_item_non_camel_case_types(cx, i);
|
||||
check_item_heap(cx, i);
|
||||
check_item_structural_records(cx, i);
|
||||
check_item_deprecated_modes(cx, i);
|
||||
check_item_type_limits(cx, i);
|
||||
check_item_default_methods(cx, i);
|
||||
@ -729,24 +720,6 @@ fn check_item_deprecated_mutable_fields(cx: ty::ctxt, item: @ast::item) {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_item_structural_records(cx: ty::ctxt, it: @ast::item) {
|
||||
let visit = item_stopping_visitor(
|
||||
visit::mk_simple_visitor(@visit::SimpleVisitor {
|
||||
visit_expr: |e: @ast::expr| {
|
||||
match e.node {
|
||||
ast::expr_rec(*) =>
|
||||
cx.sess.span_lint(
|
||||
structural_records, e.id, it.id,
|
||||
e.span,
|
||||
~"structural records are deprecated"),
|
||||
_ => ()
|
||||
}
|
||||
},
|
||||
.. *visit::default_simple_visitor()
|
||||
}));
|
||||
visit::visit_item(it, (), visit);
|
||||
}
|
||||
|
||||
fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) {
|
||||
|
||||
fn check_foreign_fn(cx: ty::ctxt, fn_id: ast::node_id,
|
||||
|
@ -615,16 +615,13 @@ fn visit_expr(expr: @expr, &&self: @mut IrMaps, vt: vt<@mut IrMaps>) {
|
||||
}
|
||||
|
||||
// otherwise, live nodes are not required:
|
||||
expr_index(*) | expr_field(*) | expr_vstore(*) |
|
||||
expr_vec(*) | expr_rec(*) | expr_call(*) | expr_method_call(*) |
|
||||
expr_tup(*) | expr_log(*) | expr_binary(*) |
|
||||
expr_assert(*) | expr_addr_of(*) | expr_copy(*) |
|
||||
expr_loop_body(*) | expr_do_body(*) | expr_cast(*) |
|
||||
expr_unary(*) |
|
||||
expr_index(*) | expr_field(*) | expr_vstore(*) | expr_vec(*) |
|
||||
expr_call(*) | expr_method_call(*) | expr_tup(*) | expr_log(*) |
|
||||
expr_binary(*) | expr_assert(*) | expr_addr_of(*) | expr_copy(*) |
|
||||
expr_loop_body(*) | expr_do_body(*) | expr_cast(*) | expr_unary(*) |
|
||||
expr_break(_) | expr_again(_) | expr_lit(_) | expr_ret(*) |
|
||||
expr_block(*) | expr_assign(*) |
|
||||
expr_swap(*) | expr_assign_op(*) | expr_mac(*) | expr_struct(*) |
|
||||
expr_repeat(*) | expr_paren(*) => {
|
||||
expr_block(*) | expr_assign(*) | expr_swap(*) | expr_assign_op(*) |
|
||||
expr_mac(*) | expr_struct(*) | expr_repeat(*) | expr_paren(*) => {
|
||||
visit::visit_expr(expr, self, vt);
|
||||
}
|
||||
}
|
||||
@ -1287,13 +1284,6 @@ pub impl Liveness {
|
||||
self.propagate_through_expr(element, succ)
|
||||
}
|
||||
|
||||
expr_rec(ref fields, with_expr) => {
|
||||
let succ = self.propagate_through_opt_expr(with_expr, succ);
|
||||
do (*fields).foldr(succ) |field, succ| {
|
||||
self.propagate_through_expr(field.node.expr, succ)
|
||||
}
|
||||
}
|
||||
|
||||
expr_struct(_, ref fields, with_expr) => {
|
||||
let succ = self.propagate_through_opt_expr(with_expr, succ);
|
||||
do (*fields).foldr(succ) |field, succ| {
|
||||
@ -1618,18 +1608,14 @@ fn check_expr(expr: @expr, &&self: @Liveness, vt: vt<@Liveness>) {
|
||||
}
|
||||
|
||||
// no correctness conditions related to liveness
|
||||
expr_call(*) | expr_method_call(*) |
|
||||
expr_if(*) | expr_match(*) |
|
||||
expr_while(*) | expr_loop(*) |
|
||||
expr_index(*) | expr_field(*) | expr_vstore(*) |
|
||||
expr_vec(*) | expr_rec(*) | expr_tup(*) |
|
||||
expr_log(*) | expr_binary(*) |
|
||||
expr_assert(*) | expr_copy(*) |
|
||||
expr_loop_body(*) | expr_do_body(*) |
|
||||
expr_cast(*) | expr_unary(*) |
|
||||
expr_ret(*) | expr_break(*) | expr_again(*) | expr_lit(_) |
|
||||
expr_block(*) | expr_swap(*) | expr_mac(*) | expr_addr_of(*) |
|
||||
expr_struct(*) | expr_repeat(*) | expr_paren(*) => {
|
||||
expr_call(*) | expr_method_call(*) | expr_if(*) | expr_match(*) |
|
||||
expr_while(*) | expr_loop(*) | expr_index(*) | expr_field(*) |
|
||||
expr_vstore(*) | expr_vec(*) | expr_tup(*) | expr_log(*) |
|
||||
expr_binary(*) | expr_assert(*) | expr_copy(*) | expr_loop_body(*) |
|
||||
expr_do_body(*) | expr_cast(*) | expr_unary(*) | expr_ret(*) |
|
||||
expr_break(*) | expr_again(*) | expr_lit(_) | expr_block(*) |
|
||||
expr_swap(*) | expr_mac(*) | expr_addr_of(*) | expr_struct(*) |
|
||||
expr_repeat(*) | expr_paren(*) => {
|
||||
visit::visit_expr(expr, self, vt);
|
||||
}
|
||||
}
|
||||
|
@ -449,8 +449,7 @@ pub impl mem_categorization_ctxt {
|
||||
ast::expr_binary(*) | ast::expr_while(*) |
|
||||
ast::expr_block(*) | ast::expr_loop(*) | ast::expr_match(*) |
|
||||
ast::expr_lit(*) | ast::expr_break(*) | ast::expr_mac(*) |
|
||||
ast::expr_again(*) | ast::expr_rec(*) | ast::expr_struct(*) |
|
||||
ast::expr_repeat(*) => {
|
||||
ast::expr_again(*) | ast::expr_struct(*) | ast::expr_repeat(*) => {
|
||||
return self.cat_rvalue(expr, expr_ty);
|
||||
}
|
||||
}
|
||||
|
@ -469,7 +469,6 @@ pub impl VisitContext {
|
||||
self.use_fn_args(expr.callee_id, *args, visitor);
|
||||
}
|
||||
|
||||
expr_rec(ref fields, opt_with) |
|
||||
expr_struct(_, ref fields, opt_with) => {
|
||||
for fields.each |field| {
|
||||
self.consume_expr(field.node.expr, visitor);
|
||||
|
@ -368,12 +368,6 @@ fn const_expr_unchecked(cx: @CrateContext, e: @ast::expr) -> ValueRef {
|
||||
let repr = adt::represent_type(cx, ety);
|
||||
adt::trans_const(cx, repr, 0, es.map(|e| const_expr(cx, *e)))
|
||||
}
|
||||
ast::expr_rec(ref fs, None) => {
|
||||
let ety = ty::expr_ty(cx.tcx, e);
|
||||
let repr = adt::represent_type(cx, ety);
|
||||
adt::trans_const(cx, repr, 0,
|
||||
fs.map(|f| const_expr(cx, f.node.expr)))
|
||||
}
|
||||
ast::expr_struct(_, ref fs, None) => {
|
||||
let ety = ty::expr_ty(cx.tcx, e);
|
||||
let repr = adt::represent_type(cx, ety);
|
||||
|
@ -599,7 +599,6 @@ fn trans_rvalue_dps_unadjusted(bcx: block, expr: @ast::expr,
|
||||
controlflow::trans_block(bcx, blk, dest)
|
||||
};
|
||||
}
|
||||
ast::expr_rec(ref fields, base) |
|
||||
ast::expr_struct(_, ref fields, base) => {
|
||||
return trans_rec_or_struct(bcx, (*fields), base, expr.id, dest);
|
||||
}
|
||||
|
@ -263,12 +263,9 @@ pub fn mark_for_method_call(cx: Context, e_id: node_id, callee_id: node_id) {
|
||||
|
||||
pub fn mark_for_expr(cx: Context, e: @expr) {
|
||||
match e.node {
|
||||
expr_vstore(_, _) |
|
||||
expr_vec(_, _) |
|
||||
expr_rec(_, _) | expr_struct(*) | expr_tup(_) |
|
||||
expr_vstore(_, _) | expr_vec(_, _) | expr_struct(*) | expr_tup(_) |
|
||||
expr_unary(box(_), _) | expr_unary(uniq(_), _) |
|
||||
expr_binary(add, _, _) |
|
||||
expr_copy(_) | expr_repeat(*) => {
|
||||
expr_binary(add, _, _) | expr_copy(_) | expr_repeat(*) => {
|
||||
node_type_needs(cx, use_repr, e.id);
|
||||
}
|
||||
expr_cast(base, _) => {
|
||||
|
@ -3066,7 +3066,6 @@ pub fn expr_kind(tcx: ctxt,
|
||||
|
||||
ast::expr_call(*) |
|
||||
ast::expr_method_call(*) |
|
||||
ast::expr_rec(*) |
|
||||
ast::expr_struct(*) |
|
||||
ast::expr_tup(*) |
|
||||
ast::expr_if(*) |
|
||||
|
@ -2508,9 +2508,6 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
||||
let typ = ty::mk_tup(tcx, elt_ts);
|
||||
fcx.write_ty(id, typ);
|
||||
}
|
||||
ast::expr_rec(ref fields, base) => {
|
||||
fail!()
|
||||
}
|
||||
ast::expr_struct(path, ref fields, base_expr) => {
|
||||
// Resolve the path.
|
||||
match tcx.def_map.find(&id) {
|
||||
|
@ -701,7 +701,6 @@ pub mod guarantor {
|
||||
ast::expr_cast(*) |
|
||||
ast::expr_call(*) |
|
||||
ast::expr_method_call(*) |
|
||||
ast::expr_rec(*) |
|
||||
ast::expr_struct(*) |
|
||||
ast::expr_tup(*) |
|
||||
ast::expr_if(*) |
|
||||
|
@ -564,7 +564,6 @@ pub enum CallSugar {
|
||||
pub enum expr_ {
|
||||
expr_vstore(@expr, expr_vstore),
|
||||
expr_vec(~[@expr], mutability),
|
||||
expr_rec(~[field], Option<@expr>),
|
||||
expr_call(@expr, ~[@expr], CallSugar),
|
||||
expr_method_call(@expr, ident, ~[@Ty], ~[@expr], CallSugar),
|
||||
expr_tup(~[@expr]),
|
||||
|
@ -162,13 +162,6 @@ pub fn mk_field(sp: span, f: &Field) -> ast::field {
|
||||
pub fn mk_fields(sp: span, fields: ~[Field]) -> ~[ast::field] {
|
||||
fields.map(|f| mk_field(sp, f))
|
||||
}
|
||||
pub fn mk_rec_e(cx: ext_ctxt,
|
||||
sp: span,
|
||||
+fields: ~[Field])
|
||||
-> @ast::expr {
|
||||
mk_expr(cx, sp, ast::expr_rec(mk_fields(sp, fields),
|
||||
option::None::<@ast::expr>))
|
||||
}
|
||||
pub fn mk_struct_e(cx: ext_ctxt,
|
||||
sp: span,
|
||||
+ctor_path: ~[ast::ident],
|
||||
|
@ -32,7 +32,10 @@ pub fn expand_syntax_ext(cx: ext_ctxt,
|
||||
MRExpr(@ast::expr {
|
||||
id: cx.next_id(),
|
||||
callee_id: cx.next_id(),
|
||||
node: ast::expr_rec(~[], option::None),
|
||||
node: ast::expr_lit(@codemap::spanned {
|
||||
node: ast::lit_nil,
|
||||
span: sp
|
||||
}),
|
||||
span: sp,
|
||||
})
|
||||
}
|
||||
|
@ -479,12 +479,6 @@ pub fn noop_fold_expr(e: &expr_, fld: @ast_fold) -> expr_ {
|
||||
expr_repeat(expr, count, mutt) => {
|
||||
expr_repeat(fld.fold_expr(expr), fld.fold_expr(count), mutt)
|
||||
}
|
||||
expr_rec(ref fields, maybe_expr) => {
|
||||
expr_rec(
|
||||
fields.map(|x| fold_field(*x)),
|
||||
maybe_expr.map(|x| fld.fold_expr(*x))
|
||||
)
|
||||
}
|
||||
expr_tup(ref elts) => expr_tup(elts.map(|x| fld.fold_expr(*x))),
|
||||
expr_call(f, ref args, blk) => {
|
||||
expr_call(
|
||||
|
@ -25,7 +25,7 @@ use ast::{expr_assert, expr_assign, expr_assign_op, expr_binary, expr_block};
|
||||
use ast::{expr_break, expr_call, expr_cast, expr_copy, expr_do_body};
|
||||
use ast::{expr_field, expr_fn_block, expr_if, expr_index};
|
||||
use ast::{expr_lit, expr_log, expr_loop, expr_loop_body, expr_mac};
|
||||
use ast::{expr_method_call, expr_paren, expr_path, expr_rec, expr_repeat};
|
||||
use ast::{expr_method_call, expr_paren, expr_path, expr_repeat};
|
||||
use ast::{expr_ret, expr_swap, expr_struct, expr_tup, expr_unary};
|
||||
use ast::{expr_vec, expr_vstore, expr_vstore_mut_box};
|
||||
use ast::{expr_vstore_fixed, expr_vstore_slice, expr_vstore_box};
|
||||
@ -1956,34 +1956,6 @@ pub impl Parser {
|
||||
self.look_ahead(2) == token::COLON))
|
||||
}
|
||||
|
||||
fn parse_record_literal(&self) -> expr_ {
|
||||
self.expect(&token::LBRACE);
|
||||
let mut fields = ~[self.parse_field(token::COLON)];
|
||||
let mut base = None;
|
||||
while *self.token != token::RBRACE {
|
||||
if *self.token == token::COMMA
|
||||
&& self.look_ahead(1) == token::DOTDOT {
|
||||
self.bump();
|
||||
self.bump();
|
||||
base = Some(self.parse_expr()); break;
|
||||
}
|
||||
|
||||
if self.try_parse_obsolete_with() {
|
||||
break;
|
||||
}
|
||||
|
||||
self.expect(&token::COMMA);
|
||||
if *self.token == token::RBRACE {
|
||||
// record ends by an optional trailing comma
|
||||
break;
|
||||
}
|
||||
fields.push(self.parse_field(token::COLON));
|
||||
}
|
||||
self.expect(&token::RBRACE);
|
||||
self.warn(~"REC");
|
||||
return expr_rec(fields, base);
|
||||
}
|
||||
|
||||
fn parse_match_expr(&self) -> @expr {
|
||||
let lo = self.last_span.lo;
|
||||
let discriminant = self.parse_expr();
|
||||
|
@ -1169,22 +1169,6 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) {
|
||||
end(s);
|
||||
}
|
||||
|
||||
ast::expr_rec(ref fields, wth) => {
|
||||
word(s.s, ~"{");
|
||||
commasep_cmnt(s, consistent, (*fields), print_field, get_span);
|
||||
match wth {
|
||||
Some(expr) => {
|
||||
ibox(s, indent_unit);
|
||||
word(s.s, ~",");
|
||||
space(s.s);
|
||||
word(s.s, ~"..");
|
||||
print_expr(s, expr);
|
||||
end(s);
|
||||
}
|
||||
_ => word(s.s, ~",")
|
||||
}
|
||||
word(s.s, ~"}");
|
||||
}
|
||||
ast::expr_struct(path, ref fields, wth) => {
|
||||
print_path(s, path, true);
|
||||
word(s.s, ~"{");
|
||||
|
@ -479,10 +479,6 @@ pub fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) {
|
||||
(v.visit_expr)(element, e, v);
|
||||
(v.visit_expr)(count, e, v);
|
||||
}
|
||||
expr_rec(ref flds, base) => {
|
||||
for flds.each |f| { (v.visit_expr)(f.node.expr, e, v); }
|
||||
visit_expr_opt(base, e, v);
|
||||
}
|
||||
expr_struct(p, ref flds, base) => {
|
||||
visit_path(p, e, v);
|
||||
for flds.each |f| { (v.visit_expr)(f.node.expr, e, v); }
|
||||
|
Loading…
x
Reference in New Issue
Block a user