@@ -36,21 +36,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
36
36
let ( lhs_ty, rhs_ty, return_ty) =
37
37
self . check_overloaded_binop ( expr, lhs, rhs, op, IsAssign :: Yes , expected) ;
38
38
39
- let ty =
40
- if !lhs_ty. is_ty_var ( ) && !rhs_ty. is_ty_var ( ) && is_builtin_binop ( lhs_ty, rhs_ty, op) {
41
- self . enforce_builtin_binop_types ( lhs. span , lhs_ty, rhs. span , rhs_ty, op) ;
42
- self . tcx . types . unit
43
- } else {
44
- return_ty
45
- } ;
39
+ let ty = if !lhs_ty. is_ty_var ( )
40
+ && !rhs_ty. is_ty_var ( )
41
+ && is_builtin_binop ( lhs_ty, rhs_ty, op. node )
42
+ {
43
+ self . enforce_builtin_binop_types ( lhs. span , lhs_ty, rhs. span , rhs_ty, op. node ) ;
44
+ self . tcx . types . unit
45
+ } else {
46
+ return_ty
47
+ } ;
46
48
47
49
self . check_lhs_assignable ( lhs, E0067 , op. span , |err| {
48
50
if let Some ( lhs_deref_ty) = self . deref_once_mutably_for_diagnostic ( lhs_ty) {
49
51
if self
50
52
. lookup_op_method (
51
53
( lhs, lhs_deref_ty) ,
52
54
Some ( ( rhs, rhs_ty) ) ,
53
- lang_item_for_binop ( self . tcx , op, IsAssign :: Yes ) ,
55
+ lang_item_for_binop ( self . tcx , op. node , IsAssign :: Yes ) ,
54
56
op. span ,
55
57
expected,
56
58
)
@@ -62,7 +64,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
62
64
. lookup_op_method (
63
65
( lhs, lhs_ty) ,
64
66
Some ( ( rhs, rhs_ty) ) ,
65
- lang_item_for_binop ( self . tcx , op, IsAssign :: Yes ) ,
67
+ lang_item_for_binop ( self . tcx , op. node , IsAssign :: Yes ) ,
66
68
op. span ,
67
69
expected,
68
70
)
@@ -101,7 +103,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
101
103
expr. hir_id, expr, op, lhs_expr, rhs_expr
102
104
) ;
103
105
104
- match BinOpCategory :: from ( op) {
106
+ match BinOpCategory :: from ( op. node ) {
105
107
BinOpCategory :: Shortcircuit => {
106
108
// && and || are a simple case.
107
109
self . check_expr_coercible_to_type ( lhs_expr, tcx. types . bool , None ) ;
@@ -140,14 +142,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
140
142
// can't pin this down to a specific impl.
141
143
if !lhs_ty. is_ty_var ( )
142
144
&& !rhs_ty. is_ty_var ( )
143
- && is_builtin_binop ( lhs_ty, rhs_ty, op)
145
+ && is_builtin_binop ( lhs_ty, rhs_ty, op. node )
144
146
{
145
147
let builtin_return_ty = self . enforce_builtin_binop_types (
146
148
lhs_expr. span ,
147
149
lhs_ty,
148
150
rhs_expr. span ,
149
151
rhs_ty,
150
- op,
152
+ op. node ,
151
153
) ;
152
154
self . demand_eqtype ( expr. span , builtin_return_ty, return_ty) ;
153
155
builtin_return_ty
@@ -164,7 +166,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
164
166
lhs_ty : Ty < ' tcx > ,
165
167
rhs_span : Span ,
166
168
rhs_ty : Ty < ' tcx > ,
167
- op : hir:: BinOp ,
169
+ op : hir:: BinOpKind ,
168
170
) -> Ty < ' tcx > {
169
171
debug_assert ! ( is_builtin_binop( lhs_ty, rhs_ty, op) ) ;
170
172
@@ -245,7 +247,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
245
247
let result = self . lookup_op_method (
246
248
( lhs_expr, lhs_ty) ,
247
249
Some ( ( rhs_expr, rhs_ty_var) ) ,
248
- lang_item_for_binop ( self . tcx , op, is_assign) ,
250
+ lang_item_for_binop ( self . tcx , op. node , is_assign) ,
249
251
op. span ,
250
252
expected,
251
253
) ;
@@ -256,7 +258,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
256
258
rhs_ty_var,
257
259
Some ( lhs_expr) ,
258
260
|err, ty| {
259
- self . suggest_swapping_lhs_and_rhs ( err, ty, lhs_ty, rhs_expr, lhs_expr, op) ;
261
+ self . suggest_swapping_lhs_and_rhs ( err, ty, lhs_ty, rhs_expr, lhs_expr, op. node ) ;
260
262
} ,
261
263
) ;
262
264
let rhs_ty = self . resolve_vars_with_obligations ( rhs_ty) ;
@@ -305,7 +307,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
305
307
Ty :: new_misc_error ( self . tcx )
306
308
}
307
309
Err ( errors) => {
308
- let ( _, trait_def_id) = lang_item_for_binop ( self . tcx , op, is_assign) ;
310
+ let ( _, trait_def_id) = lang_item_for_binop ( self . tcx , op. node , is_assign) ;
309
311
let missing_trait = trait_def_id
310
312
. map ( |def_id| with_no_trimmed_paths ! ( self . tcx. def_path_str( def_id) ) ) ;
311
313
let mut path = None ;
@@ -412,7 +414,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
412
414
. lookup_op_method (
413
415
( lhs_expr, lhs_deref_ty) ,
414
416
Some ( ( rhs_expr, rhs_ty) ) ,
415
- lang_item_for_binop ( self . tcx , op, is_assign) ,
417
+ lang_item_for_binop ( self . tcx , op. node , is_assign) ,
416
418
op. span ,
417
419
expected,
418
420
)
@@ -446,7 +448,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
446
448
. lookup_op_method (
447
449
( lhs_expr, lhs_adjusted_ty) ,
448
450
Some ( ( rhs_expr, rhs_adjusted_ty) ) ,
449
- lang_item_for_binop ( self . tcx , op, is_assign) ,
451
+ lang_item_for_binop ( self . tcx , op. node , is_assign) ,
450
452
op. span ,
451
453
expected,
452
454
)
@@ -504,7 +506,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
504
506
self . lookup_op_method (
505
507
( lhs_expr, lhs_ty) ,
506
508
Some ( ( rhs_expr, rhs_ty) ) ,
507
- lang_item_for_binop ( self . tcx , op, is_assign) ,
509
+ lang_item_for_binop ( self . tcx , op. node , is_assign) ,
508
510
op. span ,
509
511
expected,
510
512
)
@@ -598,7 +600,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
598
600
. lookup_op_method (
599
601
( lhs_expr, lhs_ty) ,
600
602
Some ( ( rhs_expr, rhs_ty) ) ,
601
- lang_item_for_binop ( self . tcx , op, is_assign) ,
603
+ lang_item_for_binop ( self . tcx , op. node , is_assign) ,
602
604
op. span ,
603
605
expected,
604
606
)
@@ -992,12 +994,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
992
994
993
995
fn lang_item_for_binop (
994
996
tcx : TyCtxt < ' _ > ,
995
- op : hir:: BinOp ,
997
+ op : hir:: BinOpKind ,
996
998
is_assign : IsAssign ,
997
999
) -> ( Symbol , Option < hir:: def_id:: DefId > ) {
998
1000
let lang = tcx. lang_items ( ) ;
999
1001
if is_assign == IsAssign :: Yes {
1000
- match op. node {
1002
+ match op {
1001
1003
hir:: BinOpKind :: Add => ( sym:: add_assign, lang. add_assign_trait ( ) ) ,
1002
1004
hir:: BinOpKind :: Sub => ( sym:: sub_assign, lang. sub_assign_trait ( ) ) ,
1003
1005
hir:: BinOpKind :: Mul => ( sym:: mul_assign, lang. mul_assign_trait ( ) ) ,
@@ -1016,11 +1018,11 @@ fn lang_item_for_binop(
1016
1018
| hir:: BinOpKind :: Ne
1017
1019
| hir:: BinOpKind :: And
1018
1020
| hir:: BinOpKind :: Or => {
1019
- bug ! ( "impossible assignment operation: {}=" , op. node . as_str( ) )
1021
+ bug ! ( "impossible assignment operation: {}=" , op. as_str( ) )
1020
1022
}
1021
1023
}
1022
1024
} else {
1023
- match op. node {
1025
+ match op {
1024
1026
hir:: BinOpKind :: Add => ( sym:: add, lang. add_trait ( ) ) ,
1025
1027
hir:: BinOpKind :: Sub => ( sym:: sub, lang. sub_trait ( ) ) ,
1026
1028
hir:: BinOpKind :: Mul => ( sym:: mul, lang. mul_trait ( ) ) ,
@@ -1077,8 +1079,8 @@ enum BinOpCategory {
1077
1079
}
1078
1080
1079
1081
impl BinOpCategory {
1080
- fn from ( op : hir:: BinOp ) -> BinOpCategory {
1081
- match op. node {
1082
+ fn from ( op : hir:: BinOpKind ) -> BinOpCategory {
1083
+ match op {
1082
1084
hir:: BinOpKind :: Shl | hir:: BinOpKind :: Shr => BinOpCategory :: Shift ,
1083
1085
1084
1086
hir:: BinOpKind :: Add
@@ -1134,7 +1136,7 @@ fn deref_ty_if_possible(ty: Ty<'_>) -> Ty<'_> {
1134
1136
/// Reason #2 is the killer. I tried for a while to always use
1135
1137
/// overloaded logic and just check the types in constants/codegen after
1136
1138
/// the fact, and it worked fine, except for SIMD types. -nmatsakis
1137
- fn is_builtin_binop < ' tcx > ( lhs : Ty < ' tcx > , rhs : Ty < ' tcx > , op : hir:: BinOp ) -> bool {
1139
+ fn is_builtin_binop < ' tcx > ( lhs : Ty < ' tcx > , rhs : Ty < ' tcx > , op : hir:: BinOpKind ) -> bool {
1138
1140
// Special-case a single layer of referencing, so that things like `5.0 + &6.0f32` work.
1139
1141
// (See https://github.com/rust-lang/rust/issues/57447.)
1140
1142
let ( lhs, rhs) = ( deref_ty_if_possible ( lhs) , deref_ty_if_possible ( rhs) ) ;
0 commit comments