@@ -9,9 +9,9 @@ use rustc::middle::region::CodeExtent;
9
9
use rustc:: ty;
10
10
use rustc_const_eval:: EvalHint :: ExprTypeChecked ;
11
11
use rustc_const_eval:: eval_const_expr_partial;
12
- use std:: borrow:: Cow ;
13
12
use std:: collections:: HashMap ;
14
13
use syntax:: ast;
14
+ use utils:: sugg;
15
15
16
16
use utils:: { snippet, span_lint, get_parent_expr, match_trait_method, match_type, multispan_sugg, in_external_macro,
17
17
span_help_and_lint, is_integer_literal, get_enclosing_block, span_lint_and_then, higher,
@@ -332,7 +332,7 @@ fn check_for_loop(cx: &LateContext, pat: &Pat, arg: &Expr, body: &Expr, expr: &E
332
332
/// Check for looping over a range and then indexing a sequence with it.
333
333
/// The iteratee must be a range literal.
334
334
fn check_for_loop_range ( cx : & LateContext , pat : & Pat , arg : & Expr , body : & Expr , expr : & Expr ) {
335
- if let Some ( higher:: Range { start : Some ( ref start) , ref end, .. } ) = higher:: range ( arg) {
335
+ if let Some ( higher:: Range { start : Some ( ref start) , ref end, limits } ) = higher:: range ( arg) {
336
336
// the var must be a single name
337
337
if let PatKind :: Binding ( _, ref ident, _) = pat. node {
338
338
let mut visitor = VarVisitor {
@@ -360,20 +360,28 @@ fn check_for_loop_range(cx: &LateContext, pat: &Pat, arg: &Expr, body: &Expr, ex
360
360
361
361
let starts_at_zero = is_integer_literal ( start, 0 ) ;
362
362
363
- let skip: Cow < _ > = if starts_at_zero {
364
- "" . into ( )
363
+ let skip = if starts_at_zero {
364
+ "" . to_owned ( )
365
365
} else {
366
- format ! ( ".skip({})" , snippet( cx, start. span, ".." ) ) . into ( )
366
+ format ! ( ".skip({})" , snippet( cx, start. span, ".." ) )
367
367
} ;
368
368
369
- let take: Cow < _ > = if let Some ( ref end) = * end {
369
+ let take = if let Some ( ref end) = * end {
370
370
if is_len_call ( end, & indexed) {
371
- "" . into ( )
371
+ "" . to_owned ( )
372
372
} else {
373
- format ! ( ".take({})" , snippet( cx, end. span, ".." ) ) . into ( )
373
+ match limits {
374
+ ast:: RangeLimits :: Closed => {
375
+ let end = sugg:: Sugg :: hir ( cx, end, "<count>" ) ;
376
+ format ! ( ".take({})" , end + sugg:: ONE )
377
+ }
378
+ ast:: RangeLimits :: HalfOpen => {
379
+ format ! ( ".take({})" , snippet( cx, end. span, ".." ) )
380
+ }
381
+ }
374
382
}
375
383
} else {
376
- "" . into ( )
384
+ "" . to_owned ( )
377
385
} ;
378
386
379
387
if visitor. nonindex {
0 commit comments