Auto merge of #6320 - giraffate:fix_suggestion_in_manual_range_contains_using_float, r=llogiq
Fix suggestion in `manual_range_contains` when using float Fix #6315 changelog: Fix suggestion in `manual_range_contains` when using float
This commit is contained in:
commit
408b615d34
@ -222,13 +222,14 @@ fn check_possible_range_contains(cx: &LateContext<'_>, op: BinOpKind, l: &Expr<'
|
||||
let name = snippet_with_applicability(cx, name_span, "_", &mut applicability);
|
||||
let lo = snippet_with_applicability(cx, l_span, "_", &mut applicability);
|
||||
let hi = snippet_with_applicability(cx, u_span, "_", &mut applicability);
|
||||
let space = if lo.ends_with('.') { " " } else { "" };
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
MANUAL_RANGE_CONTAINS,
|
||||
span,
|
||||
&format!("manual `{}::contains` implementation", range_type),
|
||||
"use",
|
||||
format!("({}{}{}).contains(&{})", lo, range_op, hi, name),
|
||||
format!("({}{}{}{}).contains(&{})", lo, space, range_op, hi, name),
|
||||
applicability,
|
||||
);
|
||||
} else if !combine_and && ord == Some(lord) {
|
||||
@ -251,13 +252,14 @@ fn check_possible_range_contains(cx: &LateContext<'_>, op: BinOpKind, l: &Expr<'
|
||||
let name = snippet_with_applicability(cx, name_span, "_", &mut applicability);
|
||||
let lo = snippet_with_applicability(cx, l_span, "_", &mut applicability);
|
||||
let hi = snippet_with_applicability(cx, u_span, "_", &mut applicability);
|
||||
let space = if lo.ends_with('.') { " " } else { "" };
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
MANUAL_RANGE_CONTAINS,
|
||||
span,
|
||||
&format!("manual `!{}::contains` implementation", range_type),
|
||||
"use",
|
||||
format!("!({}{}{}).contains(&{})", lo, range_op, hi, name),
|
||||
format!("!({}{}{}{}).contains(&{})", lo, space, range_op, hi, name),
|
||||
applicability,
|
||||
);
|
||||
}
|
||||
|
@ -38,4 +38,9 @@ fn main() {
|
||||
x >= 8 || x >= 12;
|
||||
x < 12 || 12 < x;
|
||||
x >= 8 || x <= 12;
|
||||
|
||||
// Fix #6315
|
||||
let y = 3.;
|
||||
(0. ..1.).contains(&y);
|
||||
!(0. ..=1.).contains(&y);
|
||||
}
|
||||
|
@ -38,4 +38,9 @@ fn main() {
|
||||
x >= 8 || x >= 12;
|
||||
x < 12 || 12 < x;
|
||||
x >= 8 || x <= 12;
|
||||
|
||||
// Fix #6315
|
||||
let y = 3.;
|
||||
y >= 0. && y < 1.;
|
||||
y < 0. || y > 1.;
|
||||
}
|
||||
|
@ -72,5 +72,17 @@ error: manual `!RangeInclusive::contains` implementation
|
||||
LL | 999 < x || 1 > x;
|
||||
| ^^^^^^^^^^^^^^^^ help: use: `!(1..=999).contains(&x)`
|
||||
|
||||
error: aborting due to 12 previous errors
|
||||
error: manual `Range::contains` implementation
|
||||
--> $DIR/range_contains.rs:44:5
|
||||
|
|
||||
LL | y >= 0. && y < 1.;
|
||||
| ^^^^^^^^^^^^^^^^^ help: use: `(0. ..1.).contains(&y)`
|
||||
|
||||
error: manual `!RangeInclusive::contains` implementation
|
||||
--> $DIR/range_contains.rs:45:5
|
||||
|
|
||||
LL | y < 0. || y > 1.;
|
||||
| ^^^^^^^^^^^^^^^^ help: use: `!(0. ..=1.).contains(&y)`
|
||||
|
||||
error: aborting due to 14 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user