Skip to content

step_by() API change #43063

Closed
Closed
@leonardo-m

Description

@leonardo-m

In past step_by() needed an argument of the same type of the range:

#![feature(iterator_step_by)]
fn main() {
    for i in (1u32 .. 10u32).step_by(2u32) {
        println!("{}", i);
    }
}

But now it gives an error and asks for an usize:

error[E0308]: mismatched types
 --> ...\test.rs:3:38
  |
3 |     for i in (1u32 .. 10u32).step_by(2u32) {
  |                                      ^^^^ expected usize, found u32

Is this desired (and I have to change all my Nightly code)?

This is especially bad when I've used negative step values:

(a - 2 .. 1).step_by(-2)

Now you need to write something like:

(2 + a % 2 .. a - 1).rev().step_by(2)

See also #43012

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions