File tree 3 files changed +166
-125
lines changed
clippy_lints/src/operators
3 files changed +166
-125
lines changed Original file line number Diff line number Diff line change @@ -220,7 +220,7 @@ impl ArithmeticSideEffects {
220
220
actual_lhs = expr_or_init ( cx, actual_lhs) ;
221
221
actual_rhs = expr_or_init ( cx, actual_rhs) ;
222
222
let lhs_ty = cx. typeck_results ( ) . expr_ty ( actual_lhs) . peel_refs ( ) ;
223
- let rhs_ty = cx. typeck_results ( ) . expr_ty ( actual_rhs) . peel_refs ( ) ;
223
+ let rhs_ty = cx. typeck_results ( ) . expr_ty_adjusted ( actual_rhs) . peel_refs ( ) ;
224
224
if self . has_allowed_binary ( lhs_ty, rhs_ty) {
225
225
return ;
226
226
}
@@ -283,7 +283,7 @@ impl ArithmeticSideEffects {
283
283
if ConstEvalCtxt :: new ( cx) . eval_simple ( receiver) . is_some ( ) {
284
284
return ;
285
285
}
286
- let instance_ty = cx. typeck_results ( ) . expr_ty ( receiver) ;
286
+ let instance_ty = cx. typeck_results ( ) . expr_ty_adjusted ( receiver) ;
287
287
if !Self :: is_integral ( instance_ty) {
288
288
return ;
289
289
}
@@ -311,7 +311,7 @@ impl ArithmeticSideEffects {
311
311
if ConstEvalCtxt :: new ( cx) . eval ( un_expr) . is_some ( ) {
312
312
return ;
313
313
}
314
- let ty = cx. typeck_results ( ) . expr_ty ( expr) . peel_refs ( ) ;
314
+ let ty = cx. typeck_results ( ) . expr_ty_adjusted ( expr) . peel_refs ( ) ;
315
315
if self . has_allowed_unary ( ty) {
316
316
return ;
317
317
}
Original file line number Diff line number Diff line change @@ -170,6 +170,7 @@ pub fn hard_coded_allowed() {
170
170
171
171
let _ = Saturating ( 0u32 ) + Saturating ( 0u32 ) ;
172
172
let _ = String :: new ( ) + "" ;
173
+ let _ = String :: new ( ) + & String :: new ( ) ;
173
174
let _ = Wrapping ( 0u32 ) + Wrapping ( 0u32 ) ;
174
175
175
176
let saturating: Saturating < u32 > = Saturating ( 0u32 ) ;
@@ -408,11 +409,14 @@ pub fn unknown_ops_or_runtime_ops_that_can_overflow() {
408
409
_n. wrapping_rem ( _n) ;
409
410
_n. wrapping_rem_euclid ( _n) ;
410
411
412
+ _n. saturating_div ( * Box :: new ( _n) ) ;
413
+
411
414
// Unary
412
415
_n = -_n;
413
416
_n = -& _n;
414
417
_custom = -_custom;
415
418
_custom = -& _custom;
419
+ _ = -* Box :: new ( _n) ;
416
420
}
417
421
418
422
// Copied and pasted from the `integer_arithmetic` lint for comparison.
@@ -534,4 +538,11 @@ pub fn issue_12318() {
534
538
one. sub_assign ( 1 ) ;
535
539
}
536
540
541
+ pub fn explicit_methods ( ) {
542
+ use core:: ops:: Add ;
543
+ let one: i32 = 1 ;
544
+ one. add ( & one) ;
545
+ Box :: new ( one) . add ( one) ;
546
+ }
547
+
537
548
fn main ( ) { }
You can’t perform that action at this time.
0 commit comments