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