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

Option::flatten #60256

Merged
merged 1 commit into from Apr 29, 2019

Conversation

Projects
None yet
8 participants
@ethanboxx
Copy link
Contributor

commented Apr 25, 2019

This PR makes this possible.

assert_eq!(Some(6), Some(Some(6)).flatten());
assert_eq!(Some(6), Some(Some(6)).into());
@rust-highfive

This comment has been minimized.

Copy link
Collaborator

commented Apr 25, 2019

r? @rkruppe

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

@rust-highfive

This comment was marked as resolved.

Copy link
Collaborator

commented Apr 25, 2019

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:010ca811:start=1556190631734350733,finish=1556190632673693187,duration=939342454
$ 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
$ export AWS_ACCESS_KEY_ID=AKIA46X5W6CZEJZ6XT55
---

[00:03:58] travis_fold:start:tidy
travis_time:start:tidy
tidy check
[00:03:58] tidy error: /checkout/src/libcore/option.rs: missing trailing newline
[00:04:00] some tidy checks failed
[00:04:00] 
[00:04:00] 
[00:04:00] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor" "--quiet"
[00:04:00] 
[00:04:00] 
[00:04:00] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:04:00] Build completed unsuccessfully in 0:00:47
[00:04:00] Build completed unsuccessfully in 0:00:47
[00:04:00] make: *** [tidy] Error 1
[00:04:00] Makefile:67: recipe for target 'tidy' failed
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:137715ad
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Thu Apr 25 11:14:44 UTC 2019
---
travis_time:end:08bc3308:start=1556190884944362241,finish=1556190884949320837,duration=4958596
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:0a391158
$ 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:0eb5cfe4
travis_time:start:0eb5cfe4
$ 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:116b292c
$ 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)

@rust-highfive

This comment was marked as outdated.

Copy link
Collaborator

commented Apr 25, 2019

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:0bcb3092:start=1556191101801299075,finish=1556191102583006167,duration=781707092
$ 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
$ export AWS_ACCESS_KEY_ID=AKIA46X5W6CZEJZ6XT55
---
[00:04:05]    Compiling backtrace-sys v0.1.27
[00:04:06] error[E0547]: missing 'issue'
[00:04:06]     --> src/libcore/option.rs:1417:1
[00:04:06]      |
[00:04:06] 1417 | #[unstable(feature = "option_flattening")]
[00:04:06] 
[00:04:08]    Compiling std v0.0.0 (/checkout/src/libstd)
[00:04:08]    Compiling rustc_asan v0.0.0 (/checkout/src/librustc_asan)
[00:04:08]    Compiling rustc_tsan v0.0.0 (/checkout/src/librustc_tsan)
---
travis_time:end:07bae5bd:start=1556191372703481790,finish=1556191372707937603,duration=4455813
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:25411a52
$ 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:0783980d
travis_time:start:0783980d
$ 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:22c7dfd0
$ 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)

@Centril Centril added this to the 1.36 milestone Apr 25, 2019

@Centril

This comment has been minimized.

Copy link
Contributor

commented Apr 25, 2019

I think it would be preferable to add this as a method .flatten() since that is clearer wrt. intent and is better in terms of type inference. Moreover, we already have the other monadic operations and .flatten() already exists for Iterator so there's precedent there.


Assigning over to random t-libs member;

r? @alexcrichton

@ethanboxx

This comment has been minimized.

Copy link
Contributor Author

commented Apr 25, 2019

@Centril I agree, a flatten method would be a good idea. Do you think I should add both a flatten method and an Into implementation?

@Centril

This comment has been minimized.

Copy link
Contributor

commented Apr 25, 2019

and an Into implementation?

Don't really have an opinion :)

@rust-highfive

This comment was marked as outdated.

Copy link
Collaborator

commented Apr 25, 2019

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:0aa7b38d:start=1556192655622968537,finish=1556192656412786471,duration=789817934
$ 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
$ export AWS_ACCESS_KEY_ID=AKIA46X5W6CZEJZ6XT55

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)

@ethanboxx ethanboxx changed the title Add flatten option to `Option<Option<T>>` with `Into` trait. Option::flatten Apr 25, 2019

@Keruspe

This comment has been minimized.

Copy link
Contributor

commented Apr 25, 2019

You probably could use unwrap_or_default instead of matching, couldn't you?

@rust-highfive

This comment was marked as outdated.

Copy link
Collaborator

commented Apr 25, 2019

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:08ea626e:start=1556193910441730489,finish=1556193911300274503,duration=858544014
$ 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
$ export AWS_ACCESS_KEY_ID=AKIA46X5W6CZEJZ6XT55
---
[00:27:26]    Compiling chalk-macros v0.1.0
[00:27:30]    Compiling humantime v1.2.0
[00:27:30]    Compiling backtrace-sys v0.1.27
[00:27:30]    Compiling miniz-sys v0.1.11
[00:27:30] error[E0283]: type annotations required: cannot resolve `std::option::Option<_>: std::convert::Into<std::option::Option<&str>>`
[00:27:30]    |
[00:27:30]    |
[00:27:30] 12 |         .define("MINIZ_NO_STDIO", None)
[00:27:30] 
[00:27:30] error: aborting due to previous error
[00:27:30] 
[00:27:30] For more information about this error, try `rustc --explain E0283`.
---
156512 ./src/llvm-project/clang
144704 ./obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu
144700 ./obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release
142508 ./obj/build/bootstrap/debug/incremental/bootstrap-hfsog967tquc
142504 ./obj/build/bootstrap/debug/incremental/bootstrap-hfsog967tquc/s-fbmhov9905-1nmkeo-nmt2l0hs44c2
123640 ./src/llvm-project/llvm/test/CodeGen
108536 ./src/llvm-project/lldb
101624 ./.git
97600 ./src/llvm-project/clang/test
---
19256 ./src/llvm-project/lldb/www/cpp_reference/html
18100 ./obj/build/x86_64-unknown-linux-gnu/stage0-codegen
travis_time:end:27d9563a:start=1556195574024855381,finish=1556195574585706607,duration=560851226
travis_fold:end:after_failure.1
san/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:00731020
$ 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)

@Centril

This comment has been minimized.

Copy link
Contributor

commented Apr 25, 2019

You probably could use unwrap_or_default instead of matching, couldn't you?

That imposes a constraint T: Default.

What you can do instead is self.and_then(core::convert::identity),
since it holds that (>>= id) = join.

@rust-highfive

This comment was marked as outdated.

Copy link
Collaborator

commented Apr 25, 2019

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:14062c86:start=1556197677091790503,finish=1556197679129041419,duration=2037250916
$ 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
$ export AWS_ACCESS_KEY_ID=AKIA46X5W6CZEJZ6XT55
---
[00:04:30]    Compiling build_helper v0.1.0 (/checkout/src/build_helper)
[00:04:33] error[E0433]: failed to resolve: use of undeclared type or module `convert`
[00:04:33]     --> src/libcore/option.rs:1435:23
[00:04:33]      |
[00:04:33] 1435 |         self.and_then(convert::identity)
[00:04:33]      |                       ^^^^^^^ use of undeclared type or module `convert`
[00:04:35]    Compiling compiler_builtins v0.1.10
[00:04:35]    Compiling cmake v0.1.38
[00:04:35]    Compiling backtrace-sys v0.1.27
[00:04:38]    Compiling std v0.0.0 (/checkout/src/libstd)
---
travis_time:end:0341417c:start=1556197978828891349,finish=1556197978833763162,duration=4871813
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:1a3a36ed
$ 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:162208ba
travis_time:start:162208ba
$ 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:161d5928
$ 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)

@rust-highfive

This comment was marked as resolved.

Copy link
Collaborator

commented Apr 25, 2019

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:1099e3f0:start=1556198265995629787,finish=1556198268549277999,duration=2553648212
$ 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
$ export AWS_ACCESS_KEY_ID=AKIA46X5W6CZEJZ6XT55
---
[00:04:11]    Compiling unwind v0.0.0 (/checkout/src/libunwind)
[00:04:14] error[E0433]: failed to resolve: use of undeclared type or module `core`
[00:04:14]     --> src/libcore/option.rs:1435:23
[00:04:14]      |
[00:04:14] 1435 |         self.and_then(core::convert::identity)
[00:04:14] 
[00:04:16]    Compiling compiler_builtins v0.1.10
[00:04:16]    Compiling cmake v0.1.38
[00:04:16]    Compiling backtrace-sys v0.1.27
---
travis_time:end:0949c493:start=1556198549555944115,finish=1556198549560357787,duration=4413672
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:029a6678
$ 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:0b09f5f6
travis_time:start:0b09f5f6
$ 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:0bdc9a20
$ 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)

@Centril

This comment was marked as resolved.

Copy link
Contributor

commented Apr 25, 2019

[00:04:14] error[E0433]: failed to resolve: use of undeclared type or module core
[00:04:14] --> src/libcore/option.rs:1435:23
[00:04:14] |
[00:04:14] 1435 | self.and_then(core::convert::identity)

You are inside libcore, so you have to use crate::convert::identity.

@Centril

This comment has been minimized.

Copy link
Contributor

commented Apr 25, 2019

@ethanboxx once you're done with the changes, can you please squash them into a single commit?

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

commented Apr 25, 2019

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:09cbb92c:start=1556199268327592591,finish=1556199270489011385,duration=2161418794
$ 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
$ export AWS_ACCESS_KEY_ID=AKIA46X5W6CZEJZ6XT55
---
[00:30:00]    Compiling chalk-macros v0.1.0
[00:30:04]    Compiling humantime v1.2.0
[00:30:04]    Compiling backtrace-sys v0.1.27
[00:30:04]    Compiling miniz-sys v0.1.11
[00:30:04] error[E0283]: type annotations required: cannot resolve `std::option::Option<_>: std::convert::Into<std::option::Option<&str>>`
[00:30:04]    |
[00:30:04]    |
[00:30:04] 12 |         .define("MINIZ_NO_STDIO", None)
[00:30:04] 
[00:30:04] error: aborting due to previous error
[00:30:04] 
[00:30:04] For more information about this error, try `rustc --explain E0283`.
---
travis_time:end:024dc3af:start=1556201087937006377,finish=1556201087942299209,duration=5292832
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:0c329b53
$ 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:0d75f2e1
$ cat ./obj/build/x86_64-unknown-linux-gnu/native

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)

@ethanboxx

This comment has been minimized.

Copy link
Contributor Author

commented Apr 25, 2019

@Centril I dont understand this error. Can you explain why this is failing?

@Centril

This comment has been minimized.

Copy link
Contributor

commented Apr 25, 2019

@ethanboxx It seems to me you are getting a type inference error because you are giving the compiler too many options to pick from. Try removing the implementation and that should fix it.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

commented Apr 25, 2019

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:17acb560:start=1556204635745974475,finish=1556204637832352408,duration=2086377933
$ 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
$ export AWS_ACCESS_KEY_ID=AKIA46X5W6CZEJZ6XT55
---
travis_time:start:test_assembly
Check compiletest suite=assembly mode=assembly (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:20:28] 
[01:20:28] running 9 tests
[01:20:28] iiiiiiiii
[01:20:28] 
[01:20:28]  finished in 0.146
[01:20:28] 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:20:44] 
[01:20:44] running 121 tests
[01:21:09] .iiiii...i.....i..i...i..i.i.i..i.ii...i.....i..i....i..........iiii..........i...ii...i.......ii.i. 100/121
[01:21:14] i.i......iii.i.....ii
[01:21:14] 
[01:21:14]  finished in 30.498
[01:21:14] travis_fold:end:test_debuginfo

---
[01:36:27] .................................................................................................... 1600/2309
[01:36:39] .................................................................................................... 1700/2309
[01:36:53] .................................................................................................... 1800/2309
[01:37:07] .................................................................................................... 1900/2309
[01:37:20] .......................F............................................................................ 2000/2309
[01:37:53] .................................................................................................... 2200/2309
[01:38:10] ................i................................................................................... 2300/2309
[01:38:11] .........
[01:38:11] failures:
[01:38:11] failures:
[01:38:11] 
[01:38:11] ---- option.rs - option::Option<Option<T>>::flatten (line 1424) stdout ----
[01:38:11] error[E0658]: use of unstable library feature 'option_flattening'
[01:38:11]  --> option.rs:1426:23
[01:38:11]   |
[01:38:11] 5 | assert_eq!(Some(6), x.flatten());
[01:38:11]   |
[01:38:11]   = note: for more information, see https://github.com/rust-lang/rust/issues/60258
[01:38:11]   = note: for more information, see https://github.com/rust-lang/rust/issues/60258
[01:38:11]   = help: add #![feature(option_flattening)] to the crate attributes to enable
[01:38:11] error[E0658]: use of unstable library feature 'option_flattening'
[01:38:11]  --> option.rs:1429:20
[01:38:11]   |
[01:38:11]   |
[01:38:11] 8 | assert_eq!(None, x.flatten());
[01:38:11]   |
[01:38:11]   = note: for more information, see https://github.com/rust-lang/rust/issues/60258
[01:38:11]   = note: for more information, see https://github.com/rust-lang/rust/issues/60258
[01:38:11]   = help: add #![feature(option_flattening)] to the crate attributes to enable
[01:38:11] error[E0658]: use of unstable library feature 'option_flattening'
[01:38:11]   --> option.rs:1432:20
[01:38:11]    |
[01:38:11]    |
[01:38:11] 11 | assert_eq!(None, x.flatten());
[01:38:11]    |
[01:38:11]    = note: for more information, see https://github.com/rust-lang/rust/issues/60258
[01:38:11]    = note: for more information, see https://github.com/rust-lang/rust/issues/60258
[01:38:11]    = help: add #![feature(option_flattening)] to the crate attributes to enable
[01:38:11] error: aborting due to 3 previous errors
[01:38:11] 
[01:38:11] For more information about this error, try `rustc --explain E0658`.
[01:38:11] For more information about this error, try `rustc --explain E0658`.
[01:38:11] thread 'option.rs - option::Option<Option<T>>::flatten (line 1424)' panicked at 'couldn't compile the test', src/librustdoc/test.rs:310:13
[01:38:11] 
[01:38:11] 
[01:38:11] failures:
[01:38:11]     option.rs - option::Option<Option<T>>::flatten (line 1424)
[01:38:11]     option.rs - option::Option<Option<T>>::flatten (line 1424)
[01:38:11] 
[01:38:11] test result: FAILED. 2297 passed; 1 failed; 11 ignored; 0 measured; 0 filtered out
[01:38:11] 
[01:38:11] error: test failed, to rerun pass '--doc'
[01:38:11] 
[01:38:11] 
[01:38:11] 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:38:11] 
[01:38:11] 
[01:38:11] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:38:11] Build completed unsuccessfully in 0:29:16
[01:38:11] Build completed unsuccessfully in 0:29:16
[01:38:11] make: *** [check] Error 1
[01:38:11] Makefile:48: recipe for target 'check' failed
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:0028eda4
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Thu Apr 25 16:42:20 UTC 2019
---
travis_time:end:0857dbe6:start=1556210542191347728,finish=1556210542245854899,duration=54507171
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:059e1a58
$ 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:079e6d16
$ 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)

@ethanboxx

This comment has been minimized.

Copy link
Contributor Author

commented Apr 25, 2019

@Centril Whats the best way to solve this new issue.

@cogmover

This comment has been minimized.

Copy link

commented Apr 25, 2019

TL;DR: Add #![feature(option_flattening)] at the start of the doc test, and move the attributes so they'll be below the doc comment (right above the method).
The first change fixes the issue, while the second one is to conform to the established style.

Documentation tests are external to the crate they're testing, so the x.flatten() in your doc test works the same way as writing x.flatten() in your own crate.
However, Option::flatten is unstable, so you'd have to opt into it with the feature gate, so adding #[feature(option_flattening)] at the start is what you need to solve the issue.
Vec has some unstable methods as well, and you can use them as a reference to make sure you're doing everything right.

In other places in the standard library, the #[inline] and #[unstable] attributes are below the documentation comment, just above the method itself. @Centril, is the "doc comments above attributes" style official and documented somewhere? I'm asking you because you've commented here before (and are generally helpful 😄), but if you're not the right person to ask just redirect the question to whoever is.

@Centril Centril removed this from the 1.36 milestone Apr 26, 2019

@ethanboxx ethanboxx force-pushed the ethanboxx:master branch 2 times, most recently from 99aab47 to ec10b09 Apr 26, 2019

@ethanboxx

This comment has been minimized.

Copy link
Contributor Author

commented Apr 26, 2019

@Centril @cogmover @Keruspe Thanks for all the invaluable help. Looks like everything is working now.

@alexcrichton

This comment has been minimized.

Copy link
Member

commented Apr 26, 2019

Thanks for the PR @ethanboxx! I'm personally a bit wary on adding this method though since I feel like what it morally is striving to do is collapse any amount of inner options, but it doesn't handle, for example, Option<Option<Option<T>>> -> T. This definitely works for two layers deep, but I could see how ergonomically it's intended (and the name sort of implies) that it folds everything on the inside.

The Option type is also very core to Rust and additions to its API shouldn't be taken lightly, since now Rust programmers will have to recognize what .flatten() is doing when they see it in the wild (another method to keep in mind with Option). Now that of course doesn't mean we can't extend its API, just that we need to be careful in doing so!

@Centril

This comment has been minimized.

Copy link
Contributor

commented Apr 26, 2019

@alexcrichton

but it doesn't handle, for example, Option<Option<Option<T>>> -> T. This definitely works for two layers deep, but I could see how ergonomically it's intended (and the name sort of implies) that it folds everything on the inside.

Note that this is the same for iter.flatten(). That's just how monadic join works. Is there a particular difference wrt. Option? Note that unnesting was also discussed in the tracking issue for Iterator::flatten: #48213.

@ethanboxx

This comment has been minimized.

Copy link
Contributor Author

commented Apr 26, 2019

@alexcrichton You are correct. My original intention was for it flatten all nested layers, however, it quickly became apparent that it was not possible. I have added extra documentation to clarify this in a similar way iter.flatten() is documented.

@ethanboxx ethanboxx force-pushed the ethanboxx:master branch from 8a5b704 to d79c522 Apr 26, 2019

@ethanboxx ethanboxx force-pushed the ethanboxx:master branch from d79c522 to fa7ba66 Apr 26, 2019

@alexcrichton

This comment has been minimized.

Copy link
Member

commented Apr 29, 2019

Ok, seems reasonable to me!

@bors: r+

@bors

This comment has been minimized.

Copy link
Contributor

commented Apr 29, 2019

📌 Commit fa7ba66 has been approved by alexcrichton

Centril added a commit to Centril/rust that referenced this pull request Apr 29, 2019

Rollup merge of rust-lang#60256 - ethanboxx:master, r=alexcrichton
Option::flatten

This PR makes this possible.
```rust
assert_eq!(Some(6), Some(Some(6)).flatten());
assert_eq!(Some(6), Some(Some(6)).into());
```
@Centril

This comment has been minimized.

Copy link
Contributor

commented Apr 29, 2019

@bors rollup

bors added a commit that referenced this pull request Apr 29, 2019

Auto merge of #60377 - Centril:rollup-42fxe9u, r=Centril
Rollup of 9 pull requests

Successful merges:

 - #59946 (Fix equivalent string in escape_default docs)
 - #60256 (Option::flatten)
 - #60305 (hir: remove LoweredNodeId)
 - #60334 (Stabilized vectored IO)
 - #60353 (Add test not to forget resolved ICE)
 - #60356 (Stabilize str::as_mut_ptr)
 - #60358 (Clarify the short explanation of E0207)
 - #60359 (resolve: Consider erroneous imports used to avoid duplicate diagnostics)
 - #60360 (Add test case for labeled break in const assignment)

Failed merges:

r? @ghost

@bors bors merged commit fa7ba66 into rust-lang:master Apr 29, 2019

1 check passed

Travis CI - Pull Request Build Passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.