Skip to content

TRPL: example from stable book with step_by does not compile with stable 1.0 compiler #25499

Closed
@manfredbrandl

Description

@manfredbrandl

In http://doc.rust-lang.org/stable/book/iterators.html there the third code from the bottom reads:

for i in (1..).step_by(5).take(5) {
    println!("{}", i);
}

Trying to compile this gives:

manfred@sony:~/rustprojects/step_by$ cargo build
   Compiling step_by v0.1.0 (file:///home/manfred/rustprojects/step_by)
src/main.rs:2:20: 2:30 error: use of unstable library feature 'step_by': recent addition
src/main.rs:2     for i in (1..).step_by(5).take(5) {
                                 ^~~~~~~~~~
error: aborting due to previous error
Could not compile `step_by`.

To learn more, run the command again with --verbose.
manfred@sony:~/rustprojects/step_by$ 

In http://doc.rust-lang.org/1.0.0/core/ops/struct.Range.html#method.step_by
one can see "Unstable: recent addition"
I did not find a way to compile the example.
Adding '#[unstable]' as first line in the source does not help but gives:

src/main.rs:1:3: 1:11 error: stability attributes may not be used outside of the standard library
src/main.rs:1 #[unstable]
                ^~~~~~~~

rustc --version --verbose
rustc 1.0.0 (a59de37 2015-05-13) (built 2015-05-14)
binary: rustc
commit-hash: a59de37
commit-date: 2015-05-13
build-date: 2015-05-14
host: x86_64-unknown-linux-gnu
release: 1.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions