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

Demo FromIterator short-circuiting #59362

Merged
merged 4 commits into from
Mar 26, 2019

Conversation

pnkfelix
Copy link
Member

while looking at a FIXME in FromIterator for Option and FromIterator for Result, I realized that the current documentation does not have example code showing exactly what is meant by "no further elements are taken."

The code snippets provided here are meant to correct that.

@rust-highfive
Copy link
Collaborator

r? @dtolnay

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 22, 2019
@pnkfelix pnkfelix added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 22, 2019
@Centril Centril added A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools and removed T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Mar 22, 2019
@Centril
Copy link
Contributor

Centril commented Mar 22, 2019

Looks great, thanks!

r? @Centril @bors r+ rollup

@bors
Copy link
Contributor

bors commented Mar 22, 2019

📌 Commit d5a61c0 has been approved by Centril

@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Mar 22, 2019
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request Mar 22, 2019
…ircuiting, r=Centril

Demo `FromIterator` short-circuiting

while looking at a FIXME in `FromIterator for Option` and `FromIterator for Result`, I realized that the current documentation does not have example code showing exactly what is meant by "no further elements are taken."

The code snippets provided here are meant to correct that.
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:1dfc8b41:start=1553255332022655938,finish=1553255412763729794,duration=80741073856
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
$ export GCP_CACHE_BUCKET=rust-lang-ci-cache
Setting environment variables from .travis.yml
---
travis_time:start:test_assembly
Check compiletest suite=assembly mode=assembly (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:25:07] 
[01:25:07] running 9 tests
[01:25:07] iiiiiiiii
[01:25:07] 
[01:25:07]  finished in 0.156
[01:25:07] travis_fold:end:test_assembly

---
travis_time:start:test_debuginfo
Check compiletest suite=debuginfo mode=debuginfo-both (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:25:23] 
[01:25:23] running 120 tests
[01:25:49] .iiiii...i.....i..i...i..i.i...i.ii...i.....i..i....i..........iiii..........i...ii...i.......ii.i.i 100/120
[01:25:54] .i......iii.i.....ii
[01:25:54] 
[01:25:54]  finished in 30.859
[01:25:54] travis_fold:end:test_debuginfo

---
[01:40:53] .................................................................................................... 1600/2300
[01:41:07] .................................................................................................... 1700/2300
[01:41:21] .................................................................................................... 1800/2300
[01:41:36] .................................................................................................... 1900/2300
[01:41:50] .....................................................F.............................................. 2000/2300
[01:42:06] ..................................................F................................................. 2100/2300
[01:42:40] .......i............................................................................................ 2300/2300
[01:42:40] 
[01:42:40] failures:
[01:42:40] 
[01:42:40] 
[01:42:40] ---- option.rs - option::Option<V>::from_iter (line 1321) stdout ----
[01:42:40] error: expected one of `!`, `)`, `,`, `.`, `::`, `?`, `{`, or an operator, found `;`
[01:42:40]   --> option.rs:1328:25
[01:42:40]    |
[01:42:40] 10 |     .map(|x| shared += x; x.checked_sub(2))
[01:42:40]    |                         ^ expected one of 8 possible tokens here
[01:42:40] error[E0425]: cannot find value `x` in this scope
[01:42:40]   --> option.rs:1328:27
[01:42:40]    |
[01:42:40]    |
[01:42:40] 10 |     .map(|x| shared += x; x.checked_sub(2))
[01:42:40]    |                           ^ not found in this scope
[01:42:40] error[E0061]: this function takes 1 parameter but 2 parameters were supplied
[01:42:40]   --> option.rs:1328:6
[01:42:40]    |
[01:42:40]    |
[01:42:40] 10 |     .map(|x| shared += x; x.checked_sub(2))
[01:42:40] 
[01:42:40] error: aborting due to 3 previous errors
[01:42:40] 
[01:42:40] Some errors occurred: E0061, E0425.
[01:42:40] Some errors occurred: E0061, E0425.
[01:42:40] For more information about an error, try `rustc --explain E0061`.
[01:42:40] thread 'option.rs - option::Option<V>::from_iter (line 1321)' panicked at 'couldn't compile the test', src/librustdoc/test.rs:310:13
[01:42:40] note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
[01:42:40] 
[01:42:40] ---- result.rs - result::Result<V, E>::from_iter (line 1220) stdout ----
[01:42:40] error: expected one of `!`, `)`, `,`, `.`, `::`, `?`, `{`, or an operator, found `;`
[01:42:40]   |
[01:42:40] 7 |     shared += x;
[01:42:40]   |                ^ expected one of 8 possible tokens here
[01:42:40] 
[01:42:40] 
[01:42:40] error[E0425]: cannot find value `x` in this scope
[01:42:40]  --> result.rs:1225:5
[01:42:40]   |
[01:42:40] 8 |     x.checked_sub(2).ok_or("Underflow!")
[01:42:40]   |     ^ help: a local variable with a similar name exists: `v`
[01:42:40] error[E0061]: this function takes 1 parameter but 2 parameters were supplied
[01:42:40]  --> result.rs:1223:52
[01:42:40]   |
[01:42:40]   |
[01:42:40] 6 | let res: Result<Vec<u32>, &'static str> = v.iter().map(|x: &u32|
[01:42:40] 
[01:42:40] error: aborting due to 3 previous errors
[01:42:40] 
[01:42:40] Some errors occurred: E0061, E0425.
---
[01:42:40] 
[01:42:40] error: test failed, to rerun pass '--doc'
[01:42:40] 
[01:42:40] 
[01:42:40] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "test" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" "panic-unwind backtrace" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "-p" "core" "--" "--quiet"
[01:42:40] 
[01:42:40] 
[01:42:40] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:42:40] Build completed unsuccessfully in 0:29:33
[01:42:40] Build completed unsuccessfully in 0:29:33
[01:42:40] make: *** [check] Error 1
[01:42:40] Makefile:48: recipe for target 'check' failed
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:08c35b2c
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Fri Mar 22 13:33:01 UTC 2019
---
travis_time:end:19fe9dfe:start=1553261583421882948,finish=1553261583427197903,duration=5314955
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:129e781a
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:06060120
travis_time:start:06060120
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:113dd558
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

src/libcore/option.rs Outdated Show resolved Hide resolved
@Centril
Copy link
Contributor

Centril commented Mar 22, 2019

@bors r-

(r=me with @killercup's fix / green travis)

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 22, 2019
killercup and others added 2 commits March 25, 2019 11:48
Co-Authored-By: pnkfelix <pnkfelix@pnkfx.org>
add missing braces analogous to those suggested by killercup
/// further elements are taken from `iter` after the first `None`.
///
/// ```
/// let items = vec![3_u16, 2, 1, 10];
Copy link
Contributor

@DevQps DevQps Mar 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as a question from a relative newbie: What is this 3_u16 syntax? I have seen the 3u16 syntax but never with the underscore. Is there a difference between this syntax?

I would suggest that using 3u16 or even let items: Vec<u16>= vec![3, 2, 1, 10]; to make it more clear for people that are not too experienced with Rust. But that is just my humble opinion!

EDIT: Nice examples by the way! I never knew it worked this way :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The _ here is merely an effect of separators in numeric literals, e.g. 3_000_000_u32 or 3_000____u32. The underscores are for readability and have no effect otherwise. 3u16 and 3_u16 are thus equivalent.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright! Thanks for sharing! :)

@Centril
Copy link
Contributor

Centril commented Mar 26, 2019

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Mar 26, 2019

📌 Commit 0e83e96 has been approved by Centril

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 26, 2019
Centril added a commit to Centril/rust that referenced this pull request Mar 26, 2019
…ircuiting, r=Centril

Demo `FromIterator` short-circuiting

while looking at a FIXME in `FromIterator for Option` and `FromIterator for Result`, I realized that the current documentation does not have example code showing exactly what is meant by "no further elements are taken."

The code snippets provided here are meant to correct that.
Centril added a commit to Centril/rust that referenced this pull request Mar 26, 2019
…ircuiting, r=Centril

Demo `FromIterator` short-circuiting

while looking at a FIXME in `FromIterator for Option` and `FromIterator for Result`, I realized that the current documentation does not have example code showing exactly what is meant by "no further elements are taken."

The code snippets provided here are meant to correct that.
Centril added a commit to Centril/rust that referenced this pull request Mar 26, 2019
…ircuiting, r=Centril

Demo `FromIterator` short-circuiting

while looking at a FIXME in `FromIterator for Option` and `FromIterator for Result`, I realized that the current documentation does not have example code showing exactly what is meant by "no further elements are taken."

The code snippets provided here are meant to correct that.
bors added a commit that referenced this pull request Mar 26, 2019
Rollup of 10 pull requests

Successful merges:

 - #59150 (Expand suggestions for type ascription parse errors)
 - #59232 (Merge `Promoted` and `Static` in `mir::Place`)
 - #59267 (Provide suggestion when using field access instead of path)
 - #59315 (Add no_hash to query macro and move some queries over)
 - #59334 (Update build instructions in README.md)
 - #59362 (Demo `FromIterator` short-circuiting)
 - #59374 (Simplify checked_duration_since)
 - #59389 (replace redundant note in deprecation warning)
 - #59410 (Clarify `{Ord,f32,f64}::clamp` docs a little)
 - #59419 (Utilize `?` instead of `return None`.)

Failed merges:

r? @ghost
bors added a commit that referenced this pull request Mar 26, 2019
Rollup of 10 pull requests

Successful merges:

 - #59150 (Expand suggestions for type ascription parse errors)
 - #59232 (Merge `Promoted` and `Static` in `mir::Place`)
 - #59267 (Provide suggestion when using field access instead of path)
 - #59315 (Add no_hash to query macro and move some queries over)
 - #59334 (Update build instructions in README.md)
 - #59362 (Demo `FromIterator` short-circuiting)
 - #59374 (Simplify checked_duration_since)
 - #59389 (replace redundant note in deprecation warning)
 - #59410 (Clarify `{Ord,f32,f64}::clamp` docs a little)
 - #59419 (Utilize `?` instead of `return None`.)

Failed merges:

r? @ghost
@bors bors merged commit 0e83e96 into rust-lang:master Mar 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants