11//! This module contains functions to generate default trait impl function bodies where possible.
22
33use syntax:: {
4- ast:: { self , edit:: AstNodeEdit , make, AstNode , NameOwner } ,
4+ ast:: { self , edit:: AstNodeEdit , make, AstNode , BinaryOp , CmpOp , LogicOp , NameOwner } ,
55 ted,
66} ;
77
@@ -325,7 +325,7 @@ fn gen_hash_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
325325fn gen_partial_eq ( adt : & ast:: Adt , func : & ast:: Fn ) -> Option < ( ) > {
326326 fn gen_eq_chain ( expr : Option < ast:: Expr > , cmp : ast:: Expr ) -> Option < ast:: Expr > {
327327 match expr {
328- Some ( expr) => Some ( make:: expr_op ( ast :: BinOp :: BooleanAnd , expr , cmp) ) ,
328+ Some ( expr) => Some ( make:: expr_bin_op ( expr , BinaryOp :: LogicOp ( LogicOp :: And ) , cmp) ) ,
329329 None => Some ( cmp) ,
330330 }
331331 }
@@ -362,7 +362,8 @@ fn gen_partial_eq(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
362362 let lhs = make:: expr_call ( make_discriminant ( ) ?, make:: arg_list ( Some ( lhs_name. clone ( ) ) ) ) ;
363363 let rhs_name = make:: expr_path ( make:: ext:: ident_path ( "other" ) ) ;
364364 let rhs = make:: expr_call ( make_discriminant ( ) ?, make:: arg_list ( Some ( rhs_name. clone ( ) ) ) ) ;
365- let eq_check = make:: expr_op ( ast:: BinOp :: EqualityTest , lhs, rhs) ;
365+ let eq_check =
366+ make:: expr_bin_op ( lhs, BinaryOp :: CmpOp ( CmpOp :: Eq { negated : false } ) , rhs) ;
366367
367368 let mut case_count = 0 ;
368369 let mut arms = vec ! [ ] ;
@@ -386,7 +387,11 @@ fn gen_partial_eq(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
386387
387388 let lhs = make:: expr_path ( make:: ext:: ident_path ( l_name) ) ;
388389 let rhs = make:: expr_path ( make:: ext:: ident_path ( r_name) ) ;
389- let cmp = make:: expr_op ( ast:: BinOp :: EqualityTest , lhs, rhs) ;
390+ let cmp = make:: expr_bin_op (
391+ lhs,
392+ BinaryOp :: CmpOp ( CmpOp :: Eq { negated : false } ) ,
393+ rhs,
394+ ) ;
390395 expr = gen_eq_chain ( expr, cmp) ;
391396 }
392397
@@ -415,7 +420,11 @@ fn gen_partial_eq(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
415420
416421 let lhs = make:: expr_path ( make:: ext:: ident_path ( & l_name) ) ;
417422 let rhs = make:: expr_path ( make:: ext:: ident_path ( & r_name) ) ;
418- let cmp = make:: expr_op ( ast:: BinOp :: EqualityTest , lhs, rhs) ;
423+ let cmp = make:: expr_bin_op (
424+ lhs,
425+ BinaryOp :: CmpOp ( CmpOp :: Eq { negated : false } ) ,
426+ rhs,
427+ ) ;
419428 expr = gen_eq_chain ( expr, cmp) ;
420429 }
421430
@@ -455,7 +464,8 @@ fn gen_partial_eq(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
455464 let lhs = make:: expr_field ( lhs, & field. name ( ) ?. to_string ( ) ) ;
456465 let rhs = make:: expr_path ( make:: ext:: ident_path ( "other" ) ) ;
457466 let rhs = make:: expr_field ( rhs, & field. name ( ) ?. to_string ( ) ) ;
458- let cmp = make:: expr_op ( ast:: BinOp :: EqualityTest , lhs, rhs) ;
467+ let cmp =
468+ make:: expr_bin_op ( lhs, BinaryOp :: CmpOp ( CmpOp :: Eq { negated : false } ) , rhs) ;
459469 expr = gen_eq_chain ( expr, cmp) ;
460470 }
461471 make:: block_expr ( None , expr) . indent ( ast:: edit:: IndentLevel ( 1 ) )
@@ -469,7 +479,8 @@ fn gen_partial_eq(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
469479 let lhs = make:: expr_field ( lhs, & idx) ;
470480 let rhs = make:: expr_path ( make:: ext:: ident_path ( "other" ) ) ;
471481 let rhs = make:: expr_field ( rhs, & idx) ;
472- let cmp = make:: expr_op ( ast:: BinOp :: EqualityTest , lhs, rhs) ;
482+ let cmp =
483+ make:: expr_bin_op ( lhs, BinaryOp :: CmpOp ( CmpOp :: Eq { negated : false } ) , rhs) ;
473484 expr = gen_eq_chain ( expr, cmp) ;
474485 }
475486 make:: block_expr ( None , expr) . indent ( ast:: edit:: IndentLevel ( 1 ) )
0 commit comments