Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
manfredbrandl opened this issue May 16, 2015 · 7 comments

Comments

@manfredbrandl
Copy link

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

@manfredbrandl
Copy link
Author

I also cannot use the feature directive:

manfred@sony:~/rustprojects/step_by$ cargo build
   Compiling step_by v0.1.0 (file:///home/manfred/rustprojects/step_by)
src/main.rs:1:1: 1:21 error: unstable feature
src/main.rs:1 #![feature(step_by)]
              ^~~~~~~~~~~~~~~~~~~~
note: this feature may not be used in the stable release channel
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$ 

@mo
Copy link
Contributor

mo commented May 16, 2015

Using "#![feature(step_by)]" should work if you switch to the nightly channel. For example, I got it to work using:
rustc 1.1.0-nightly (7a52835 2015-05-16) (built 2015-05-16)

@michaelsproul
Copy link
Contributor

Yeah, all unstable features are disabled in the stable and beta builds. You can read more of the rationale for this here: http://blog.rust-lang.org/2014/10/30/Stability.html

It is potentially problematic that step_by is used in the stable docs, as it also won't be stable for 1.1 in six weeks.

@manfredbrandl
Copy link
Author

As a potential user I expect that I can use the examples in the stable docs with the stable compiler. If I cannot then I expect to see a note describing why not.

@manfredbrandl manfredbrandl changed the title TRPL: example with step_by does not compile TRPL: example from stable book with step_by does not compile with stable 1.0 compiler May 17, 2015
@steveklabnik
Copy link
Member

The book shouldn't use unstable things except in the nightly section at the end, for sure.

@michaelsproul
Copy link
Contributor

@steveklabnik: In terms of making this change, would it involve manually patching the 1.0 source? In general do we have a way to update the docs for a release after the release has been made?

@steveklabnik
Copy link
Member

No, it's just a bug to be fixed on master and will go out with the next release its part of.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants