@@ -28,6 +28,11 @@ declare_clippy_lint! {
28
28
/// ### Why is this bad?
29
29
/// clamp is much shorter, easier to read, and doesn't use any control flow.
30
30
///
31
+ /// ### Limitations
32
+ ///
33
+ /// This lint will only trigger if max and min are known at compile time, and max is
34
+ /// greater than min.
35
+ ///
31
36
/// ### Known issue(s)
32
37
/// If the clamped variable is NaN this suggestion will cause the code to propagate NaN
33
38
/// rather than returning either `max` or `min`.
@@ -145,9 +150,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualClamp {
145
150
. or_else ( || is_match_pattern ( cx, expr) )
146
151
. or_else ( || is_if_elseif_pattern ( cx, expr) ) ;
147
152
if let Some ( suggestion) = suggestion {
148
- if suggestion. min_less_than_max ( cx) {
149
- emit_suggestion ( cx, & suggestion) ;
150
- }
153
+ maybe_emit_suggestion ( cx, & suggestion) ;
151
154
}
152
155
}
153
156
}
@@ -157,15 +160,16 @@ impl<'tcx> LateLintPass<'tcx> for ManualClamp {
157
160
return ;
158
161
}
159
162
for suggestion in is_two_if_pattern ( cx, block) {
160
- if suggestion. min_less_than_max ( cx) {
161
- emit_suggestion ( cx, & suggestion) ;
162
- }
163
+ maybe_emit_suggestion ( cx, & suggestion) ;
163
164
}
164
165
}
165
166
extract_msrv_attr ! ( LateContext ) ;
166
167
}
167
168
168
- fn emit_suggestion < ' tcx > ( cx : & LateContext < ' tcx > , suggestion : & ClampSuggestion < ' tcx > ) {
169
+ fn maybe_emit_suggestion < ' tcx > ( cx : & LateContext < ' tcx > , suggestion : & ClampSuggestion < ' tcx > ) {
170
+ if !suggestion. min_less_than_max ( cx) {
171
+ return ;
172
+ }
169
173
let ClampSuggestion {
170
174
params : InputMinMax {
171
175
input,
0 commit comments