Skip to content
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

RangeFrom::step_by docs: fix example #31172

Merged
merged 1 commit into from
Jan 26, 2016
Merged

Conversation

SimonSapin
Copy link
Contributor

The previous example did not do what its description said. In it panicked on integer overflow in debug mode, and went into an infinite loop in release mode (wrapping back to 0 after printing 254).

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@ranma42
Copy link
Contributor

ranma42 commented Jan 25, 2016

The example is now much better, but I am afraid that the overflow behaviour is still not clear.
Should we state that overflow should be avoided by the caller?
"Creates an iterator starting at the same point, but stepping by the given amount at each iteration." does not really convey the information about what is going to happen (for example, it is not obvious whether the step addition is panicking/wrapping/saturating/checked/...).

Would this work?
"Creates an iterator starting at the same point, but stepping by the given amount at each iteration. Stepping beyond the maximum value that can be represented by A is undefined behaviour."

@SimonSapin
Copy link
Contributor Author

I think discussion of overflow should go into the docs of RangeFrom (which is itself an iterator) rather than RangeFrom::step_by (which gives a "subset" of that iterator)

@ranma42
Copy link
Contributor

ranma42 commented Jan 25, 2016

Yes, that seems right

@alexcrichton
Copy link
Member

Can the ignore tag also be removed from the example? I'm a little surprised we have an ignored code example...

@SimonSapin
Copy link
Contributor Author

Done. It was probably ignored because it didn’t work :)

@alexcrichton
Copy link
Member

@bors: r+ 6e87d781a6eb3dae7014968f60c4ec2b137a9fe4

@Manishearth
Copy link
Member

http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/7783/steps/test/logs/stdio

failures:

---- iter::RangeFrom<A>::step_by_0 stdout ----
    <anon>:4:22: 4:29 error: use of unstable library feature 'step_by': recent addition (see issue #27741)
<anon>:4     for i in (0u8..).step_by(2).take(10) {
                              ^~~~~~~
<anon>:4:22: 4:29 help: add #![feature(step_by)] to the crate attributes to enable
error: aborting due to previous error
thread 'iter::RangeFrom<A>::step_by_0' panicked at 'Box<Any>', ../src/libsyntax/errors/mod.rs:527

protip: run rustdoc --test on the file directly to avoid recompiling everything to run a doctest

@bors
Copy link
Contributor

bors commented Jan 26, 2016

⌛ Testing commit 6e87d78 with merge 85ecc8b...

@Manishearth
Copy link
Member

@bors r- force

(doctest not yet fixed)

@bors
Copy link
Contributor

bors commented Jan 26, 2016

⛄ The build was interrupted to prioritize another pull request.

The previous example did not do what its description said. In it panicked on integer overflow in debug mode, and went into an infinite loop in release mode (wrapping back to 0 after printing 254).
@SimonSapin
Copy link
Contributor Author

Fixed and tested locally with rustdoc. This is a good tip, thanks Manish! So far I had made this PR in GitHub’s web editor, hoping it would be trivial…

@Manishearth
Copy link
Member

@bors r=sfackler

@bors
Copy link
Contributor

bors commented Jan 26, 2016

📌 Commit 70d4f26 has been approved by sfackler

Manishearth added a commit to Manishearth/rust that referenced this pull request Jan 26, 2016
The previous example did not do what its description said. In it panicked on integer overflow in debug mode, and went into an infinite loop in release mode (wrapping back to 0 after printing 254).
@Manishearth
Copy link
Member

Great! I'll stick it in a rollup since the build for the other PR just started anyway.

bors added a commit that referenced this pull request Jan 26, 2016
@bors bors merged commit 70d4f26 into rust-lang:master Jan 26, 2016
@SimonSapin SimonSapin deleted the patch-17 branch February 18, 2016 15:57
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

Successfully merging this pull request may close these issues.

6 participants