Skip to content

Commit 63c7e2f

Browse files
committed
Remove the '<->' operator from the language
1 parent 998fece commit 63c7e2f

File tree

18 files changed

+16
-128
lines changed

18 files changed

+16
-128
lines changed

doc/rust.md

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,35 +1946,6 @@ fn avg(v: &[float]) -> float {
19461946
}
19471947
~~~~
19481948

1949-
#### Swap expressions
1950-
1951-
A _swap expression_ consists of an [lvalue](#lvalues-rvalues-and-temporaries) followed by a bi-directional arrow (`<->`) and another [lvalue](#lvalues-rvalues-and-temporaries).
1952-
1953-
Evaluating a swap expression causes, as a side effect, the values held in the left-hand-side and right-hand-side [lvalues](#lvalues-rvalues-and-temporaries) to be exchanged indivisibly.
1954-
1955-
Evaluating a swap expression neither changes reference counts,
1956-
nor deeply copies any owned structure pointed to by the moved [rvalue](#lvalues-rvalues-and-temporaries).
1957-
Instead, the swap expression represents an indivisible *exchange of ownership*,
1958-
between the right-hand-side and the left-hand-side of the expression.
1959-
No allocation or destruction is entailed.
1960-
1961-
An example of three different swap expressions:
1962-
1963-
~~~~~~~~
1964-
# let mut x = &mut [0];
1965-
# let mut a = &mut [0];
1966-
# let i = 0;
1967-
# struct S1 { z: int };
1968-
# struct S2 { c: int };
1969-
# let mut y = S1{z: 0};
1970-
# let mut b = S2{c: 0};
1971-
1972-
x <-> a;
1973-
x[i] <-> a[i];
1974-
y.z <-> b.c;
1975-
~~~~~~~~
1976-
1977-
19781949
#### Assignment expressions
19791950

19801951
An _assignment expression_ consists of an [lvalue](#lvalues-rvalues-and-temporaries) expression followed by an
@@ -2015,7 +1986,7 @@ as
20151986
== !=
20161987
&&
20171988
||
2018-
= <->
1989+
=
20191990
~~~~
20201991

20211992
Operators at the same precedence level are evaluated left-to-right.

src/librustc/middle/borrowck/check_loans.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -758,10 +758,6 @@ fn check_loans_in_expr<'a>(expr: @ast::expr,
758758
}
759759

760760
match expr.node {
761-
ast::expr_swap(l, r) => {
762-
self.check_assignment(l);
763-
self.check_assignment(r);
764-
}
765761
ast::expr_assign(dest, _) |
766762
ast::expr_assign_op(_, dest, _) => {
767763
self.check_assignment(dest);

src/librustc/middle/dataflow.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -698,11 +698,6 @@ impl<'self, O:DataFlowOperator> PropagationContext<'self, O> {
698698
self.walk_expr(l, in_out, loop_scopes);
699699
}
700700

701-
ast::expr_swap(l, r) => {
702-
self.walk_expr(l, in_out, loop_scopes);
703-
self.walk_expr(r, in_out, loop_scopes);
704-
}
705-
706701
ast::expr_vec(ref exprs, _) => {
707702
self.walk_exprs(*exprs, in_out, loop_scopes)
708703
}

src/librustc/middle/liveness.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ fn visit_expr(expr: @expr, self: @mut IrMaps, vt: vt<@mut IrMaps>) {
523523
expr_binary(*) | expr_addr_of(*) | expr_copy(*) | expr_loop_body(*) |
524524
expr_do_body(*) | expr_cast(*) | expr_unary(*) | expr_break(_) |
525525
expr_again(_) | expr_lit(_) | expr_ret(*) | expr_block(*) |
526-
expr_assign(*) | expr_swap(*) | expr_assign_op(*) | expr_mac(*) |
526+
expr_assign(*) | expr_assign_op(*) | expr_mac(*) |
527527
expr_struct(*) | expr_repeat(*) | expr_paren(*) |
528528
expr_inline_asm(*) => {
529529
visit::visit_expr(expr, self, vt);
@@ -1141,21 +1141,6 @@ pub impl Liveness {
11411141
self.propagate_through_expr(r, succ)
11421142
}
11431143

1144-
expr_swap(l, r) => {
1145-
// see comment on lvalues in
1146-
// propagate_through_lvalue_components()
1147-
1148-
// I count swaps as `used` cause it might be something like:
1149-
// foo.bar <-> x
1150-
// and I am too lazy to distinguish this case from
1151-
// y <-> x
1152-
// (where both x, y are unused) just for a warning.
1153-
let succ = self.write_lvalue(r, succ, ACC_WRITE|ACC_READ|ACC_USE);
1154-
let succ = self.write_lvalue(l, succ, ACC_WRITE|ACC_READ|ACC_USE);
1155-
let succ = self.propagate_through_lvalue_components(r, succ);
1156-
self.propagate_through_lvalue_components(l, succ)
1157-
}
1158-
11591144
expr_assign_op(_, l, r) => {
11601145
// see comment on lvalues in
11611146
// propagate_through_lvalue_components()
@@ -1533,7 +1518,7 @@ fn check_expr(expr: @expr, self: @Liveness, vt: vt<@Liveness>) {
15331518
expr_vstore(*) | expr_vec(*) | expr_tup(*) | expr_log(*) |
15341519
expr_binary(*) | expr_copy(*) | expr_loop_body(*) | expr_do_body(*) |
15351520
expr_cast(*) | expr_unary(*) | expr_ret(*) | expr_break(*) |
1536-
expr_again(*) | expr_lit(_) | expr_block(*) | expr_swap(*) |
1521+
expr_again(*) | expr_lit(_) | expr_block(*) |
15371522
expr_mac(*) | expr_addr_of(*) | expr_struct(*) | expr_repeat(*) |
15381523
expr_paren(*) => {
15391524
visit::visit_expr(expr, self, vt);

src/librustc/middle/mem_categorization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ pub impl mem_categorization_ctxt {
413413

414414
ast::expr_paren(e) => self.cat_expr_unadjusted(e),
415415

416-
ast::expr_addr_of(*) | ast::expr_call(*) | ast::expr_swap(*) |
416+
ast::expr_addr_of(*) | ast::expr_call(*) |
417417
ast::expr_assign(*) | ast::expr_assign_op(*) |
418418
ast::expr_fn_block(*) | ast::expr_ret(*) | ast::expr_loop_body(*) |
419419
ast::expr_do_body(*) | ast::expr_unary(*) |

src/librustc/middle/moves.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -650,11 +650,6 @@ pub impl VisitContext {
650650
self.consume_expr(count, visitor);
651651
}
652652

653-
expr_swap(lhs, rhs) => {
654-
self.use_expr(lhs, Read, visitor);
655-
self.use_expr(rhs, Read, visitor);
656-
}
657-
658653
expr_loop_body(base) |
659654
expr_do_body(base) => {
660655
self.use_expr(base, comp_mode, visitor);

src/librustc/middle/trans/expr.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -528,33 +528,6 @@ fn trans_rvalue_stmt_unadjusted(bcx: block, expr: @ast::expr) -> block {
528528
return src_datum.store_to_datum(
529529
bcx, src.id, DROP_EXISTING, dst_datum);
530530
}
531-
ast::expr_swap(dst, src) => {
532-
let dst_datum = unpack_datum!(bcx, trans_lvalue(bcx, dst));
533-
let src_datum = unpack_datum!(bcx, trans_lvalue(bcx, src));
534-
535-
// If the source and destination are the same, then don't swap.
536-
// Avoids performing an overlapping memcpy
537-
let dst_datum_ref = dst_datum.to_ref_llval(bcx);
538-
let src_datum_ref = src_datum.to_ref_llval(bcx);
539-
let cmp = ICmp(bcx, lib::llvm::IntEQ,
540-
src_datum_ref,
541-
dst_datum_ref);
542-
543-
let swap_cx = base::sub_block(bcx, "swap");
544-
let next_cx = base::sub_block(bcx, "next");
545-
546-
CondBr(bcx, cmp, next_cx.llbb, swap_cx.llbb);
547-
548-
let scratch = scratch_datum(swap_cx, dst_datum.ty, false);
549-
550-
let swap_cx = dst_datum.move_to_datum(swap_cx, INIT, scratch);
551-
let swap_cx = src_datum.move_to_datum(swap_cx, INIT, dst_datum);
552-
let swap_cx = scratch.move_to_datum(swap_cx, INIT, src_datum);
553-
554-
Br(swap_cx, next_cx.llbb);
555-
556-
return next_cx;
557-
}
558531
ast::expr_assign_op(op, dst, src) => {
559532
return trans_assign_op(bcx, expr, op, dst, src);
560533
}

src/librustc/middle/trans/type_use.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ pub fn mark_for_expr(cx: Context, e: @expr) {
314314
}
315315
}
316316
}
317-
expr_assign(val, _) | expr_swap(val, _) | expr_assign_op(_, val, _) |
317+
expr_assign(val, _) | expr_assign_op(_, val, _) |
318318
expr_ret(Some(val)) => {
319319
node_type_needs(cx, use_repr, val.id);
320320
}

src/librustc/middle/ty.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3465,7 +3465,6 @@ pub fn expr_kind(tcx: ctxt,
34653465
ast::expr_while(*) |
34663466
ast::expr_loop(*) |
34673467
ast::expr_assign(*) |
3468-
ast::expr_swap(*) |
34693468
ast::expr_inline_asm(*) |
34703469
ast::expr_assign_op(*) => {
34713470
RvalueStmtExpr

src/librustc/middle/typeck/check/mod.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,20 +2460,6 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
24602460
fcx.write_nil(id);
24612461
}
24622462
}
2463-
ast::expr_swap(lhs, rhs) => {
2464-
check_assignment(fcx, lhs, rhs, id);
2465-
let lhs_ty = fcx.expr_ty(lhs);
2466-
let rhs_ty = fcx.expr_ty(rhs);
2467-
if ty::type_is_error(lhs_ty) || ty::type_is_error(rhs_ty) {
2468-
fcx.write_error(id);
2469-
}
2470-
else if ty::type_is_bot(lhs_ty) || ty::type_is_bot(rhs_ty) {
2471-
fcx.write_bot(id);
2472-
}
2473-
else {
2474-
fcx.write_nil(id);
2475-
}
2476-
}
24772463
ast::expr_if(cond, ref thn, elsopt) => {
24782464
check_expr_has_type(fcx, cond, ty::mk_bool());
24792465
check_then_else(fcx, thn, elsopt, id, expr.span);

0 commit comments

Comments
 (0)