@@ -21,7 +21,6 @@ use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow};
21
21
use rustc:: ty:: cast:: CastKind as TyCastKind ;
22
22
use rustc:: ty:: subst:: Subst ;
23
23
use rustc:: hir;
24
- use syntax:: ptr:: P ;
25
24
26
25
impl < ' tcx > Mirror < ' tcx > for & ' tcx hir:: Expr {
27
26
type Output = Expr < ' tcx > ;
@@ -117,13 +116,7 @@ fn apply_adjustment<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
117
116
} ,
118
117
} ;
119
118
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( ) ] )
127
120
}
128
121
Adjust :: Borrow ( AutoBorrow :: Ref ( r, m) ) => {
129
122
ExprKind :: Borrow {
@@ -281,17 +274,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
281
274
282
275
hir:: ExprAssignOp ( op, ref lhs, ref rhs) => {
283
276
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( ) ] )
295
278
} else {
296
279
ExprKind :: AssignOp {
297
280
op : bin_op ( op. node ) ,
@@ -305,17 +288,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
305
288
306
289
hir:: ExprBinary ( op, ref lhs, ref rhs) => {
307
290
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( ) ] )
319
292
} else {
320
293
// FIXME overflow
321
294
match ( op. node , cx. constness ) {
@@ -365,13 +338,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
365
338
366
339
hir:: ExprIndex ( ref lhs, ref index) => {
367
340
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( ) ] )
375
342
} else {
376
343
ExprKind :: Index {
377
344
lhs : lhs. to_ref ( ) ,
@@ -382,26 +349,15 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
382
349
383
350
hir:: ExprUnary ( hir:: UnOp :: UnDeref , ref arg) => {
384
351
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( ) ] )
392
353
} else {
393
354
ExprKind :: Deref { arg : arg. to_ref ( ) }
394
355
}
395
356
}
396
357
397
358
hir:: ExprUnary ( hir:: UnOp :: UnNot , ref arg) => {
398
359
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( ) ] )
405
361
} else {
406
362
ExprKind :: Unary {
407
363
op : UnOp :: Not ,
@@ -412,12 +368,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
412
368
413
369
hir:: ExprUnary ( hir:: UnOp :: UnNeg , ref arg) => {
414
370
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( ) ] )
421
372
} else {
422
373
// FIXME runtime-overflow
423
374
if let hir:: ExprLit ( _) = arg. node {
@@ -873,77 +824,29 @@ fn bin_op(op: hir::BinOp_) -> BinOp {
873
824
}
874
825
}
875
826
876
- enum PassArgs {
877
- ByValue ,
878
- ByRef ,
879
- }
880
-
881
827
fn overloaded_operator < ' a , ' gcx , ' tcx > ( cx : & mut Cx < ' a , ' gcx , ' tcx > ,
882
828
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 > > )
887
830
-> 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 ) ;
927
832
ExprKind :: Call {
928
833
ty : fun. ty ,
929
834
fun : fun. to_ref ( ) ,
930
- args : argrefs ,
835
+ args,
931
836
}
932
837
}
933
838
934
839
fn overloaded_lvalue < ' a , ' gcx , ' tcx > ( cx : & mut Cx < ' a , ' gcx , ' tcx > ,
935
840
expr : & ' tcx hir:: Expr ,
936
841
lvalue_ty : Ty < ' tcx > ,
937
842
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 > > )
941
844
-> ExprKind < ' tcx > {
942
845
// For an overloaded *x or x[y] expression of type T, the method
943
846
// call returns an &T and we must add the deref so that the types
944
847
// line up (this is because `*x` and `x[y]` represent lvalues):
945
848
946
- let recv_ty = match receiver {
849
+ let recv_ty = match args [ 0 ] {
947
850
ExprRef :: Hair ( e) => cx. tables ( ) . expr_ty_adjusted ( e) ,
948
851
ExprRef :: Mirror ( ref e) => e. ty
949
852
} ;
@@ -963,13 +866,17 @@ fn overloaded_lvalue<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
963
866
// construct the complete expression `foo()` for the overloaded call,
964
867
// which will yield the &T type
965
868
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) ;
967
870
let ref_expr = Expr {
968
871
temp_lifetime : temp_lifetime,
969
872
temp_lifetime_was_shrunk : was_shrunk,
970
873
ty : ref_ty,
971
874
span : expr. span ,
972
- kind : ref_kind,
875
+ kind : ExprKind :: Call {
876
+ ty : fun. ty ,
877
+ fun : fun. to_ref ( ) ,
878
+ args,
879
+ } ,
973
880
} ;
974
881
975
882
// construct and return a deref wrapper `*foo()`
0 commit comments