]>
Commit | Line | Data |
---|---|---|
781aab86 | 1 | //@aux-build:proc_macros.rs |
136023e0 | 2 | |
f20569fa | 3 | #![warn(clippy::default_numeric_fallback)] |
04454e1e FG |
4 | #![allow( |
5 | unused, | |
6 | clippy::never_loop, | |
7 | clippy::no_effect, | |
8 | clippy::unnecessary_operation, | |
9 | clippy::branches_sharing_code, | |
10 | clippy::match_single_binding, | |
353b0b11 FG |
11 | clippy::let_unit_value, |
12 | clippy::let_with_type_underscore | |
04454e1e | 13 | )] |
136023e0 | 14 | |
353b0b11 FG |
15 | extern crate proc_macros; |
16 | use proc_macros::{external, inline_macros}; | |
f20569fa XL |
17 | |
18 | mod basic_expr { | |
19 | fn test() { | |
f20569fa | 20 | // Should lint unsuffixed literals typed `f64`. |
136023e0 XL |
21 | let x = 0.12_f64; |
22 | let x = [1.0_f64, 2.0_f64, 3.0_f64]; | |
23 | let x = if true { (1.0_f64, 2.0_f64) } else { (3.0_f64, 4.0_f64) }; | |
24 | let x = match 1.0_f64 { | |
25 | _ => 1.0_f64, | |
26 | }; | |
f20569fa XL |
27 | |
28 | // Should NOT lint suffixed literals. | |
f20569fa XL |
29 | let x = 0.12_f64; |
30 | ||
31 | // Should NOT lint literals in init expr if `Local` has a type annotation. | |
32 | let x: f64 = 0.1; | |
136023e0 XL |
33 | let x: [f64; 3] = [1., 2., 3.]; |
34 | let x: (f64, f64) = if true { (1., 2.) } else { (3., 4.) }; | |
35 | let x: _ = 1.; | |
2b03887a | 36 | const X: f32 = 1.; |
f20569fa XL |
37 | } |
38 | } | |
39 | ||
40 | mod nested_local { | |
41 | fn test() { | |
42 | let x: _ = { | |
43 | // Should lint this because this literal is not bound to any types. | |
136023e0 | 44 | let y = 1.0_f64; |
f20569fa XL |
45 | |
46 | // Should NOT lint this because this literal is bound to `_` of outer `Local`. | |
136023e0 | 47 | 1. |
f20569fa XL |
48 | }; |
49 | ||
50 | let x: _ = if true { | |
51 | // Should lint this because this literal is not bound to any types. | |
136023e0 | 52 | let y = 1.0_f64; |
f20569fa XL |
53 | |
54 | // Should NOT lint this because this literal is bound to `_` of outer `Local`. | |
136023e0 | 55 | 1. |
f20569fa XL |
56 | } else { |
57 | // Should lint this because this literal is not bound to any types. | |
136023e0 | 58 | let y = 1.0_f64; |
f20569fa XL |
59 | |
60 | // Should NOT lint this because this literal is bound to `_` of outer `Local`. | |
136023e0 | 61 | 2. |
f20569fa | 62 | }; |
2b03887a FG |
63 | |
64 | const X: f32 = { | |
65 | // Should lint this because this literal is not bound to any types. | |
66 | let y = 1.0_f64; | |
67 | ||
68 | // Should NOT lint this because this literal is bound to `_` of outer `Local`. | |
69 | 1. | |
70 | }; | |
f20569fa XL |
71 | } |
72 | } | |
73 | ||
74 | mod function_def { | |
136023e0 | 75 | fn ret_f64() -> f64 { |
c0240ec0 | 76 | 1. |
f20569fa XL |
77 | } |
78 | ||
79 | fn test() { | |
136023e0 | 80 | // Should lint this because return type is inferred to `f64` and NOT bound to a concrete |
f20569fa | 81 | // type. |
136023e0 | 82 | let f = || -> _ { 1.0_f64 }; |
f20569fa XL |
83 | |
84 | // Even though the output type is specified, | |
85 | // this unsuffixed literal is linted to reduce heuristics and keep codebase simple. | |
136023e0 | 86 | let f = || -> f64 { 1.0_f64 }; |
f20569fa XL |
87 | } |
88 | } | |
89 | ||
90 | mod function_calls { | |
136023e0 | 91 | fn concrete_arg(f: f64) {} |
f20569fa XL |
92 | |
93 | fn generic_arg<T>(t: T) {} | |
94 | ||
95 | fn test() { | |
96 | // Should NOT lint this because the argument type is bound to a concrete type. | |
136023e0 | 97 | concrete_arg(1.); |
f20569fa | 98 | |
136023e0 XL |
99 | // Should lint this because the argument type is inferred to `f64` and NOT bound to a concrete type. |
100 | generic_arg(1.0_f64); | |
f20569fa | 101 | |
136023e0 XL |
102 | // Should lint this because the argument type is inferred to `f64` and NOT bound to a concrete type. |
103 | let x: _ = generic_arg(1.0_f64); | |
f20569fa XL |
104 | } |
105 | } | |
106 | ||
107 | mod struct_ctor { | |
108 | struct ConcreteStruct { | |
136023e0 | 109 | x: f64, |
f20569fa XL |
110 | } |
111 | ||
112 | struct GenericStruct<T> { | |
113 | x: T, | |
114 | } | |
115 | ||
116 | fn test() { | |
117 | // Should NOT lint this because the field type is bound to a concrete type. | |
136023e0 XL |
118 | ConcreteStruct { x: 1. }; |
119 | ||
120 | // Should lint this because the field type is inferred to `f64` and NOT bound to a concrete type. | |
121 | GenericStruct { x: 1.0_f64 }; | |
122 | ||
123 | // Should lint this because the field type is inferred to `f64` and NOT bound to a concrete type. | |
124 | let _ = GenericStruct { x: 1.0_f64 }; | |
125 | } | |
126 | } | |
127 | ||
128 | mod enum_ctor { | |
129 | enum ConcreteEnum { | |
130 | X(f64), | |
131 | } | |
f20569fa | 132 | |
136023e0 XL |
133 | enum GenericEnum<T> { |
134 | X(T), | |
135 | } | |
136 | ||
137 | fn test() { | |
138 | // Should NOT lint this because the field type is bound to a concrete type. | |
139 | ConcreteEnum::X(1.); | |
f20569fa | 140 | |
136023e0 XL |
141 | // Should lint this because the field type is inferred to `f64` and NOT bound to a concrete type. |
142 | GenericEnum::X(1.0_f64); | |
f20569fa XL |
143 | } |
144 | } | |
145 | ||
146 | mod method_calls { | |
04454e1e | 147 | struct StructForMethodCallTest; |
f20569fa XL |
148 | |
149 | impl StructForMethodCallTest { | |
136023e0 | 150 | fn concrete_arg(&self, f: f64) {} |
f20569fa XL |
151 | |
152 | fn generic_arg<T>(&self, t: T) {} | |
153 | } | |
154 | ||
155 | fn test() { | |
156 | let s = StructForMethodCallTest {}; | |
157 | ||
158 | // Should NOT lint this because the argument type is bound to a concrete type. | |
136023e0 | 159 | s.concrete_arg(1.); |
f20569fa XL |
160 | |
161 | // Should lint this because the argument type is bound to a concrete type. | |
136023e0 XL |
162 | s.generic_arg(1.0_f64); |
163 | } | |
164 | } | |
165 | ||
166 | mod in_macro { | |
353b0b11 | 167 | use super::*; |
136023e0 XL |
168 | |
169 | // Should lint in internal macro. | |
353b0b11 | 170 | #[inline_macros] |
136023e0 | 171 | fn internal() { |
353b0b11 | 172 | inline!(let x = 22.0_f64;); |
136023e0 XL |
173 | } |
174 | ||
175 | // Should NOT lint in external macro. | |
176 | fn external() { | |
353b0b11 | 177 | external!(let x = 22.;); |
f20569fa XL |
178 | } |
179 | } | |
180 | ||
181 | fn main() {} |