2 clippy::assign_op_pattern,
6 clippy::unnecessary_owned_empty_strings,
10 #![feature(const_mut_refs, inline_const, saturating_int_impl)]
11 #![warn(clippy::arithmetic_side_effects)]
13 use core::num::{Saturating, Wrapping};
17 macro_rules! impl_arith {
18 ( $( $_trait:ident, $ty:ty, $method:ident; )* ) => {
20 impl core::ops::$_trait<$ty> for Custom {
22 fn $method(self, _: $ty) -> Self::Output { Self }
40 pub fn association_with_structures_should_not_trigger_the_lint() {
53 struct Baz([i32; 1 + 1]);
56 const ASSOC: i32 = 1 + 1;
59 type Alias = [i32; 1 + 1];
65 let _: [i32; 1 + 1] = [0, 0];
67 let _: [i32; 1 + 1] = {
68 let a: [i32; 1 + 1] = [0, 0];
73 pub fn hard_coded_allowed() {
77 let _ = Saturating(0u32) + Saturating(0u32);
78 let _ = String::new() + "";
79 let _ = Wrapping(0u32) + Wrapping(0u32);
81 let saturating: Saturating<u32> = Saturating(0u32);
82 let string: String = String::new();
83 let wrapping: Wrapping<u32> = Wrapping(0u32);
85 let inferred_saturating = saturating + saturating;
86 let inferred_string = string + "";
87 let inferred_wrapping = wrapping + wrapping;
89 let _ = inferred_saturating + inferred_saturating;
90 let _ = inferred_string + "";
91 let _ = inferred_wrapping + inferred_wrapping;
95 pub fn const_ops_should_not_trigger_the_lint() {
96 const _: i32 = { let mut n = 1; n += 1; n };
97 let _ = const { let mut n = 1; n += 1; n };
99 const _: i32 = { let mut n = 1; n = n + 1; n };
100 let _ = const { let mut n = 1; n = n + 1; n };
102 const _: i32 = { let mut n = 1; n = 1 + n; n };
103 let _ = const { let mut n = 1; n = 1 + n; n };
105 const _: i32 = 1 + 1;
106 let _ = const { 1 + 1 };
108 const _: i32 = { let mut n = 1; n = -1; n = -(-1); n = -n; n };
109 let _ = const { let mut n = 1; n = -1; n = -(-1); n = -n; n };
112 pub fn non_overflowing_ops_or_ops_already_handled_by_the_compiler_should_not_trigger_the_lint() {
113 let mut _n = i32::MAX;
157 pub fn runtime_ops() {
158 let mut _n = i32::MAX;
197 let _ = Custom + 0.0;
198 let _ = Custom + 1.0;
199 let _ = Custom + 2.0;
203 let _ = Custom - 0.0;
204 let _ = Custom - 1.0;
205 let _ = Custom - 2.0;
209 let _ = Custom / 0.0;
210 let _ = Custom / 1.0;
211 let _ = Custom / 2.0;
215 let _ = Custom * 0.0;
216 let _ = Custom * 1.0;
217 let _ = Custom * 2.0;