mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 13:13:34 +00:00
Fix suggestions for REVERSE_RANGE_LOOP
This commit is contained in:
parent
3ae39145fc
commit
e9360f7675
2 changed files with 10 additions and 2 deletions
|
@ -444,6 +444,11 @@ fn check_for_loop_reverse_range(cx: &LateContext, arg: &Expr, expr: &Expr) {
|
|||
if sup {
|
||||
let start_snippet = snippet(cx, start.span, "_");
|
||||
let end_snippet = snippet(cx, end.span, "_");
|
||||
let dots = if limits == ast::RangeLimits::Closed {
|
||||
"..."
|
||||
} else {
|
||||
".."
|
||||
};
|
||||
|
||||
span_lint_and_then(cx,
|
||||
REVERSE_RANGE_LOOP,
|
||||
|
@ -454,7 +459,10 @@ fn check_for_loop_reverse_range(cx: &LateContext, arg: &Expr, expr: &Expr) {
|
|||
"consider using the following if \
|
||||
you are attempting to iterate \
|
||||
over this range in reverse",
|
||||
format!("({}..{}).rev()", end_snippet, start_snippet));
|
||||
format!("({end}{dots}{start}).rev()",
|
||||
end=end_snippet,
|
||||
dots=dots,
|
||||
start=start_snippet));
|
||||
});
|
||||
} else if eq && limits != ast::RangeLimits::Closed {
|
||||
// if they are equal, it's also problematic - this loop
|
||||
|
|
|
@ -169,7 +169,7 @@ fn main() {
|
|||
for i in 10...0 {
|
||||
//~^ERROR this range is empty so this for loop will never run
|
||||
//~|HELP consider
|
||||
//~|SUGGESTION (0..10).rev()
|
||||
//~|SUGGESTION (0...10).rev()
|
||||
println!("{}", i);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue