@@ -21,7 +21,7 @@ const HARD_CODED_ALLOWED_BINARY: &[[&str; 2]] = &[
21
21
[ "f64" , "f64" ] ,
22
22
[ "std::num::Saturating" , "std::num::Saturating" ] ,
23
23
[ "std::num::Wrapping" , "std::num::Wrapping" ] ,
24
- [ "std::string::String" , "& str" ] ,
24
+ [ "std::string::String" , "str" ] ,
25
25
] ;
26
26
const HARD_CODED_ALLOWED_UNARY : & [ & str ] = & [ "f32" , "f64" , "std::num::Saturating" , "std::num::Wrapping" ] ;
27
27
const INTEGER_METHODS : & [ & str ] = & [ "saturating_div" , "wrapping_div" , "wrapping_rem" , "wrapping_rem_euclid" ] ;
@@ -67,9 +67,17 @@ impl ArithmeticSideEffects {
67
67
/// "multiplication" are present in the inner set of allowed types.
68
68
fn has_allowed_binary ( & self , lhs_ty : Ty < ' _ > , rhs_ty : Ty < ' _ > ) -> bool {
69
69
let lhs_ty_string = lhs_ty. to_string ( ) ;
70
- let lhs_ty_string_elem = lhs_ty_string. split ( '<' ) . next ( ) . unwrap_or_default ( ) ;
70
+ let lhs_ty_string_elem = lhs_ty_string
71
+ . split ( '<' )
72
+ . next ( )
73
+ . unwrap_or_default ( )
74
+ . trim_start_matches ( '&' ) ;
71
75
let rhs_ty_string = rhs_ty. to_string ( ) ;
72
- let rhs_ty_string_elem = rhs_ty_string. split ( '<' ) . next ( ) . unwrap_or_default ( ) ;
76
+ let rhs_ty_string_elem = rhs_ty_string
77
+ . split ( '<' )
78
+ . next ( )
79
+ . unwrap_or_default ( )
80
+ . trim_start_matches ( '&' ) ;
73
81
if let Some ( rhs_from_specific) = self . allowed_binary . get ( lhs_ty_string_elem)
74
82
&& {
75
83
let rhs_has_allowed_ty = rhs_from_specific. contains ( rhs_ty_string_elem) ;
@@ -144,8 +152,10 @@ impl ArithmeticSideEffects {
144
152
) {
145
153
return ;
146
154
} ;
147
- let lhs_ty = cx. typeck_results ( ) . expr_ty ( lhs) ;
148
- let rhs_ty = cx. typeck_results ( ) . expr_ty ( rhs) ;
155
+ let ( actual_lhs, lhs_ref_counter) = peel_hir_expr_refs ( lhs) ;
156
+ let ( actual_rhs, rhs_ref_counter) = peel_hir_expr_refs ( rhs) ;
157
+ let lhs_ty = cx. typeck_results ( ) . expr_ty ( actual_lhs) ;
158
+ let rhs_ty = cx. typeck_results ( ) . expr_ty ( actual_rhs) ;
149
159
if self . has_allowed_binary ( lhs_ty, rhs_ty) {
150
160
return ;
151
161
}
@@ -154,8 +164,6 @@ impl ArithmeticSideEffects {
154
164
// At least for integers, shifts are already handled by the CTFE
155
165
return ;
156
166
}
157
- let ( actual_lhs, lhs_ref_counter) = peel_hir_expr_refs ( lhs) ;
158
- let ( actual_rhs, rhs_ref_counter) = peel_hir_expr_refs ( rhs) ;
159
167
match (
160
168
Self :: literal_integer ( cx, actual_lhs) ,
161
169
Self :: literal_integer ( cx, actual_rhs) ,
0 commit comments