@@ -3356,14 +3356,15 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
3356
3356
trait_did : Option < ast:: DefId > ,
3357
3357
ex : & ast:: Expr ,
3358
3358
rhs_expr : & ast:: Expr ,
3359
- rhs_t : Ty < ' tcx > ) -> Ty < ' tcx > {
3359
+ rhs_t : Ty < ' tcx > ,
3360
+ op : ast:: UnOp ) -> Ty < ' tcx > {
3360
3361
lookup_op_method ( fcx, ex, rhs_t, token:: intern ( mname) ,
3361
3362
trait_did, rhs_expr, None , || {
3362
3363
fcx. type_error_message ( ex. span , |actual| {
3363
3364
format ! ( "cannot apply unary operator `{}` to type `{}`" ,
3364
3365
op_str, actual)
3365
3366
} , rhs_t, None ) ;
3366
- } , AutorefArgs :: No )
3367
+ } , if ast_util :: is_by_value_unop ( op ) { AutorefArgs :: No } else { AutorefArgs :: Yes } )
3367
3368
}
3368
3369
3369
3370
// Check field access expressions
@@ -3803,7 +3804,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
3803
3804
oprnd_t. sty == ty:: ty_bool) {
3804
3805
oprnd_t = check_user_unop ( fcx, "!" , "not" ,
3805
3806
tcx. lang_items . not_trait ( ) ,
3806
- expr, & * * oprnd, oprnd_t) ;
3807
+ expr, & * * oprnd, oprnd_t, unop ) ;
3807
3808
}
3808
3809
}
3809
3810
ast:: UnNeg => {
@@ -3813,7 +3814,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
3813
3814
ty:: type_is_fp ( oprnd_t) ) {
3814
3815
oprnd_t = check_user_unop ( fcx, "-" , "neg" ,
3815
3816
tcx. lang_items . neg_trait ( ) ,
3816
- expr, & * * oprnd, oprnd_t) ;
3817
+ expr, & * * oprnd, oprnd_t, unop ) ;
3817
3818
}
3818
3819
}
3819
3820
}
0 commit comments