librustc: Remove `copy` expressions from the language.

This commit is contained in:
Patrick Walton 2013-07-09 19:32:09 -07:00
parent 99b33f7219
commit 99d44d24c7
21 changed files with 13 additions and 103 deletions

View File

@ -394,7 +394,6 @@ impl CFGBuilder {
}
ast::expr_addr_of(_, e) |
ast::expr_copy(e) |
ast::expr_loop_body(e) |
ast::expr_do_body(e) |
ast::expr_cast(e, _) |
@ -520,4 +519,4 @@ impl CFGBuilder {
fn is_method_call(&self, expr: &ast::expr) -> bool {
self.method_map.contains_key(&expr.id)
}
}
}

View File

@ -90,7 +90,6 @@ pub fn classify(e: &expr,
}
}
ast::expr_copy(inner) |
ast::expr_unary(_, _, inner) |
ast::expr_paren(inner) => {
classify(inner, tcx)

View File

@ -754,7 +754,6 @@ impl<'self, O:DataFlowOperator> PropagationContext<'self, O> {
}
ast::expr_addr_of(_, e) |
ast::expr_copy(e) |
ast::expr_loop_body(e) |
ast::expr_do_body(e) |
ast::expr_cast(e, _) |

View File

@ -298,17 +298,6 @@ pub fn check_expr(e: @expr, (cx, v): (Context, visit::vt<Context>)) {
_ => { }
}
}
expr_copy(expr) => {
// Note: This is the only place where we must check whether the
// argument is copyable. This is not because this is the only
// kind of expression that may copy things, but rather because all
// other copies will have been converted to moves by by the
// `moves` pass if the value is not copyable.
check_copy(cx,
ty::expr_ty(cx.tcx, expr),
expr.span,
"explicit copy requires a copyable argument");
}
expr_repeat(element, count_expr, _) => {
let count = ty::eval_repeat_count(&cx.tcx, count_expr);
if count > 1 {

View File

@ -83,7 +83,6 @@ pub enum lint {
type_limits,
default_methods,
unused_unsafe,
copy_implicitly_copyable,
managed_heap_memory,
owned_heap_memory,
@ -260,14 +259,6 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[
default: warn
}),
("copy_implicitly_copyable",
LintSpec {
lint: copy_implicitly_copyable,
desc: "detect unnecessary uses of `copy` on implicitly copyable \
values",
default: warn
}),
("unused_variable",
LintSpec {
lint: unused_variable,
@ -947,26 +938,6 @@ fn lint_unused_unsafe() -> visit::vt<@mut Context> {
})
}
fn lint_copy_implicitly_copyable() -> visit::vt<@mut Context> {
visit::mk_vt(@visit::Visitor {
visit_expr: |e, (cx, vt): (@mut Context, visit::vt<@mut Context>)| {
match e.node {
ast::expr_copy(subexpr) => {
let ty = ty::expr_ty(cx.tcx, subexpr);
if !ty::type_moves_by_default(cx.tcx, ty) {
cx.span_lint(copy_implicitly_copyable,
e.span,
"unnecessary `copy`; this value is implicitly copyable");
}
}
_ => ()
}
visit::visit_expr(e, (cx, vt));
},
.. *visit::default_visitor()
})
}
fn lint_unused_mut() -> visit::vt<@mut Context> {
fn check_pat(cx: &Context, p: @ast::pat) {
let mut used = false;
@ -1179,7 +1150,6 @@ pub fn check_crate(tcx: ty::ctxt, crate: @ast::crate) {
cx.add_lint(lint_heap());
cx.add_lint(lint_type_limits());
cx.add_lint(lint_unused_unsafe());
cx.add_lint(lint_copy_implicitly_copyable());
cx.add_lint(lint_unused_mut());
cx.add_lint(lint_session());
cx.add_lint(lint_unnecessary_allocations());

View File

@ -511,7 +511,7 @@ fn visit_expr(expr: @expr, (this, vt): (@mut IrMaps, vt<@mut IrMaps>)) {
// otherwise, live nodes are not required:
expr_index(*) | expr_field(*) | expr_vstore(*) | expr_vec(*) |
expr_call(*) | expr_method_call(*) | expr_tup(*) | expr_log(*) |
expr_binary(*) | expr_addr_of(*) | expr_copy(*) | expr_loop_body(*) |
expr_binary(*) | expr_addr_of(*) | expr_loop_body(*) |
expr_do_body(*) | expr_cast(*) | expr_unary(*) | expr_break(_) |
expr_again(_) | expr_lit(_) | expr_ret(*) | expr_block(*) |
expr_assign(*) | expr_assign_op(*) | expr_mac(*) |
@ -1206,7 +1206,6 @@ impl Liveness {
}
expr_addr_of(_, e) |
expr_copy(e) |
expr_loop_body(e) |
expr_do_body(e) |
expr_cast(e, _) |
@ -1481,7 +1480,7 @@ fn check_expr(expr: @expr, (this, vt): (@Liveness, vt<@Liveness>)) {
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_copy(*) | expr_loop_body(*) | expr_do_body(*) |
expr_binary(*) | expr_loop_body(*) | expr_do_body(*) |
expr_cast(*) | expr_unary(*) | expr_ret(*) | expr_break(*) |
expr_again(*) | expr_lit(_) | expr_block(*) |
expr_mac(*) | expr_addr_of(*) | expr_struct(*) | expr_repeat(*) |

View File

@ -426,13 +426,13 @@ impl mem_categorization_ctxt {
ast::expr_assign(*) | ast::expr_assign_op(*) |
ast::expr_fn_block(*) | ast::expr_ret(*) | ast::expr_loop_body(*) |
ast::expr_do_body(*) | ast::expr_unary(*) |
ast::expr_method_call(*) | ast::expr_copy(*) | ast::expr_cast(*) |
ast::expr_vstore(*) | ast::expr_vec(*) | ast::expr_tup(*) |
ast::expr_if(*) | ast::expr_log(*) | 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_struct(*) |
ast::expr_repeat(*) | ast::expr_inline_asm(*) => {
ast::expr_method_call(*) | ast::expr_cast(*) | ast::expr_vstore(*) |
ast::expr_vec(*) | ast::expr_tup(*) | ast::expr_if(*) |
ast::expr_log(*) | 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_struct(*) | ast::expr_repeat(*) |
ast::expr_inline_asm(*) => {
return self.cat_rvalue_node(expr, expr_ty);
}
}

View File

@ -454,10 +454,6 @@ impl VisitContext {
self.use_expr(discr, Read, visitor);
}
expr_copy(base) => {
self.use_expr(base, Read, visitor);
}
expr_paren(base) => {
// Note: base is not considered a *component* here, so
// use `expr_mode` not `comp_mode`.

View File

@ -631,17 +631,6 @@ fn trans_rvalue_dps_unadjusted(bcx: block, expr: @ast::expr,
ast::expr_do_body(blk) => {
return trans_into(bcx, blk, dest);
}
ast::expr_copy(a) => {
// If we just called `trans_into(bcx, a, dest)`, then this
// might *move* the value into `dest` if the value is
// non-copyable. So first get a datum and then do an
// explicit copy.
let datumblk = trans_to_datum(bcx, a);
return match dest {
Ignore => datumblk.bcx,
SaveIn(llval) => datumblk.copy_to(INIT, llval)
};
}
ast::expr_call(f, ref args, _) => {
return callee::trans_call(
bcx, expr, f, callee::ArgExprs(*args), expr.id, dest);

View File

@ -306,7 +306,7 @@ pub fn mark_for_expr(cx: &Context, e: &expr) {
match e.node {
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_repeat(*) => {
node_type_needs(cx, use_repr, e.id);
}
expr_cast(base, _) => {

View File

@ -3181,7 +3181,6 @@ pub fn expr_kind(tcx: ctxt,
ast::expr_loop_body(*) |
ast::expr_do_body(*) |
ast::expr_block(*) |
ast::expr_copy(*) |
ast::expr_repeat(*) |
ast::expr_lit(@codemap::spanned {node: lit_str(_), _}) |
ast::expr_vstore(_, ast::expr_vstore_slice) |

View File

@ -2518,10 +2518,6 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
fcx.write_nil(id);
}
}
ast::expr_copy(a) => {
check_expr_with_opt_hint(fcx, a, expected);
fcx.write_ty(id, fcx.expr_ty(a));
}
ast::expr_paren(a) => {
check_expr_with_opt_hint(fcx, a, expected);
fcx.write_ty(id, fcx.expr_ty(a));

View File

@ -1035,7 +1035,6 @@ pub mod guarantor {
ast::expr_loop_body(*) |
ast::expr_do_body(*) |
ast::expr_block(*) |
ast::expr_copy(*) |
ast::expr_repeat(*) |
ast::expr_vec(*) => {
assert!(!ty::expr_is_lval(

View File

@ -455,7 +455,6 @@ pub enum expr_ {
expr_do_body(@expr),
expr_block(blk),
expr_copy(@expr),
expr_assign(@expr, @expr),
expr_assign_op(node_id, binop, @expr, @expr),
expr_field(@expr, ident, ~[Ty]),

View File

@ -94,7 +94,6 @@ pub trait AstBuilder {
fn expr_deref(&self, sp: span, e: @ast::expr) -> @ast::expr;
fn expr_unary(&self, sp: span, op: ast::unop, e: @ast::expr) -> @ast::expr;
fn expr_copy(&self, sp: span, e: @ast::expr) -> @ast::expr;
fn expr_managed(&self, sp: span, e: @ast::expr) -> @ast::expr;
fn expr_addr_of(&self, sp: span, e: @ast::expr) -> @ast::expr;
fn expr_mut_addr_of(&self, sp: span, e: @ast::expr) -> @ast::expr;
@ -442,9 +441,6 @@ impl AstBuilder for @ExtCtxt {
self.expr(sp, ast::expr_unary(self.next_id(), op, e))
}
fn expr_copy(&self, sp: span, e: @ast::expr) -> @ast::expr {
self.expr(sp, ast::expr_copy(e))
}
fn expr_managed(&self, sp: span, e: @ast::expr) -> @ast::expr {
self.expr_unary(sp, ast::box(ast::m_imm), e)
}

View File

@ -580,7 +580,6 @@ pub fn noop_fold_expr(e: &expr_, fld: @ast_fold) -> expr_ {
)
}
expr_block(ref blk) => expr_block(fld.fold_block(blk)),
expr_copy(e) => expr_copy(fld.fold_expr(e)),
expr_assign(el, er) => {
expr_assign(fld.fold_expr(el), fld.fold_expr(er))
}

View File

@ -63,7 +63,6 @@ pub enum ObsoleteSyntax {
ObsoleteNamedExternModule,
ObsoleteMultipleLocalDecl,
ObsoleteMutWithMultipleBindings,
ObsoletePatternCopyKeyword,
}
impl to_bytes::IterBytes for ObsoleteSyntax {
@ -249,10 +248,6 @@ impl ParserObsoleteMethods for Parser {
"use multiple local declarations instead of e.g. `let mut \
(x, y) = ...`."
),
ObsoletePatternCopyKeyword => (
"`copy` in patterns",
"`copy` in patterns no longer has any effect"
),
};
self.report(sp, kind, kind_str, desc);

View File

@ -22,7 +22,7 @@ use ast::{crate, crate_cfg, decl, decl_item};
use ast::{decl_local, default_blk, deref, div, enum_def, explicit_self};
use ast::{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};
use ast::{expr_break, expr_call, expr_cast, 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_repeat};
@ -84,7 +84,7 @@ use parse::obsolete::{ObsoletePurity, ObsoleteStaticMethod};
use parse::obsolete::{ObsoleteConstItem, ObsoleteFixedLengthVectorType};
use parse::obsolete::{ObsoleteNamedExternModule, ObsoleteMultipleLocalDecl};
use parse::obsolete::{ObsoleteMutWithMultipleBindings};
use parse::obsolete::{ObsoletePatternCopyKeyword, ParserObsoleteMethods};
use parse::obsolete::{ParserObsoleteMethods};
use parse::token::{can_begin_expr, get_ident_interner, ident_to_str, is_ident};
use parse::token::{is_ident_or_path};
use parse::token::{is_plain_ident, INTERPOLATED, keywords, special_idents};
@ -1704,11 +1704,6 @@ impl Parser {
ex = expr_break(None);
}
hi = self.span.hi;
} else if self.eat_keyword(keywords::Copy) {
// COPY expression
let e = self.parse_expr();
ex = expr_copy(e);
hi = e.span.hi;
} else if *self.token == token::MOD_SEP ||
is_ident(&*self.token) && !self.is_keyword(keywords::True) &&
!self.is_keyword(keywords::False) {
@ -2799,10 +2794,6 @@ impl Parser {
// parse ref pat
let mutbl = self.parse_mutability();
pat = self.parse_pat_ident(bind_by_ref(mutbl));
} else if self.eat_keyword(keywords::Copy) {
// parse copy pat
self.obsolete(*self.span, ObsoletePatternCopyKeyword);
pat = self.parse_pat_ident(bind_infer);
} else {
let can_be_enum_or_struct = do self.look_ahead(1) |t| {
match *t {

View File

@ -566,7 +566,6 @@ pub mod keywords {
As,
Break,
Const,
Copy,
Do,
Else,
Enum,
@ -609,7 +608,6 @@ pub mod keywords {
As => ident { name: 32, ctxt: 0 },
Break => ident { name: 33, ctxt: 0 },
Const => ident { name: 34, ctxt: 0 },
Copy => ident { name: 35, ctxt: 0 },
Do => ident { name: 36, ctxt: 0 },
Else => ident { name: 37, ctxt: 0 },
Enum => ident { name: 38, ctxt: 0 },

View File

@ -1344,7 +1344,6 @@ pub fn print_expr(s: @ps, expr: &ast::expr) {
ibox(s, 0u);
print_block(s, blk);
}
ast::expr_copy(e) => { word_space(s, "copy"); print_expr(s, e); }
ast::expr_assign(lhs, rhs) => {
print_expr(s, lhs);
space(s.s);

View File

@ -532,7 +532,6 @@ pub fn visit_expr<E:Clone>(ex: @expr, (e, v): (E, vt<E>)) {
(v.visit_expr)(b, (e.clone(), v));
(v.visit_expr)(a, (e.clone(), v));
}
expr_copy(a) => (v.visit_expr)(a, (e.clone(), v)),
expr_assign_op(_, _, a, b) => {
(v.visit_expr)(b, (e.clone(), v));
(v.visit_expr)(a, (e.clone(), v));