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

Add Iterator::try_find #63177

Open
wants to merge 1 commit into
base: master
from

Conversation

@MOZGIII
Copy link

commented Jul 31, 2019

I found a need for this fn, and created this PR.

Tracking issue: #63178

I did a fair amount of thinking about the function name, and settled on the current one.
I don't see other anything else that's non-trivial here, but I'm open for debate. I just want this functionality to be there.
It couples with the collect trick for collecting Result<Vec<T>, E> from Iterator<Item = Result<T, E>>.

UPD:

I've already looked at fallible_iterator crate, but I don't think it supports my use case.
The main problem is that I can't construct a failable iterator. I have a regular iterator, and I just need to apply a predicate that can fail via find method.

UPD: fallible_iterator would work, but it's not elegant cause I'd have to make a failable iterator by mapping iterator with Result::Ok first.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

commented Jul 31, 2019

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @sfackler (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.

@rust-highfive

This comment was marked as outdated.

Copy link
Collaborator

commented Jul 31, 2019

The job mingw-check of your PR failed (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.
2019-07-31T22:58:48.4035534Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-07-31T22:58:48.4217823Z ##[command]git config gc.auto 0
2019-07-31T22:58:48.4279666Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-07-31T22:58:48.4326202Z ##[command]git config --get-all http.proxy
2019-07-31T22:58:48.4451465Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/63177/merge:refs/remotes/pull/63177/merge
---
2019-07-31T22:59:24.6419252Z do so (now or later) by using -b with the checkout command again. Example:
2019-07-31T22:59:24.6419295Z 
2019-07-31T22:59:24.6419482Z   git checkout -b <new-branch-name>
2019-07-31T22:59:24.6419507Z 
2019-07-31T22:59:24.6419560Z HEAD is now at 2cc45b074 Merge 05df16d423250b3f7b47b74df9d657cdb06188d2 into 8a58268b5ad9c4a240be349a633069d48991eb0c
2019-07-31T22:59:24.6566061Z ##[section]Starting: Collect CPU-usage statistics in the background
2019-07-31T22:59:24.6568783Z ==============================================================================
2019-07-31T22:59:24.6568845Z Task         : Bash
2019-07-31T22:59:24.6568884Z Description  : Run a Bash script on macOS, Linux, or Windows
---
2019-07-31T23:04:10.9758552Z    |
2019-07-31T23:04:10.9758825Z 76 | #![feature(const_generics)]
2019-07-31T23:04:10.9759109Z    |            ^^^^^^^^^^^^^^
2019-07-31T23:04:10.9759148Z 
2019-07-31T23:04:13.7913168Z error[E0545]: incorrect 'issue'
2019-07-31T23:04:13.7913975Z     --> src/libcore/iter/traits/iterator.rs:1988:5
2019-07-31T23:04:13.7914285Z      |
2019-07-31T23:04:13.7914623Z 1988 |     #[unstable(feature = "find_result", reason = "new API", issue = "?")]
2019-07-31T23:04:13.7915012Z 
2019-07-31T23:04:13.7915012Z 
2019-07-31T23:04:17.3512358Z error[E0599]: no method named `break_value` found for type `result::Result<(), result::Result<<Self as iter::traits::iterator::Iterator>::Item, E>>` in the current scope
2019-07-31T23:04:17.3512818Z     --> src/libcore/iter/traits/iterator.rs:1999:12
2019-07-31T23:04:17.3513050Z      |
2019-07-31T23:04:17.3513342Z 1999 |         }).break_value().transpose()
2019-07-31T23:04:17.3513952Z      | 
2019-07-31T23:04:17.3514194Z     ::: src/libcore/result.rs:246:1
2019-07-31T23:04:17.3514415Z      |
2019-07-31T23:04:17.3514415Z      |
2019-07-31T23:04:17.3514670Z 246  | pub enum Result<T, E> {
2019-07-31T23:04:17.3514984Z      | --------------------- method `break_value` not found for this
2019-07-31T23:04:18.9449098Z    Compiling libc v0.2.54
2019-07-31T23:04:19.7115692Z    Compiling build_helper v0.1.0 (/checkout/src/build_helper)
2019-07-31T23:04:20.6802209Z error: aborting due to 2 previous errors
2019-07-31T23:04:20.6802311Z 
2019-07-31T23:04:20.6802311Z 
2019-07-31T23:04:20.6802612Z For more information about this error, try `rustc --explain E0599`.
2019-07-31T23:04:20.7677901Z error: Could not compile `core`.
2019-07-31T23:04:20.7679166Z warning: build failed, waiting for other jobs to finish...
2019-07-31T23:04:21.0261434Z error: build failed
2019-07-31T23:04:21.0282157Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "check" "--target" "x86_64-unknown-linux-gnu" "-j" "2" "--release" "--color" "always" "--features" "panic-unwind backtrace compiler-builtins-c" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "--message-format" "json"
2019-07-31T23:04:21.0294394Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap check
2019-07-31T23:04:21.0294461Z Build completed unsuccessfully in 0:02:07
2019-07-31T23:04:21.0294461Z Build completed unsuccessfully in 0:02:07
2019-07-31T23:04:32.4940728Z ##[error]Bash exited with code '1'.
2019-07-31T23:04:32.4972964Z ##[section]Starting: Checkout
2019-07-31T23:04:32.4974593Z ==============================================================================
2019-07-31T23:04:32.4974659Z Task         : Get sources
2019-07-31T23:04:32.4974698Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

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)

@MOZGIII MOZGIII force-pushed the MOZGIII:find-result branch from 05df16d to 80cab9d Jul 31, 2019

@rust-highfive

This comment was marked as outdated.

Copy link
Collaborator

commented Jul 31, 2019

The job mingw-check of your PR failed (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.
2019-07-31T23:11:32.5430032Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-07-31T23:11:32.5620022Z ##[command]git config gc.auto 0
2019-07-31T23:11:32.6012608Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-07-31T23:11:32.6061055Z ##[command]git config --get-all http.proxy
2019-07-31T23:11:32.6186597Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/63177/merge:refs/remotes/pull/63177/merge
---
2019-07-31T23:12:06.4441344Z do so (now or later) by using -b with the checkout command again. Example:
2019-07-31T23:12:06.4441378Z 
2019-07-31T23:12:06.4441604Z   git checkout -b <new-branch-name>
2019-07-31T23:12:06.4441634Z 
2019-07-31T23:12:06.4441704Z HEAD is now at c40986eae Merge 80cab9dc63ab786287444e485a5f0ee9ccd4218a into 8a58268b5ad9c4a240be349a633069d48991eb0c
2019-07-31T23:12:06.4605199Z ##[section]Starting: Collect CPU-usage statistics in the background
2019-07-31T23:12:06.4607997Z ==============================================================================
2019-07-31T23:12:06.4608085Z Task         : Bash
2019-07-31T23:12:06.4608127Z Description  : Run a Bash script on macOS, Linux, or Windows
---
2019-07-31T23:17:07.3342712Z    |
2019-07-31T23:17:07.3342978Z 76 | #![feature(const_generics)]
2019-07-31T23:17:07.3343742Z    |            ^^^^^^^^^^^^^^
2019-07-31T23:17:07.3343810Z 
2019-07-31T23:17:10.3828621Z error[E0545]: incorrect 'issue'
2019-07-31T23:17:10.3829099Z     --> src/libcore/iter/traits/iterator.rs:1988:5
2019-07-31T23:17:10.3829376Z      |
2019-07-31T23:17:10.3829719Z 1988 |     #[unstable(feature = "find_result", reason = "new API", issue = "?")]
2019-07-31T23:17:10.3830138Z 
2019-07-31T23:17:10.3830138Z 
2019-07-31T23:17:14.1981160Z error[E0599]: no method named `break_value` found for type `result::Result<(), result::Result<<Self as iter::traits::iterator::Iterator>::Item, E>>` in the current scope
2019-07-31T23:17:14.1981600Z     --> src/libcore/iter/traits/iterator.rs:1999:12
2019-07-31T23:17:14.1981972Z      |
2019-07-31T23:17:14.1982262Z 1999 |         }).break_value().transpose()
2019-07-31T23:17:14.1982684Z      | 
2019-07-31T23:17:14.1982919Z     ::: src/libcore/result.rs:246:1
2019-07-31T23:17:14.1983106Z      |
2019-07-31T23:17:14.1983106Z      |
2019-07-31T23:17:14.1983329Z 246  | pub enum Result<T, E> {
2019-07-31T23:17:14.1984378Z      | --------------------- method `break_value` not found for this
2019-07-31T23:17:15.8630006Z    Compiling libc v0.2.54
2019-07-31T23:17:16.6813516Z    Compiling build_helper v0.1.0 (/checkout/src/build_helper)
2019-07-31T23:17:17.7756351Z error: aborting due to 2 previous errors
2019-07-31T23:17:17.7756734Z 
2019-07-31T23:17:17.7756734Z 
2019-07-31T23:17:17.7757154Z For more information about this error, try `rustc --explain E0599`.
2019-07-31T23:17:17.8701626Z error: Could not compile `core`.
2019-07-31T23:17:17.8703709Z warning: build failed, waiting for other jobs to finish...
2019-07-31T23:17:18.1220153Z error: build failed
2019-07-31T23:17:18.1241861Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "check" "--target" "x86_64-unknown-linux-gnu" "-j" "2" "--release" "--color" "always" "--features" "panic-unwind backtrace compiler-builtins-c" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "--message-format" "json"
2019-07-31T23:17:18.1255284Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap check
2019-07-31T23:17:18.1255520Z Build completed unsuccessfully in 0:02:14
2019-07-31T23:17:18.1255520Z Build completed unsuccessfully in 0:02:14
2019-07-31T23:17:31.4296441Z ##[error]Bash exited with code '1'.
2019-07-31T23:17:31.4331656Z ##[section]Starting: Checkout
2019-07-31T23:17:31.4333197Z ==============================================================================
2019-07-31T23:17:31.4333270Z Task         : Get sources
2019-07-31T23:17:31.4333317Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

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)

@MOZGIII MOZGIII force-pushed the MOZGIII:find-result branch from 80cab9d to 2727a67 Jul 31, 2019

@rust-highfive

This comment was marked as outdated.

Copy link
Collaborator

commented Jul 31, 2019

The job mingw-check of your PR failed (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.
2019-07-31T23:41:03.8982670Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-07-31T23:41:03.9150102Z ##[command]git config gc.auto 0
2019-07-31T23:41:03.9236904Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-07-31T23:41:03.9294060Z ##[command]git config --get-all http.proxy
2019-07-31T23:41:03.9434894Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/63177/merge:refs/remotes/pull/63177/merge
---
2019-07-31T23:41:36.9830792Z do so (now or later) by using -b with the checkout command again. Example:
2019-07-31T23:41:36.9830843Z 
2019-07-31T23:41:36.9831084Z   git checkout -b <new-branch-name>
2019-07-31T23:41:36.9831116Z 
2019-07-31T23:41:36.9831170Z HEAD is now at e9a63e959 Merge 2727a675ae54addc21be6411a3678f94a65e6936 into 8a58268b5ad9c4a240be349a633069d48991eb0c
2019-07-31T23:41:36.9984317Z ##[section]Starting: Collect CPU-usage statistics in the background
2019-07-31T23:41:36.9987579Z ==============================================================================
2019-07-31T23:41:36.9987648Z Task         : Bash
2019-07-31T23:41:36.9987701Z Description  : Run a Bash script on macOS, Linux, or Windows
---
2019-07-31T23:46:47.6440612Z    |
2019-07-31T23:46:47.6440989Z 76 | #![feature(const_generics)]
2019-07-31T23:46:47.6441346Z    |            ^^^^^^^^^^^^^^
2019-07-31T23:46:47.6441429Z 
2019-07-31T23:46:50.6673294Z error[E0545]: incorrect 'issue'
2019-07-31T23:46:50.6674689Z     --> src/libcore/iter/traits/iterator.rs:1988:5
2019-07-31T23:46:50.6675668Z      |
2019-07-31T23:46:50.6676528Z 1988 |     #[unstable(feature = "find_result", reason = "new API", issue = "?")]
2019-07-31T23:46:50.6677666Z 
2019-07-31T23:46:54.4750823Z error[E0308]: match arms have incompatible types
2019-07-31T23:46:54.4751330Z     --> src/libcore/iter/traits/iterator.rs:1996:29
2019-07-31T23:46:54.4751766Z      |
2019-07-31T23:46:54.4751766Z      |
2019-07-31T23:46:54.4752102Z 1994 | /             match f(&x) {
2019-07-31T23:46:54.4752469Z 1995 | |                 Ok(false) => LoopState::Continue,
2019-07-31T23:46:54.4753030Z      | |                              ------------------- this is found to be of type `fn(_) -> iter::LoopState<_, _> {iter::LoopState::<_, _>::Continue}`
2019-07-31T23:46:54.4753411Z 1996 | |                 Ok(true) => LoopState::Break(Ok(x)),
2019-07-31T23:46:54.4753864Z      | |                             ^^^^^^^^^^^^^^^^^^^^^^^ expected fn item, found enum `iter::LoopState`
2019-07-31T23:46:54.4754232Z 1997 | |                 Err(x) => LoopState::Break(Err(x)),
2019-07-31T23:46:54.4754587Z 1998 | |             }
2019-07-31T23:46:54.4755162Z      | |_____________- `match` arms have incompatible types
2019-07-31T23:46:54.4755433Z      |
2019-07-31T23:46:54.4755795Z      = note: expected type `fn(_) -> iter::LoopState<_, _> {iter::LoopState::<_, _>::Continue}`
2019-07-31T23:46:54.4756139Z                 found type `iter::LoopState<_, result::Result<<Self as iter::traits::iterator::Iterator>::Item, _>>`
2019-07-31T23:46:55.9620479Z    Compiling libc v0.2.54
2019-07-31T23:46:56.7731307Z    Compiling unwind v0.0.0 (/checkout/src/libunwind)
2019-07-31T23:46:57.3140985Z    Compiling build_helper v0.1.0 (/checkout/src/build_helper)
2019-07-31T23:46:58.0733258Z error: aborting due to 2 previous errors
2019-07-31T23:46:58.0733258Z error: aborting due to 2 previous errors
2019-07-31T23:46:58.0737909Z 
2019-07-31T23:46:58.0744544Z For more information about this error, try `rustc --explain E0308`.
2019-07-31T23:46:58.1696024Z error: Could not compile `core`.
2019-07-31T23:46:58.1696376Z warning: build failed, waiting for other jobs to finish...
2019-07-31T23:46:58.5388409Z error: build failed
2019-07-31T23:46:58.5409624Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "check" "--target" "x86_64-unknown-linux-gnu" "-j" "2" "--release" "--color" "always" "--features" "panic-unwind backtrace compiler-builtins-c" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "--message-format" "json"
2019-07-31T23:46:58.5419268Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap check
2019-07-31T23:46:58.5420229Z Build completed unsuccessfully in 0:02:21
2019-07-31T23:46:58.5420229Z Build completed unsuccessfully in 0:02:21
2019-07-31T23:47:11.8762510Z ##[error]Bash exited with code '1'.
2019-07-31T23:47:11.8807467Z ##[section]Starting: Checkout
2019-07-31T23:47:11.8809213Z ==============================================================================
2019-07-31T23:47:11.8809292Z Task         : Get sources
2019-07-31T23:47:11.8809346Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

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)

@MOZGIII MOZGIII force-pushed the MOZGIII:find-result branch from 2727a67 to 017f987 Jul 31, 2019

@rust-highfive

This comment was marked as outdated.

Copy link
Collaborator

commented Aug 1, 2019

The job mingw-check of your PR failed (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.
2019-07-31T23:57:05.7413860Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-07-31T23:57:05.7605218Z ##[command]git config gc.auto 0
2019-07-31T23:57:05.7683228Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-07-31T23:57:05.7747190Z ##[command]git config --get-all http.proxy
2019-07-31T23:57:05.7887749Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/63177/merge:refs/remotes/pull/63177/merge
---
2019-07-31T23:57:41.0266929Z do so (now or later) by using -b with the checkout command again. Example:
2019-07-31T23:57:41.0266953Z 
2019-07-31T23:57:41.0267120Z   git checkout -b <new-branch-name>
2019-07-31T23:57:41.0267156Z 
2019-07-31T23:57:41.0267213Z HEAD is now at 39ba8181c Merge 017f98768c66598901f9c95f24369f78185369e9 into 8a58268b5ad9c4a240be349a633069d48991eb0c
2019-07-31T23:57:41.0442922Z ##[section]Starting: Collect CPU-usage statistics in the background
2019-07-31T23:57:41.0446911Z ==============================================================================
2019-07-31T23:57:41.0446960Z Task         : Bash
2019-07-31T23:57:41.0446996Z Description  : Run a Bash script on macOS, Linux, or Windows
---
2019-08-01T00:02:46.8743375Z    |
2019-08-01T00:02:46.8743874Z 76 | #![feature(const_generics)]
2019-08-01T00:02:46.8744190Z    |            ^^^^^^^^^^^^^^
2019-08-01T00:02:46.8744487Z 
2019-08-01T00:02:49.7956176Z error[E0545]: incorrect 'issue'
2019-08-01T00:02:49.7956556Z     --> src/libcore/iter/traits/iterator.rs:1988:5
2019-08-01T00:02:49.7956756Z      |
2019-08-01T00:02:49.7957039Z 1988 |     #[unstable(feature = "find_result", reason = "new API", issue = "?")]
2019-08-01T00:02:49.7957344Z 
2019-08-01T00:02:54.7264226Z    Compiling libc v0.2.54
2019-08-01T00:02:55.5085223Z    Compiling unwind v0.0.0 (/checkout/src/libunwind)
2019-08-01T00:02:56.0577475Z    Compiling build_helper v0.1.0 (/checkout/src/build_helper)
2019-08-01T00:02:56.0577475Z    Compiling build_helper v0.1.0 (/checkout/src/build_helper)
2019-08-01T00:02:56.9325848Z error: aborting due to previous error
2019-08-01T00:02:56.9326004Z 
2019-08-01T00:02:57.0306846Z error: Could not compile `core`.
2019-08-01T00:02:57.0318626Z warning: build failed, waiting for other jobs to finish...
2019-08-01T00:02:57.3330563Z error: build failed
2019-08-01T00:02:57.3351049Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "check" "--target" "x86_64-unknown-linux-gnu" "-j" "2" "--release" "--color" "always" "--features" "panic-unwind backtrace compiler-builtins-c" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "--message-format" "json"
2019-08-01T00:02:57.3364897Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap check
2019-08-01T00:02:57.3365217Z Build completed unsuccessfully in 0:02:11
2019-08-01T00:02:57.3365217Z Build completed unsuccessfully in 0:02:11
2019-08-01T00:03:11.6957889Z ##[error]Bash exited with code '1'.
2019-08-01T00:03:11.6993422Z ##[section]Starting: Checkout
2019-08-01T00:03:11.6995163Z ==============================================================================
2019-08-01T00:03:11.6995212Z Task         : Get sources
2019-08-01T00:03:11.6995273Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

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)

@MOZGIII

This comment has been minimized.

Copy link
Author

commented Aug 1, 2019

Sorry about force-pushes. The code was completely broken, but not it compiles at least, so I'll be adding commits instead of force pushing from now on.

@MOZGIII MOZGIII changed the title Add find_result at Iterator Add Iterator::find_result Aug 1, 2019

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

commented Aug 1, 2019

The job x86_64-gnu-llvm-6.0 of your PR failed (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.
2019-08-01T00:08:29.1243892Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-08-01T00:08:29.1423352Z ##[command]git config gc.auto 0
2019-08-01T00:08:29.1473539Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-08-01T00:08:29.1517023Z ##[command]git config --get-all http.proxy
2019-08-01T00:08:29.1641956Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/63177/merge:refs/remotes/pull/63177/merge
---
2019-08-01T00:09:03.9396430Z do so (now or later) by using -b with the checkout command again. Example:
2019-08-01T00:09:03.9396456Z 
2019-08-01T00:09:03.9396620Z   git checkout -b <new-branch-name>
2019-08-01T00:09:03.9396644Z 
2019-08-01T00:09:03.9396695Z HEAD is now at 91e130838 Merge f851f29352aaa9d33fdd08397a297fcfb6c418d8 into 8a58268b5ad9c4a240be349a633069d48991eb0c
2019-08-01T00:09:03.9593590Z ##[section]Starting: Collect CPU-usage statistics in the background
2019-08-01T00:09:03.9595940Z ==============================================================================
2019-08-01T00:09:03.9595986Z Task         : Bash
2019-08-01T00:09:03.9596037Z Description  : Run a Bash script on macOS, Linux, or Windows
---
2019-08-01T01:08:36.9698737Z .................................................................................................... 1400/8819
2019-08-01T01:08:42.8103162Z .................................................................................................... 1500/8819
2019-08-01T01:08:55.5173414Z .................................................................i...............i.................. 1600/8819
2019-08-01T01:09:02.8500228Z .................................................................................................... 1700/8819
2019-08-01T01:09:17.3263892Z ...................................................iiiii............................................ 1800/8819
2019-08-01T01:09:28.3308992Z .................................................................................................... 2000/8819
2019-08-01T01:09:30.7032436Z .................................................................................................... 2100/8819
2019-08-01T01:09:34.2948831Z .................................................................................................... 2200/8819
2019-08-01T01:09:41.1424125Z .................................................................................................... 2300/8819
---
2019-08-01T01:13:34.7135879Z .................................................................................................... 5300/8819
2019-08-01T01:13:42.1100280Z ..............i..................................................................................... 5400/8819
2019-08-01T01:13:47.7255558Z .................................................................................................... 5500/8819
2019-08-01T01:14:00.2290628Z .................................................................................................... 5600/8819
2019-08-01T01:14:13.6168452Z ........ii...i..ii...........i...................................................................... 5700/8819
2019-08-01T01:14:31.0965989Z .................................................................................................... 5900/8819
2019-08-01T01:14:36.0580848Z .................................................................................................... 6000/8819
2019-08-01T01:14:36.0580848Z .................................................................................................... 6000/8819
2019-08-01T01:14:50.1004519Z ........i..ii....................................................................................... 6100/8819
2019-08-01T01:15:09.4352515Z ...................................................i................................................ 6300/8819
2019-08-01T01:15:11.5098524Z .................................................................................................... 6400/8819
2019-08-01T01:15:13.9784184Z .....................i.............................................................................. 6500/8819
2019-08-01T01:15:18.5059526Z .................................................................................................... 6600/8819
---
2019-08-01T01:19:55.0634585Z  finished in 20.485
2019-08-01T01:19:55.0807889Z Check compiletest suite=codegen mode=codegen (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-08-01T01:19:55.2364015Z 
2019-08-01T01:19:55.2364818Z running 146 tests
2019-08-01T01:19:58.4538831Z i....iii......iii..iiii....i............................i..i................i....i.........ii.i.i..i 100/146
2019-08-01T01:20:00.2778030Z iii..............i.........iii.i......ii......
2019-08-01T01:20:00.2781739Z 
2019-08-01T01:20:00.2783118Z  finished in 5.197
2019-08-01T01:20:00.2956021Z Check compiletest suite=codegen-units mode=codegen-units (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-08-01T01:20:00.4517342Z 
---
2019-08-01T01:20:02.4759891Z  finished in 2.180
2019-08-01T01:20:02.4935453Z Check compiletest suite=assembly mode=assembly (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-08-01T01:20:02.6419283Z 
2019-08-01T01:20:02.6419869Z running 9 tests
2019-08-01T01:20:02.6421064Z iiiiiiiii
2019-08-01T01:20:02.6421456Z 
2019-08-01T01:20:02.6421502Z  finished in 0.148
2019-08-01T01:20:02.6598460Z Check compiletest suite=incremental mode=incremental (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-08-01T01:20:02.8148703Z 
---
2019-08-01T01:20:20.7166270Z  finished in 18.056
2019-08-01T01:20:20.7357841Z Check compiletest suite=debuginfo mode=debuginfo-gdb+lldb (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-08-01T01:20:20.8999427Z 
2019-08-01T01:20:20.8999773Z running 122 tests
2019-08-01T01:20:43.6670459Z .iiiii...i.....i..i...i..i.i.i..i.ii..i.i.....i..i....i..........iiii..........i...ii...i.......ii.i 100/122
2019-08-01T01:20:48.1862250Z .i.i......iii.i.....ii
2019-08-01T01:20:48.1865961Z 
2019-08-01T01:20:48.1870288Z  finished in 27.451
2019-08-01T01:20:48.1877922Z Uplifting stage1 rustc (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-08-01T01:20:48.1878347Z Copying stage2 rustc from stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
---
2019-08-01T01:33:15.5752170Z 
2019-08-01T01:33:15.5876215Z  finished in 161.372
2019-08-01T01:33:15.5891763Z Testing core stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-08-01T01:33:15.7765974Z    Compiling core v0.0.0 (/checkout/src/libcore)
2019-08-01T01:33:21.0310751Z error[E0658]: use of unstable library feature 'find_result': new API
2019-08-01T01:33:21.0312405Z     --> src/libcore/../libcore/tests/iter.rs:1264:26
2019-08-01T01:33:21.0312985Z      |
2019-08-01T01:33:21.0313573Z 1264 |     assert_eq!(xs.iter().find_result(testfn), Ok(None));
2019-08-01T01:33:21.0314964Z      |
2019-08-01T01:33:21.0314964Z      |
2019-08-01T01:33:21.0315738Z      = note: for more information, see ***/issues/63178
2019-08-01T01:33:21.0316304Z      = help: add `#![feature(find_result)]` to the crate attributes to enable
2019-08-01T01:33:21.0316497Z 
2019-08-01T01:33:21.0328362Z error[E0658]: use of unstable library feature 'find_result': new API
2019-08-01T01:33:21.0328667Z     --> src/libcore/../libcore/tests/iter.rs:1266:26
2019-08-01T01:33:21.0329028Z      |
2019-08-01T01:33:21.0329272Z 1266 |     assert_eq!(xs.iter().find_result(testfn), Ok(Some(&2)));
2019-08-01T01:33:21.0329719Z      |
2019-08-01T01:33:21.0329719Z      |
2019-08-01T01:33:21.0330211Z      = note: for more information, see ***/issues/63178
2019-08-01T01:33:21.0330465Z      = help: add `#![feature(find_result)]` to the crate attributes to enable
2019-08-01T01:33:21.0330498Z 
2019-08-01T01:33:21.0342397Z error[E0658]: use of unstable library feature 'find_result': new API
2019-08-01T01:33:21.0342935Z     --> src/libcore/../libcore/tests/iter.rs:1268:26
2019-08-01T01:33:21.0343291Z      |
2019-08-01T01:33:21.0343669Z 1268 |     assert_eq!(xs.iter().find_result(testfn), Err(()));
2019-08-01T01:33:21.0345149Z      |
2019-08-01T01:33:21.0345149Z      |
2019-08-01T01:33:21.0345741Z      = note: for more information, see ***/issues/63178
2019-08-01T01:33:21.0346455Z      = help: add `#![feature(find_result)]` to the crate attributes to enable
2019-08-01T01:33:21.0346682Z 
2019-08-01T01:33:21.0358742Z error[E0658]: use of unstable library feature 'find_result': new API
2019-08-01T01:33:21.0359392Z     --> src/libcore/../libcore/tests/iter.rs:1272:21
2019-08-01T01:33:21.0359817Z      |
2019-08-01T01:33:21.0360439Z 1272 |     assert_eq!(iter.find_result(testfn), Ok(Some(&2)));
2019-08-01T01:33:21.0361994Z      |
2019-08-01T01:33:21.0361994Z      |
2019-08-01T01:33:21.0362831Z      = note: for more information, see ***/issues/63178
2019-08-01T01:33:21.0363557Z      = help: add `#![feature(find_result)]` to the crate attributes to enable
2019-08-01T01:33:21.0363724Z 
2019-08-01T01:33:21.0376001Z error[E0658]: use of unstable library feature 'find_result': new API
2019-08-01T01:33:21.0376567Z     --> src/libcore/../libcore/tests/iter.rs:1273:21
2019-08-01T01:33:21.0377066Z      |
2019-08-01T01:33:21.0377745Z 1273 |     assert_eq!(iter.find_result(testfn), Err(()));
2019-08-01T01:33:21.0378525Z      |
2019-08-01T01:33:21.0378525Z      |
2019-08-01T01:33:21.0379024Z      = note: for more information, see ***/issues/63178
2019-08-01T01:33:21.0379659Z      = help: add `#![feature(find_result)]` to the crate attributes to enable
2019-08-01T01:33:27.3009518Z error: aborting due to 5 previous errors
2019-08-01T01:33:27.3010100Z 
2019-08-01T01:33:27.3010483Z For more information about this error, try `rustc --explain E0658`.
2019-08-01T01:33:27.4120842Z error: Could not compile `core`.
2019-08-01T01:33:27.4120842Z error: Could not compile `core`.
2019-08-01T01:33:27.4121441Z 
2019-08-01T01:33:27.4121823Z To learn more, run the command again with --verbose.
2019-08-01T01:33:27.4140405Z 
2019-08-01T01:33:27.4140639Z 
2019-08-01T01:33:27.4141341Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "test" "--target" "x86_64-unknown-linux-gnu" "-j" "2" "--release" "--locked" "--color" "always" "--features" "panic-unwind backtrace compiler-builtins-c" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "-p" "core" "--" "--quiet"
2019-08-01T01:33:27.4141742Z 
2019-08-01T01:33:27.4141851Z 
2019-08-01T01:33:27.4151992Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
2019-08-01T01:33:27.4152242Z Build completed unsuccessfully in 1:18:01
2019-08-01T01:33:27.4152242Z Build completed unsuccessfully in 1:18:01
2019-08-01T01:33:27.9374229Z ##[error]Bash exited with code '1'.
2019-08-01T01:33:27.9420049Z ##[section]Starting: Checkout
2019-08-01T01:33:27.9421543Z ==============================================================================
2019-08-01T01:33:27.9421603Z Task         : Get sources
2019-08-01T01:33:27.9421640Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

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)

@sfackler

This comment has been minimized.

Copy link
Member

commented Aug 1, 2019

The iterator trait is generally not built around iteration over Results, and I'm not sure that adding a variant of a single method makes sense when thinking about Iterator on the whole.

Thoughts @rust-lang/libs?

@sinkuu

This comment has been minimized.

Copy link
Contributor

commented Aug 1, 2019

We already have try_fold and try_for_each that uses Try trait, so generic try_find may make more sense than a Result-specific method.

@MOZGIII

This comment has been minimized.

Copy link
Author

commented Aug 1, 2019

Using Try sounds reasonable, I’ll update the PR with generic Try instead of a Result.

@MOZGIII

This comment has been minimized.

Copy link
Author

commented Aug 1, 2019

I also had a feeling this Result-specific functionality does not belong with the Iterator trait, but then I deduced it’s not that bad. And now it’s going to be solved elegantly with Try - and it won’t extend the existing practices. Except for it’d be the first occasion of returning a Try (concrete Result as in the current version). Is this an issue? I feel like it’s ok.

@alexcrichton

This comment has been minimized.

Copy link
Member

commented Aug 1, 2019

I personally agree with @sfackler in terms of stabilization and @sinkuu in terms of implementation basically. I would be wary to stabilize just one try_* method without starting consider more, and it seems good for Result-intended methods to largely have consistent signatures.

@MOZGIII

This comment has been minimized.

Copy link
Author

commented Aug 1, 2019

@alexcrichton could you elaborate more? If I understand correctly - stabilizing means promoting this fn to stable, and I'd rather just keep unstable for a while - cause maybe there's a better way of providing this API. I fully agree that we might want to add other try_* calls.
I can even give it a try if this PR goes in successfully. I just want to get used to the contribution process before taking a bigger bite.

@alexcrichton

This comment has been minimized.

Copy link
Member

commented Aug 1, 2019

Sorry yeah what I mean to say is that I would want to pause before stabilization, but this is fine to land unstable at any time. When landing it unstable though it seem reasonable to try to use Try and perhaps tweak the name to try_* or something like that.

@MOZGIII

This comment has been minimized.

Copy link
Author

commented Aug 1, 2019

Right, I'm in progress with switching to Try and changing the name.
There seems to be a bit of an issue though - I'm not sure how to derive the return value of the whole fn (not the predicate) via trait combinations with Try. Might be worth to just explicitly use Result there...

@MOZGIII

This comment has been minimized.

Copy link
Author

commented Aug 1, 2019

fn try_find<F, E, T, FR, R>(&mut self, mut f: F) -> R where
        Self: Sized,
        FR: Try<Ok = bool, Error = E>,
        F: FnMut(&Self::Item) -> FR,
        R: Try<Ok = Option<Self::Item>, Error = E> { ... }

This is what I'm trying atm. Is it ok if we use R the return value like that? Or should it be Result<Option<Self::Item>, E> explicitly?

@MOZGIII

This comment has been minimized.

Copy link
Author

commented Aug 1, 2019

Returning the Result explicitly (instead of Try) kind of makes much more sense to me.

Any thoughts?

@MOZGIII MOZGIII force-pushed the MOZGIII:find-result branch from fd0fff3 to e0dbc3e Aug 2, 2019

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

commented Aug 2, 2019

The job x86_64-gnu-llvm-6.0 of your PR failed (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.
2019-08-02T00:51:11.7223319Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-08-02T00:51:11.7406187Z ##[command]git config gc.auto 0
2019-08-02T00:51:11.7495213Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-08-02T00:51:11.7586489Z ##[command]git config --get-all http.proxy
2019-08-02T00:51:11.7799232Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/63177/merge:refs/remotes/pull/63177/merge
---
2019-08-02T00:51:45.6215568Z do so (now or later) by using -b with the checkout command again. Example:
2019-08-02T00:51:45.6215613Z 
2019-08-02T00:51:45.6215795Z   git checkout -b <new-branch-name>
2019-08-02T00:51:45.6215822Z 
2019-08-02T00:51:45.6215865Z HEAD is now at c123b0fa5 Merge e0dbc3e57ab09e080499165617d9103459adcebd into 435236b8877cdb98c82eaebfb7887782277265c5
2019-08-02T00:51:45.6384597Z ##[section]Starting: Collect CPU-usage statistics in the background
2019-08-02T00:51:45.6387804Z ==============================================================================
2019-08-02T00:51:45.6387887Z Task         : Bash
2019-08-02T00:51:45.6387933Z Description  : Run a Bash script on macOS, Linux, or Windows
---
2019-08-02T01:48:56.6603545Z .................................................................................................... 1400/8821
2019-08-02T01:49:02.2298524Z .................................................................................................... 1500/8821
2019-08-02T01:49:14.4804627Z .................................................................i...............i.................. 1600/8821
2019-08-02T01:49:21.5839974Z .................................................................................................... 1700/8821
2019-08-02T01:49:35.8492732Z ...................................................iiiii............................................ 1800/8821
2019-08-02T01:49:46.4675457Z .................................................................................................... 2000/8821
2019-08-02T01:49:48.8544227Z .................................................................................................... 2100/8821
2019-08-02T01:49:52.2049894Z .................................................................................................... 2200/8821
2019-08-02T01:49:58.4840338Z .................................................................................................... 2300/8821
---
2019-08-02T01:53:43.4688859Z .................................................................................................... 5300/8821
2019-08-02T01:53:51.3939606Z ...............i.................................................................................... 5400/8821
2019-08-02T01:53:56.3736312Z .................................................................................................... 5500/8821
2019-08-02T01:54:08.3884713Z .................................................................................................... 5600/8821
2019-08-02T01:54:21.3696465Z .........ii...i..ii...........i..................................................................... 5700/8821
2019-08-02T01:54:36.2059084Z .................................................................................................... 5900/8821
2019-08-02T01:54:40.9344920Z .................................................................................................... 6000/8821
2019-08-02T01:54:40.9344920Z .................................................................................................... 6000/8821
2019-08-02T01:54:54.2325195Z .........i..ii...................................................................................... 6100/8821
2019-08-02T01:55:12.5204205Z ....................................................i............................................... 6300/8821
2019-08-02T01:55:14.4634016Z .................................................................................................... 6400/8821
2019-08-02T01:55:16.7478926Z .......................i............................................................................ 6500/8821
2019-08-02T01:55:20.9493280Z .................................................................................................... 6600/8821
---
2019-08-02T01:59:48.9525148Z  finished in 22.191
2019-08-02T01:59:48.9689740Z Check compiletest suite=codegen mode=codegen (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-08-02T01:59:49.1201150Z 
2019-08-02T01:59:49.1201307Z running 146 tests
2019-08-02T01:59:52.1574482Z i....iii......iii..iiii....i............................i..i................i....i.........ii.i.i..i 100/146
2019-08-02T01:59:53.9047367Z iii..............i.........iii.i......ii......
2019-08-02T01:59:53.9047811Z 
2019-08-02T01:59:53.9047855Z  finished in 4.935
2019-08-02T01:59:53.9212835Z Check compiletest suite=codegen-units mode=codegen-units (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-08-02T01:59:54.0616991Z 
---
2019-08-02T01:59:56.0106617Z  finished in 2.089
2019-08-02T01:59:56.0276884Z Check compiletest suite=assembly mode=assembly (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-08-02T01:59:56.1723349Z 
2019-08-02T01:59:56.1723881Z running 9 tests
2019-08-02T01:59:56.1724461Z iiiiiiiii
2019-08-02T01:59:56.1724822Z 
2019-08-02T01:59:56.1724859Z  finished in 0.144
2019-08-02T01:59:56.1881720Z Check compiletest suite=incremental mode=incremental (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-08-02T01:59:56.3370376Z 
---
2019-08-02T02:00:13.8425183Z  finished in 17.654
2019-08-02T02:00:13.8611952Z Check compiletest suite=debuginfo mode=debuginfo-gdb+lldb (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-08-02T02:00:14.0234464Z 
2019-08-02T02:00:14.0234808Z running 122 tests
2019-08-02T02:00:37.0889550Z .iiiii...i.....i..i...i..i.i.i..i.ii..i.i.....i..i....i..........iiii..........i...ii...i.......ii.i 100/122
2019-08-02T02:00:41.5230739Z .i.i......iii.i.....ii
2019-08-02T02:00:41.5234369Z 
2019-08-02T02:00:41.5234979Z  finished in 27.662
2019-08-02T02:00:41.5238750Z Uplifting stage1 rustc (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-08-02T02:00:41.5239387Z Copying stage2 rustc from stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
---
2019-08-02T02:13:56.4932462Z 
2019-08-02T02:13:56.4933437Z    Doc-tests core
2019-08-02T02:14:00.3109700Z 
2019-08-02T02:14:00.3110662Z running 2381 tests
2019-08-02T02:14:12.4394069Z ......iiiii......................................................................................... 100/2381
2019-08-02T02:14:24.4127755Z .........................................................................ii......................... 200/2381
2019-08-02T02:14:52.8061489Z .................................................................................................... 400/2381
2019-08-02T02:14:52.8061489Z .................................................................................................... 400/2381
2019-08-02T02:15:03.4015042Z ........................FF......i..i.................iiii........................................... 500/2381
2019-08-02T02:15:25.8315461Z .................................................................................................... 700/2381
2019-08-02T02:15:37.3104857Z .................................................................................................... 800/2381
2019-08-02T02:15:48.8218963Z .................................................................................................... 900/2381
2019-08-02T02:16:00.0256426Z .................................................................................................... 1000/2381
---
2019-08-02T02:18:48.6030981Z ---- iter/traits/iterator.rs - iter::traits::iterator::Iterator::try_find (line 1972) stdout ----
2019-08-02T02:18:48.6031265Z error[E0277]: the trait bound `bool: std::ops::Try` is not satisfied
2019-08-02T02:18:48.6031713Z  --> iter/traits/iterator.rs:1976:23
2019-08-02T02:18:48.6032292Z   |
2019-08-02T02:18:48.6032512Z 7 | let result = a.iter().try_find(|&s| s.parse()? == 2);
2019-08-02T02:18:48.6032899Z   |                       ^^^^^^^^ the trait `std::ops::Try` is not implemented for `bool`
2019-08-02T02:18:48.6033081Z 
2019-08-02T02:18:48.6033280Z error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
2019-08-02T02:18:48.6033799Z  --> iter/traits/iterator.rs:1976:37
2019-08-02T02:18:48.6034049Z   |
2019-08-02T02:18:48.6034270Z 7 | let result = a.iter().try_find(|&s| s.parse()? == 2);
2019-08-02T02:18:48.6034480Z   |                                     ^^^^^^^^^^ cannot use the `?` operator in a function that returns `bool`
2019-08-02T02:18:48.6034868Z   = help: the trait `std::ops::Try` is not implemented for `bool`
2019-08-02T02:18:48.6035054Z   = note: required by `std::ops::Try::from_error`
2019-08-02T02:18:48.6035219Z 
2019-08-02T02:18:48.6035423Z error[E0308]: mismatched types
2019-08-02T02:18:48.6035423Z error[E0308]: mismatched types
2019-08-02T02:18:48.6036663Z  --> iter/traits/iterator.rs:1978:1
2019-08-02T02:18:48.6037004Z   |
2019-08-02T02:18:48.6037272Z 9 | assert_eq!(result, Ok(Some(&2)));
2019-08-02T02:18:48.6037742Z   | |
2019-08-02T02:18:48.6038023Z   | expected &str, found integer
2019-08-02T02:18:48.6038023Z   | expected &str, found integer
2019-08-02T02:18:48.6038267Z   | help: try using a variant of the expected type: `Err(*right_val)`
2019-08-02T02:18:48.6038495Z   |
2019-08-02T02:18:48.6038959Z   = note: expected type `std::result::Result<std::option::Option<&&str>, _>`
2019-08-02T02:18:48.6039442Z              found type `std::result::Result<std::option::Option<&{integer}>, _>`
2019-08-02T02:18:48.6040235Z 
2019-08-02T02:18:48.6040447Z error: aborting due to 3 previous errors
2019-08-02T02:18:48.6040624Z 
2019-08-02T02:18:48.6040842Z Some errors have detailed explanations: E0277, E0308.
2019-08-02T02:18:48.6040842Z Some errors have detailed explanations: E0277, E0308.
2019-08-02T02:18:48.6041285Z For more information about an error, try `rustc --explain E0277`.
2019-08-02T02:18:48.6041745Z Couldn't compile the test.
2019-08-02T02:18:48.6042228Z ---- iter/traits/iterator.rs - iter::traits::iterator::Iterator::try_find (line 1981) stdout ----
2019-08-02T02:18:48.6043343Z error[E0277]: the trait bound `bool: std::ops::Try` is not satisfied
2019-08-02T02:18:48.6044218Z  --> iter/traits/iterator.rs:1985:23
2019-08-02T02:18:48.6044603Z   |
2019-08-02T02:18:48.6044752Z 7 | let result = a.iter().try_find(|&s| s.parse()? == 5);
2019-08-02T02:18:48.6045074Z   |                       ^^^^^^^^ the trait `std::ops::Try` is not implemented for `bool`
2019-08-02T02:18:48.6046197Z 
2019-08-02T02:18:48.6046396Z error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
2019-08-02T02:18:48.6046884Z  --> iter/traits/iterator.rs:1985:37
2019-08-02T02:18:48.6047093Z   |
2019-08-02T02:18:48.6047256Z 7 | let result = a.iter().try_find(|&s| s.parse()? == 5);
2019-08-02T02:18:48.6047444Z   |                                     ^^^^^^^^^^ cannot use the `?` operator in a function that returns `bool`
2019-08-02T02:18:48.6047785Z   = help: the trait `std::ops::Try` is not implemented for `bool`
2019-08-02T02:18:48.6047963Z   = note: required by `std::ops::Try::from_error`
2019-08-02T02:18:48.6048101Z 
2019-08-02T02:18:48.6048257Z error: aborting due to 2 previous errors
---
2019-08-02T02:18:48.6051111Z 
2019-08-02T02:18:48.6267775Z error: test failed, to rerun pass '--doc'
2019-08-02T02:18:48.6282631Z 
2019-08-02T02:18:48.6282920Z 
2019-08-02T02:18:48.6283987Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "test" "--target" "x86_64-unknown-linux-gnu" "-j" "2" "--release" "--locked" "--color" "always" "--features" "panic-unwind backtrace compiler-builtins-c" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "-p" "core" "--" "--quiet"
2019-08-02T02:18:48.6284295Z 
2019-08-02T02:18:48.6284322Z 
2019-08-02T02:18:48.6296306Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
2019-08-02T02:18:48.6296413Z Build completed unsuccessfully in 1:21:11
2019-08-02T02:18:48.6296413Z Build completed unsuccessfully in 1:21:11
2019-08-02T02:18:49.0839307Z ##[error]Bash exited with code '1'.
2019-08-02T02:18:49.0886606Z ##[section]Starting: Checkout
2019-08-02T02:18:49.0888492Z ==============================================================================
2019-08-02T02:18:49.0888549Z Task         : Get sources
2019-08-02T02:18:49.0888633Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

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)

@MOZGIII

This comment has been minimized.

Copy link
Author

commented Aug 2, 2019

I'm having troubles with running tests locally - ./x.py test -i -j 4 src/libcore --stage 1 --test-args iter::traits::iterator::Iterator::try_find seems to compile stage0 compiler every time, and it takes at least 10 mins. I just want to iterate quickly on my feature - how can I do that?

UPD: for later: --keep-stage 0 helps

@timvermeulen

This comment has been minimized.

Copy link
Contributor

commented Aug 2, 2019

I really like this, having it return a Result is unfortunate though. I believe returning R would require higher-kinded types, since R::Ok of the return value would need to be Option<Self::Item> instead of bool.

Something else to think about: similar to try_find there could be try_find_map / try_any / try_all / try_position, would those be as useful as try_find?

@MOZGIII

This comment has been minimized.

Copy link
Author

commented Aug 2, 2019

I think, as a general rule, almost anything that takes FnMut would benefit from a Try version... Maybe we should think about this in a broader scale.

With the result - I think I implement it with Try as return value instead of Result, but that would be an independent type - and user would have to somehow specify what it should be. Technically it should be ok I guess - unless it's used like .try_find(...)? - this would leave compiler with no hint about the result type, and will force user to do verbose stuff. I'd also prefer having a generic Try as the response type, but I just can't figure out how to make it not painful to use.

@MOZGIII

This comment has been minimized.

Copy link
Author

commented Aug 2, 2019

I've created this: https://github.com/MOZGIII/iter-try-rs
It supports generalization over the result type. I decided to only provide a generic impl over Try for the Result type, here: https://github.com/MOZGIII/iter-try-rs/blob/946d5e61dbde2458d27b99387290bf3b933281d2/src/try_find.rs#L48-L51

Based on this experiment, I think it looks like we should only provide a single implementation of the Try value of the box for the whole try_find return value - because otherwise users would have to inelegantly specify the exact type to disambiguate the inference when using ? operator. In other words, generic Try as a result would hurt the usability, and surprisingly the usability of the Try (?) operator itself, lol.

I'd suggest to go with the Result type explicitly in this case. I think it's justified enough.

@MOZGIII

This comment has been minimized.

Copy link
Author

commented Aug 2, 2019

Btw, I'd prefer squashing the commits in this PR before merging it, if that's ok. I can squash manually, just ping me when (if ever :)) it is time for merge. I'd do it now but I'm trying to follow the guidelines and let people review the changes more comfortably.

@timvermeulen

This comment has been minimized.

Copy link
Contributor

commented Aug 2, 2019

I think, as a general rule, almost anything that takes FnMut would benefit from a Try version... Maybe we should think about this in a broader scale.

If I'm not mistaken, you can trivially implement try_find in terms of find by using itertools's process_results, which I'm adding as an internal function in #62459. Something like process_results(self, |i| i.find(f)) seems like it should work. It's so simple that it's making me doubt whether we should even add try_find (and possibly other try_ methods) at all, rather than making process_results public in one way or another 🙂

@MOZGIII

This comment has been minimized.

Copy link
Author

commented Aug 3, 2019

This sounds good, yet I'm not sure if it solves the particular issue that I have. Your code seems to require that the iterator itself iterates over Results. In this case, we're adding support for the non-Result iterators to use a Result-returning predicate in find.

@timvermeulen

This comment has been minimized.

Copy link
Contributor

commented Aug 3, 2019

Right, I forgot about that. You might still be able to achieve that by mapping to an iterator of Results first? But yeah, definitely not as trivial/elegant as I assumed it was.

@MOZGIII

This comment has been minimized.

Copy link
Author

commented Aug 3, 2019

It's very inelegant actually, and the worst thing is - you first have to map to your (Self::Item, Result<bool, E>, then perform find over the result, mapping either Ok(false) or any Err(...), and then properly unpack the outcome - Option<(Self::Item, Result<bool, E>)>. Pretty much unreadable and makes whoever has to maintain the code base very sad.

@timvermeulen

This comment has been minimized.

Copy link
Contributor

commented Aug 3, 2019

Yep, you could still possibly implement try_find that way, but even that doesn't seem worth it compared to implementing find in terms of try_find using !.

@MOZGIII

This comment has been minimized.

Copy link
Author

commented Aug 3, 2019

Could you elaborate more? I don't recall ! other than in macro calls...

@timvermeulen

This comment has been minimized.

Copy link
Contributor

commented Aug 3, 2019

Iterator::fold is currently implemented as

self.try_fold(init, move |acc, x| Ok::<B, !>(f(acc, x))).unwrap()

where ! is the never type. Given a try_find method you could implement find this way, too, with

self.try_find(move |x| Ok::<_, !>(f(x))).unwrap()

You could probably even take out the parts these have in common into a new function.

@MOZGIII

This comment has been minimized.

Copy link
Author

commented Aug 3, 2019

Oh, I got it now, how could I forget, true. Does it make sense to reimplement the find and fold like that though? I'd be interesting to see how the two compare in generated code and performance. Ideally, as I understand, the generated code should be the same as with the current find implementation, right? But can the compiler actually do that... Is it tested somehow btw?

@timvermeulen

This comment has been minimized.

Copy link
Contributor

commented Aug 3, 2019

Does it make sense to reimplement the find and fold like that though?

Maybe not, but it would prevent having some duplicate logic 🙂

I'd be interesting to see how the two compare in generated code and performance. Ideally, as I understand, the generated code should be the same as with the current find implementation, right? But can the compiler actually do that...

Result<T, !> has the same representation as T, so it should generate the same code. There are some iterator benchmarks in core that would surely regress if it has any overhead.

@MOZGIII

This comment has been minimized.

Copy link
Author

commented Aug 3, 2019

Nice. So, should I include that rewrite with this PR?

@scottmcm

This comment has been minimized.

Copy link
Member

commented Aug 6, 2019

Given a try_find method you could implement find this way, too

Personally, I think I prefer the current version in terms of try_for_each as it avoids the unwrap and looks about as close as it can to the imperative-loop form:

        self.try_for_each(move |x| {
            if predicate(&x) { LoopState::Break(x) }
            else { LoopState::Continue(()) }
        }).break_value()

@MOZGIII MOZGIII force-pushed the MOZGIII:find-result branch from 7b9df81 to a7fdfb0 Aug 6, 2019

@MOZGIII MOZGIII changed the title Add Iterator::find_result Add Iterator::try_find Aug 6, 2019

@MOZGIII

This comment has been minimized.

Copy link
Author

commented Aug 6, 2019

Assuming there's been some time since the last change, and everyone interested had time to pick up the changes, I squashed the commits and updated PR and tracking issue title and details with try_find vs the original find_result. Ready for merge.

@timvermeulen

This comment has been minimized.

Copy link
Contributor

commented Aug 7, 2019

@scottmcm Yeah, I don’t think it’s necessarily worth reimplementing find (and other similar methods) here, especially considering how simple it is.

Having said that, I don’t know if making implementations look like imperative loops is a very useful goal – something like

self.find_map(|x| if predicate(&x) { Some(x) } else { None })

is a lot less noisy, and nicely shows the relation between the two methods. You could even use Option::filter there 🙂

@MOZGIII

This comment has been minimized.

Copy link
Author

commented Aug 7, 2019

If the API look good I'd suggest we merge this - there's not much sense to change the internals if they do the trick. I'd hold with stabilization of this though - maybe until the related trait types arrive to the language, to connect predicate and whole-fn return types over Try implementation.

@JohnCSimon

This comment has been minimized.

Copy link

commented Aug 17, 2019

pinging from triage
@MOZGIII @sfackler @timvermeulen This PR has sat idle for more than a week. Is this ready to merge?

Thanks for your contribution @MOZGIII !

@MOZGIII

This comment has been minimized.

Copy link
Author

commented Aug 17, 2019

AFAIK there are no changes requested atm. We can improve further with Try response type when proper support arrives at the language type system. If anyone knows PR for that, I-forgot-how-it's-called, thing - let's link it here to let people working on it know about this use case.

This request is ready merge, unless there are no new change requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants
You can’t perform that action at this time.