@@ -21,7 +21,6 @@ use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow};
2121use rustc:: ty:: cast:: CastKind as TyCastKind ;
2222use rustc:: ty:: subst:: Subst ;
2323use rustc:: hir;
24- use syntax:: ptr:: P ;
2524
2625impl < ' tcx > Mirror < ' tcx > for & ' tcx hir:: Expr {
2726 type Output = Expr < ' tcx > ;
@@ -117,13 +116,7 @@ fn apply_adjustment<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
117116 } ,
118117 } ;
119118
120- overloaded_lvalue ( cx,
121- hir_expr,
122- adjustment. target ,
123- Some ( call) ,
124- PassArgs :: ByValue ,
125- expr. to_ref ( ) ,
126- vec ! [ ] )
119+ overloaded_lvalue ( cx, hir_expr, adjustment. target , Some ( call) , vec ! [ expr. to_ref( ) ] )
127120 }
128121 Adjust :: Borrow ( AutoBorrow :: Ref ( r, m) ) => {
129122 ExprKind :: Borrow {
@@ -281,17 +274,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
281274
282275 hir:: ExprAssignOp ( op, ref lhs, ref rhs) => {
283276 if cx. tables ( ) . is_method_call ( expr) {
284- let pass_args = if op. node . is_by_value ( ) {
285- PassArgs :: ByValue
286- } else {
287- PassArgs :: ByRef
288- } ;
289- overloaded_operator ( cx,
290- expr,
291- None ,
292- pass_args,
293- lhs. to_ref ( ) ,
294- vec ! [ rhs] )
277+ overloaded_operator ( cx, expr, vec ! [ lhs. to_ref( ) , rhs. to_ref( ) ] )
295278 } else {
296279 ExprKind :: AssignOp {
297280 op : bin_op ( op. node ) ,
@@ -305,17 +288,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
305288
306289 hir:: ExprBinary ( op, ref lhs, ref rhs) => {
307290 if cx. tables ( ) . is_method_call ( expr) {
308- let pass_args = if op. node . is_by_value ( ) {
309- PassArgs :: ByValue
310- } else {
311- PassArgs :: ByRef
312- } ;
313- overloaded_operator ( cx,
314- expr,
315- None ,
316- pass_args,
317- lhs. to_ref ( ) ,
318- vec ! [ rhs] )
291+ overloaded_operator ( cx, expr, vec ! [ lhs. to_ref( ) , rhs. to_ref( ) ] )
319292 } else {
320293 // FIXME overflow
321294 match ( op. node , cx. constness ) {
@@ -365,13 +338,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
365338
366339 hir:: ExprIndex ( ref lhs, ref index) => {
367340 if cx. tables ( ) . is_method_call ( expr) {
368- overloaded_lvalue ( cx,
369- expr,
370- expr_ty,
371- None ,
372- PassArgs :: ByValue ,
373- lhs. to_ref ( ) ,
374- vec ! [ index] )
341+ overloaded_lvalue ( cx, expr, expr_ty, None , vec ! [ lhs. to_ref( ) , index. to_ref( ) ] )
375342 } else {
376343 ExprKind :: Index {
377344 lhs : lhs. to_ref ( ) ,
@@ -382,26 +349,15 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
382349
383350 hir:: ExprUnary ( hir:: UnOp :: UnDeref , ref arg) => {
384351 if cx. tables ( ) . is_method_call ( expr) {
385- overloaded_lvalue ( cx,
386- expr,
387- expr_ty,
388- None ,
389- PassArgs :: ByValue ,
390- arg. to_ref ( ) ,
391- vec ! [ ] )
352+ overloaded_lvalue ( cx, expr, expr_ty, None , vec ! [ arg. to_ref( ) ] )
392353 } else {
393354 ExprKind :: Deref { arg : arg. to_ref ( ) }
394355 }
395356 }
396357
397358 hir:: ExprUnary ( hir:: UnOp :: UnNot , ref arg) => {
398359 if cx. tables ( ) . is_method_call ( expr) {
399- overloaded_operator ( cx,
400- expr,
401- None ,
402- PassArgs :: ByValue ,
403- arg. to_ref ( ) ,
404- vec ! [ ] )
360+ overloaded_operator ( cx, expr, vec ! [ arg. to_ref( ) ] )
405361 } else {
406362 ExprKind :: Unary {
407363 op : UnOp :: Not ,
@@ -412,12 +368,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
412368
413369 hir:: ExprUnary ( hir:: UnOp :: UnNeg , ref arg) => {
414370 if cx. tables ( ) . is_method_call ( expr) {
415- overloaded_operator ( cx,
416- expr,
417- None ,
418- PassArgs :: ByValue ,
419- arg. to_ref ( ) ,
420- vec ! [ ] )
371+ overloaded_operator ( cx, expr, vec ! [ arg. to_ref( ) ] )
421372 } else {
422373 // FIXME runtime-overflow
423374 if let hir:: ExprLit ( _) = arg. node {
@@ -873,77 +824,29 @@ fn bin_op(op: hir::BinOp_) -> BinOp {
873824 }
874825}
875826
876- enum PassArgs {
877- ByValue ,
878- ByRef ,
879- }
880-
881827fn overloaded_operator < ' a , ' gcx , ' tcx > ( cx : & mut Cx < ' a , ' gcx , ' tcx > ,
882828 expr : & ' tcx hir:: Expr ,
883- custom_callee : Option < ( DefId , & ' tcx Substs < ' tcx > ) > ,
884- pass_args : PassArgs ,
885- receiver : ExprRef < ' tcx > ,
886- args : Vec < & ' tcx P < hir:: Expr > > )
829+ args : Vec < ExprRef < ' tcx > > )
887830 -> ExprKind < ' tcx > {
888- // the receiver has all the adjustments that are needed, so we can
889- // just push a reference to it
890- let mut argrefs = vec ! [ receiver] ;
891-
892- // the arguments, unfortunately, do not, so if this is a ByRef
893- // operator, we have to gin up the autorefs (but by value is easy)
894- match pass_args {
895- PassArgs :: ByValue => argrefs. extend ( args. iter ( ) . map ( |arg| arg. to_ref ( ) ) ) ,
896-
897- PassArgs :: ByRef => {
898- let region = cx. tcx . node_scope_region ( expr. id ) ;
899- let ( temp_lifetime, was_shrunk) =
900- cx. region_maps . temporary_scope2 ( expr. id ) ;
901- argrefs. extend ( args. iter ( )
902- . map ( |arg| {
903- let arg_ty = cx. tables ( ) . expr_ty_adjusted ( arg) ;
904- let adjusted_ty = cx. tcx . mk_ref ( region,
905- ty:: TypeAndMut {
906- ty : arg_ty,
907- mutbl : hir:: MutImmutable ,
908- } ) ;
909- Expr {
910- temp_lifetime : temp_lifetime,
911- temp_lifetime_was_shrunk : was_shrunk,
912- ty : adjusted_ty,
913- span : expr. span ,
914- kind : ExprKind :: Borrow {
915- region : region,
916- borrow_kind : BorrowKind :: Shared ,
917- arg : arg. to_ref ( ) ,
918- } ,
919- }
920- . to_ref ( )
921- } ) )
922- }
923- }
924-
925- // now create the call itself
926- let fun = method_callee ( cx, expr, custom_callee) ;
831+ let fun = method_callee ( cx, expr, None ) ;
927832 ExprKind :: Call {
928833 ty : fun. ty ,
929834 fun : fun. to_ref ( ) ,
930- args : argrefs ,
835+ args,
931836 }
932837}
933838
934839fn overloaded_lvalue < ' a , ' gcx , ' tcx > ( cx : & mut Cx < ' a , ' gcx , ' tcx > ,
935840 expr : & ' tcx hir:: Expr ,
936841 lvalue_ty : Ty < ' tcx > ,
937842 custom_callee : Option < ( DefId , & ' tcx Substs < ' tcx > ) > ,
938- pass_args : PassArgs ,
939- receiver : ExprRef < ' tcx > ,
940- args : Vec < & ' tcx P < hir:: Expr > > )
843+ args : Vec < ExprRef < ' tcx > > )
941844 -> ExprKind < ' tcx > {
942845 // For an overloaded *x or x[y] expression of type T, the method
943846 // call returns an &T and we must add the deref so that the types
944847 // line up (this is because `*x` and `x[y]` represent lvalues):
945848
946- let recv_ty = match receiver {
849+ let recv_ty = match args [ 0 ] {
947850 ExprRef :: Hair ( e) => cx. tables ( ) . expr_ty_adjusted ( e) ,
948851 ExprRef :: Mirror ( ref e) => e. ty
949852 } ;
@@ -963,13 +866,17 @@ fn overloaded_lvalue<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
963866 // construct the complete expression `foo()` for the overloaded call,
964867 // which will yield the &T type
965868 let ( temp_lifetime, was_shrunk) = cx. region_maps . temporary_scope2 ( expr. id ) ;
966- let ref_kind = overloaded_operator ( cx, expr, custom_callee, pass_args , receiver , args ) ;
869+ let fun = method_callee ( cx, expr, custom_callee) ;
967870 let ref_expr = Expr {
968871 temp_lifetime : temp_lifetime,
969872 temp_lifetime_was_shrunk : was_shrunk,
970873 ty : ref_ty,
971874 span : expr. span ,
972- kind : ref_kind,
875+ kind : ExprKind :: Call {
876+ ty : fun. ty ,
877+ fun : fun. to_ref ( ) ,
878+ args,
879+ } ,
973880 } ;
974881
975882 // construct and return a deref wrapper `*foo()`
0 commit comments