@@ -28,6 +28,11 @@ declare_clippy_lint! {
2828 /// ### Why is this bad?
2929 /// clamp is much shorter, easier to read, and doesn't use any control flow.
3030 ///
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+ ///
3136 /// ### Known issue(s)
3237 /// If the clamped variable is NaN this suggestion will cause the code to propagate NaN
3338 /// rather than returning either `max` or `min`.
@@ -145,9 +150,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualClamp {
145150 . or_else ( || is_match_pattern ( cx, expr) )
146151 . or_else ( || is_if_elseif_pattern ( cx, expr) ) ;
147152 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) ;
151154 }
152155 }
153156 }
@@ -157,15 +160,16 @@ impl<'tcx> LateLintPass<'tcx> for ManualClamp {
157160 return ;
158161 }
159162 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) ;
163164 }
164165 }
165166 extract_msrv_attr ! ( LateContext ) ;
166167}
167168
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+ }
169173 let ClampSuggestion {
170174 params : InputMinMax {
171175 input,
0 commit comments