Skip to content

Commit c95d42f

Browse files
author
Jorge Aparicio
committed
take RHS by value
1 parent c008919 commit c95d42f

File tree

7 files changed

+29
-36
lines changed

7 files changed

+29
-36
lines changed

src/libcore/ops.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -885,79 +885,79 @@ shr_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
885885
#[lang = "add_assign"]
886886
pub trait AddAssign<Rhs=Self> {
887887
/// `+=`
888-
fn add_assign(&mut self, &Rhs);
888+
fn add_assign(&mut self, Rhs);
889889
}
890890

891891
#[cfg(not(stage0))]
892892
/// `&=`
893893
#[lang = "bitand_assign"]
894894
pub trait BitAndAssign<Rhs=Self> {
895895
/// `&=`
896-
fn bitand_assign(&mut self, &Rhs);
896+
fn bitand_assign(&mut self, Rhs);
897897
}
898898

899899
#[cfg(not(stage0))]
900900
/// `|=`
901901
#[lang = "bitor_assign"]
902902
pub trait BitOrAssign<Rhs=Self> {
903903
/// `|=`
904-
fn bitor_assign(&mut self, &Rhs);
904+
fn bitor_assign(&mut self, Rhs);
905905
}
906906

907907
#[cfg(not(stage0))]
908908
/// `^=`
909909
#[lang = "bitxor_assign"]
910910
pub trait BitXorAssign<Rhs=Self> {
911911
/// `^=`
912-
fn bitxor_assign(&mut self, &Rhs);
912+
fn bitxor_assign(&mut self, Rhs);
913913
}
914914

915915
#[cfg(not(stage0))]
916916
/// `/=`
917917
#[lang = "div_assign"]
918918
pub trait DivAssign<Rhs=Self> {
919919
/// `/=`
920-
fn div_assign(&mut self, &Rhs);
920+
fn div_assign(&mut self, Rhs);
921921
}
922922

923923
#[cfg(not(stage0))]
924924
/// `*=`
925925
#[lang = "mul_assign"]
926926
pub trait MulAssign<Rhs=Self> {
927927
/// `*=`
928-
fn mul_assign(&mut self, &Rhs);
928+
fn mul_assign(&mut self, Rhs);
929929
}
930930

931931
#[cfg(not(stage0))]
932932
/// `%=`
933933
#[lang = "rem_assign"]
934934
pub trait RemAssign<Rhs=Self> {
935935
/// `%=`
936-
fn rem_assign(&mut self, &Rhs);
936+
fn rem_assign(&mut self, Rhs);
937937
}
938938

939939
#[cfg(not(stage0))]
940940
/// `<<=`
941941
#[lang = "shl_assign"]
942942
pub trait ShlAssign<Rhs> {
943943
/// `<<=`
944-
fn shl_assign(&mut self, &Rhs);
944+
fn shl_assign(&mut self, Rhs);
945945
}
946946

947947
#[cfg(not(stage0))]
948948
/// `>>=`
949949
#[lang = "shr_assign"]
950950
pub trait ShrAssign<Rhs> {
951951
/// `>>=`
952-
fn shr_assign(&mut self, &Rhs);
952+
fn shr_assign(&mut self, Rhs);
953953
}
954954

955955
#[cfg(not(stage0))]
956956
/// `-=`
957957
#[lang = "sub_assign"]
958958
pub trait SubAssign<Rhs=Self> {
959959
/// `-=`
960-
fn sub_assign(&mut self, &Rhs);
960+
fn sub_assign(&mut self, Rhs);
961961
}
962962

963963
/// The `Index` trait is used to specify the functionality of indexing operations

src/librustc/middle/expr_use_visitor.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -585,14 +585,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
585585

586586
ast::ExprAssignOp(_, ref lhs, ref rhs) => {
587587
self.mutate_expr(expr, &**lhs, WriteAndRead);
588-
589-
if self.typer.is_method_call(expr.id) {
590-
let r = ty::ReScope(region::CodeExtent::from_node_id(expr.id));
591-
self.borrow_expr(rhs, r, ty::ImmBorrow, OverloadedOperator);
592-
} else {
593-
// built-in assignment operations consume the RHS
594-
self.consume_expr(&**rhs);
595-
}
588+
self.consume_expr(&**rhs);
596589
}
597590

598591
ast::ExprRepeat(ref base, ref count) => {

src/librustc_trans/trans/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ fn trans_rvalue_stmt_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
10481048
let src_datum = unpack_datum!(bcx, trans(bcx, &**src));
10491049
trans_overloaded_op(bcx, expr, MethodCall::expr(expr.id), dst,
10501050
vec![(src_datum, src.id)], None,
1051-
true).bcx
1051+
false).bcx
10521052
}
10531053
}
10541054
ast::ExprInlineAsm(ref a) => {

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3087,7 +3087,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
30873087
ast_util::binop_to_string(op.node),
30883088
actual)
30893089
}, lhs_resolved_t, None)
3090-
}, AutorefArgs::Yes)
3090+
}, AutorefArgs::No)
30913091
}
30923092

30933093
fn check_user_unop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,

src/test/compile-fail/feature-gate-op-assign.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::ops::AddAssign;
1313
struct MyInt(i32);
1414

1515
impl AddAssign for MyInt {
16-
fn add_assign(&mut self, rhs: &MyInt) {
16+
fn add_assign(&mut self, rhs: MyInt) {
1717
self.0 += rhs.0
1818
}
1919
}

src/test/compile-fail/op-assign-borrow.rs src/test/compile-fail/op-assign-move.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ use std::ops::AddAssign;
1515
struct Int(i32);
1616

1717
impl AddAssign for Int {
18-
fn add_assign(&mut self, rhs: &Int) {
18+
fn add_assign(&mut self, rhs: Int) {
1919
self.0 += rhs.0
2020
}
2121
}
2222

2323
fn main() {
2424
let mut x = Int(1);
25-
x //~ error: cannot borrow `x` as mutable because it is also borrowed as immutable
25+
x //~ error: use of moved value: `x`
2626
+=
27-
x; //~ note: previous borrow of `x` occurs here
27+
x; //~ note: `x` moved here because it has type `Int`, which is non-copyable
2828

2929
let y = Int(2);
3030
y //~ error: cannot borrow immutable local variable `y` as mutable

src/test/run-pass/op-assign.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -65,73 +65,73 @@ fn main() {
6565
}
6666

6767
impl AddAssign for Int {
68-
fn add_assign(&mut self, rhs: &Int) {
68+
fn add_assign(&mut self, rhs: Int) {
6969
self.0 += rhs.0;
7070
}
7171
}
7272

7373
impl BitAndAssign for Int {
74-
fn bitand_assign(&mut self, rhs: &Int) {
74+
fn bitand_assign(&mut self, rhs: Int) {
7575
self.0 &= rhs.0;
7676
}
7777
}
7878

7979
impl BitOrAssign for Int {
80-
fn bitor_assign(&mut self, rhs: &Int) {
80+
fn bitor_assign(&mut self, rhs: Int) {
8181
self.0 |= rhs.0;
8282
}
8383
}
8484

8585
impl BitXorAssign for Int {
86-
fn bitxor_assign(&mut self, rhs: &Int) {
86+
fn bitxor_assign(&mut self, rhs: Int) {
8787
self.0 ^= rhs.0;
8888
}
8989
}
9090

9191
impl DivAssign for Int {
92-
fn div_assign(&mut self, rhs: &Int) {
92+
fn div_assign(&mut self, rhs: Int) {
9393
self.0 /= rhs.0;
9494
}
9595
}
9696

9797
impl MulAssign for Int {
98-
fn mul_assign(&mut self, rhs: &Int) {
98+
fn mul_assign(&mut self, rhs: Int) {
9999
self.0 *= rhs.0;
100100
}
101101
}
102102

103103
impl RemAssign for Int {
104-
fn rem_assign(&mut self, rhs: &Int) {
104+
fn rem_assign(&mut self, rhs: Int) {
105105
self.0 %= rhs.0;
106106
}
107107
}
108108

109109
impl ShlAssign<u8> for Int {
110-
fn shl_assign(&mut self, &rhs: &u8) {
110+
fn shl_assign(&mut self, rhs: u8) {
111111
self.0 <<= rhs;
112112
}
113113
}
114114

115115
impl ShlAssign<u16> for Int {
116-
fn shl_assign(&mut self, &rhs: &u16) {
116+
fn shl_assign(&mut self, rhs: u16) {
117117
self.0 <<= rhs;
118118
}
119119
}
120120

121121
impl ShrAssign<u8> for Int {
122-
fn shr_assign(&mut self, &rhs: &u8) {
122+
fn shr_assign(&mut self, rhs: u8) {
123123
self.0 >>= rhs;
124124
}
125125
}
126126

127127
impl ShrAssign<u16> for Int {
128-
fn shr_assign(&mut self, &rhs: &u16) {
128+
fn shr_assign(&mut self, rhs: u16) {
129129
self.0 >>= rhs;
130130
}
131131
}
132132

133133
impl SubAssign for Int {
134-
fn sub_assign(&mut self, rhs: &Int) {
134+
fn sub_assign(&mut self, rhs: Int) {
135135
self.0 -= rhs.0;
136136
}
137137
}

0 commit comments

Comments
 (0)