@@ -35,21 +35,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3535 let ( lhs_ty, rhs_ty, return_ty) =
3636 self . check_overloaded_binop ( expr, lhs, rhs, op, IsAssign :: Yes , expected) ;
3737
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+ } ;
4547
4648 self . check_lhs_assignable ( lhs, E0067 , op. span , |err| {
4749 if let Some ( lhs_deref_ty) = self . deref_once_mutably_for_diagnostic ( lhs_ty) {
4850 if self
4951 . lookup_op_method (
5052 ( lhs, lhs_deref_ty) ,
5153 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 ) ,
5355 op. span ,
5456 expected,
5557 )
@@ -61,7 +63,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
6163 . lookup_op_method (
6264 ( lhs, lhs_ty) ,
6365 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 ) ,
6567 op. span ,
6668 expected,
6769 )
@@ -100,7 +102,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
100102 expr. hir_id, expr, op, lhs_expr, rhs_expr
101103 ) ;
102104
103- match BinOpCategory :: from ( op) {
105+ match BinOpCategory :: from ( op. node ) {
104106 BinOpCategory :: Shortcircuit => {
105107 // && and || are a simple case.
106108 self . check_expr_coercible_to_type ( lhs_expr, tcx. types . bool , None ) ;
@@ -139,14 +141,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
139141 // can't pin this down to a specific impl.
140142 if !lhs_ty. is_ty_var ( )
141143 && !rhs_ty. is_ty_var ( )
142- && is_builtin_binop ( lhs_ty, rhs_ty, op)
144+ && is_builtin_binop ( lhs_ty, rhs_ty, op. node )
143145 {
144146 let builtin_return_ty = self . enforce_builtin_binop_types (
145147 lhs_expr. span ,
146148 lhs_ty,
147149 rhs_expr. span ,
148150 rhs_ty,
149- op,
151+ op. node ,
150152 ) ;
151153 self . demand_eqtype ( expr. span , builtin_return_ty, return_ty) ;
152154 builtin_return_ty
@@ -163,7 +165,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
163165 lhs_ty : Ty < ' tcx > ,
164166 rhs_span : Span ,
165167 rhs_ty : Ty < ' tcx > ,
166- op : hir:: BinOp ,
168+ op : hir:: BinOpKind ,
167169 ) -> Ty < ' tcx > {
168170 debug_assert ! ( is_builtin_binop( lhs_ty, rhs_ty, op) ) ;
169171
@@ -244,7 +246,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
244246 let result = self . lookup_op_method (
245247 ( lhs_expr, lhs_ty) ,
246248 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) ,
248250 op. span ,
249251 expected,
250252 ) ;
@@ -255,7 +257,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
255257 rhs_ty_var,
256258 Some ( lhs_expr) ,
257259 |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 ) ;
259261 } ,
260262 ) ;
261263 let rhs_ty = self . resolve_vars_with_obligations ( rhs_ty) ;
@@ -304,7 +306,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
304306 Ty :: new_misc_error ( self . tcx )
305307 }
306308 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) ;
308310 let missing_trait = trait_def_id
309311 . map ( |def_id| with_no_trimmed_paths ! ( self . tcx. def_path_str( def_id) ) ) ;
310312 let mut path = None ;
@@ -411,7 +413,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
411413 . lookup_op_method (
412414 ( lhs_expr, lhs_deref_ty) ,
413415 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) ,
415417 op. span ,
416418 expected,
417419 )
@@ -445,7 +447,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
445447 . lookup_op_method (
446448 ( lhs_expr, lhs_adjusted_ty) ,
447449 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) ,
449451 op. span ,
450452 expected,
451453 )
@@ -503,7 +505,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
503505 self . lookup_op_method (
504506 ( lhs_expr, lhs_ty) ,
505507 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) ,
507509 op. span ,
508510 expected,
509511 )
@@ -597,7 +599,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
597599 . lookup_op_method (
598600 ( lhs_expr, lhs_ty) ,
599601 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) ,
601603 op. span ,
602604 expected,
603605 )
@@ -991,12 +993,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
991993
992994fn lang_item_for_binop (
993995 tcx : TyCtxt < ' _ > ,
994- op : hir:: BinOp ,
996+ op : hir:: BinOpKind ,
995997 is_assign : IsAssign ,
996998) -> ( Symbol , Option < hir:: def_id:: DefId > ) {
997999 let lang = tcx. lang_items ( ) ;
9981000 if is_assign == IsAssign :: Yes {
999- match op. node {
1001+ match op {
10001002 hir:: BinOpKind :: Add => ( sym:: add_assign, lang. add_assign_trait ( ) ) ,
10011003 hir:: BinOpKind :: Sub => ( sym:: sub_assign, lang. sub_assign_trait ( ) ) ,
10021004 hir:: BinOpKind :: Mul => ( sym:: mul_assign, lang. mul_assign_trait ( ) ) ,
@@ -1015,11 +1017,11 @@ fn lang_item_for_binop(
10151017 | hir:: BinOpKind :: Ne
10161018 | hir:: BinOpKind :: And
10171019 | hir:: BinOpKind :: Or => {
1018- bug ! ( "impossible assignment operation: {}=" , op. node . as_str( ) )
1020+ bug ! ( "impossible assignment operation: {}=" , op. as_str( ) )
10191021 }
10201022 }
10211023 } else {
1022- match op. node {
1024+ match op {
10231025 hir:: BinOpKind :: Add => ( sym:: add, lang. add_trait ( ) ) ,
10241026 hir:: BinOpKind :: Sub => ( sym:: sub, lang. sub_trait ( ) ) ,
10251027 hir:: BinOpKind :: Mul => ( sym:: mul, lang. mul_trait ( ) ) ,
@@ -1076,8 +1078,8 @@ enum BinOpCategory {
10761078}
10771079
10781080impl BinOpCategory {
1079- fn from ( op : hir:: BinOp ) -> BinOpCategory {
1080- match op. node {
1081+ fn from ( op : hir:: BinOpKind ) -> BinOpCategory {
1082+ match op {
10811083 hir:: BinOpKind :: Shl | hir:: BinOpKind :: Shr => BinOpCategory :: Shift ,
10821084
10831085 hir:: BinOpKind :: Add
@@ -1133,7 +1135,7 @@ fn deref_ty_if_possible(ty: Ty<'_>) -> Ty<'_> {
11331135/// Reason #2 is the killer. I tried for a while to always use
11341136/// overloaded logic and just check the types in constants/codegen after
11351137/// 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 {
11371139 // Special-case a single layer of referencing, so that things like `5.0 + &6.0f32` work.
11381140 // (See https://github.com/rust-lang/rust/issues/57447.)
11391141 let ( lhs, rhs) = ( deref_ty_if_possible ( lhs) , deref_ty_if_possible ( rhs) ) ;
0 commit comments