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 better tests for hidden lifetimes in impl trait #60756

Merged
merged 1 commit into from
May 29, 2019

Conversation

matthewjasper
Copy link
Contributor

cc #60670

@rust-highfive
Copy link
Collaborator

r? @nikomatsakis

(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 May 12, 2019
Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

Good idea to add a test! But since this test is kind of testing for a tricky scenario, it'd be good to explain the scenario in more detail, so when we trip over it, we can understand what happened. =)

@@ -0,0 +1,53 @@
// Test to show actual unsound behaviour that occurs when the hidden lifetime
// check is removed from impl trait types.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you cc the relevant issues/PRs here in the test, to help us track down more info later?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or else expand this comment a bit?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or both? :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Something like:


Test to show what would happen if we were not careful and permitted lifetimes to escape through an impl trait. In this case, we are returning a &'a mut &'b T, but the 'b does not appear in the impl trait type. We can use this to engineer an unsoundness. (XXX perhaps a more detailed explanation)

@nikomatsakis nikomatsakis 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-review Status: Awaiting review from the assignee but also interested parties. labels May 17, 2019
@matthewjasper matthewjasper force-pushed the extra-impl-trait-tests branch from 05ebc79 to 32c790c Compare May 17, 2019 22:02
@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:05399439:start=1558130585300147390,finish=1558130672456236753,duration=87156089363
$ 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
---
[01:15:06] .................................................................................................... 1400/5531
[01:15:09] .................................................................................................... 1500/5531
[01:15:12] .................................................................................................... 1600/5531
[01:15:16] .............................i...................................................................... 1700/5531
[01:15:19] ......................................................................................F............. 1800/5531
[01:15:27] .................................................................................................... 2000/5531
[01:15:30] ..........................................................................i......................... 2100/5531
[01:15:34] .................................................................................................... 2200/5531
[01:15:38] .................................................................................................... 2300/5531
---
[01:17:47] 
[01:17:47] ---- [ui] ui/impl-trait/hidden-lifetimes.rs stdout ----
[01:17:47] diff of stderr:
[01:17:47] 
[01:17:47] 1 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
[01:17:47] -   --> $DIR/hidden-lifetimes.rs:23:54
[01:17:47] +   --> $DIR/hidden-lifetimes.rs:28:54
[01:17:47] 3    |
[01:17:47] 4 LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a {
[01:17:47] 
[01:17:47] 6    |
[01:17:47] 6    |
[01:17:47] - note: hidden type `&'a mut &'b T` captures the lifetime 'b as defined on the function body at 23:17
[01:17:47] -   --> $DIR/hidden-lifetimes.rs:23:17
[01:17:47] + note: hidden type `&'a mut &'b T` captures the lifetime 'b as defined on the function body at 28:17
[01:17:47] +   --> $DIR/hidden-lifetimes.rs:28:17
[01:17:47] 9    |
[01:17:47] 10 LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a {
[01:17:47] 
[01:17:47] 12 
[01:17:47] 12 
[01:17:47] 13 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
[01:17:47] -   --> $DIR/hidden-lifetimes.rs:35:70
[01:17:47] +   --> $DIR/hidden-lifetimes.rs:45:70
[01:17:47] 15    |
[01:17:47] 16 LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a {
[01:17:47] 
[01:17:47] 18    |
[01:17:47] 18    |
[01:17:47] - note: hidden type `std::rc::Rc<std::cell::RefCell<&'b T>>` captures the lifetime 'b as defined on the function body at 35:24
[01:17:47] -   --> $DIR/hidden-lifetimes.rs:35:24
[01:17:47] + note: hidden type `std::rc::Rc<std::cell::RefCell<&'b T>>` captures the lifetime 'b as defined on the function body at 45:24
[01:17:47] +   --> $DIR/hidden-lifetimes.rs:45:24
[01:17:47] 21    |
[01:17:47] 22 LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a {
[01:17:47] 
[01:17:47] 
[01:17:47] The actual stderr differed from the expected stderr.
[01:17:47] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/impl-trait/hidden-lifetimes/hidden-lifetimes.stderr
[01:17:47] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/impl-trait/hidden-lifetimes/hidden-lifetimes.stderr
[01:17:47] To update references, rerun the tests and pass the `--bless` flag
[01:17:47] To only update this specific test, also pass `--test-args impl-trait/hidden-lifetimes.rs`
[01:17:47] error: 1 errors occurred comparing output.
[01:17:47] status: exit code: 1
[01:17:47] status: exit code: 1
[01:17:47] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/impl-trait/hidden-lifetimes.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/impl-trait/hidden-lifetimes" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/impl-trait/hidden-lifetimes/auxiliary" "-A" "unused"
[01:17:47] ------------------------------------------
[01:17:47] 
[01:17:47] ------------------------------------------
[01:17:47] stderr:
[01:17:47] stderr:
[01:17:47] ------------------------------------------
[01:17:47] error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
[01:17:47]   --> /checkout/src/test/ui/impl-trait/hidden-lifetimes.rs:28:54
[01:17:47]    |
[01:17:47] LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a {
[01:17:47]    |
[01:17:47]    |
[01:17:47] note: hidden type `&'a mut &'b T` captures the lifetime 'b as defined on the function body at 28:17
[01:17:47]   --> /checkout/src/test/ui/impl-trait/hidden-lifetimes.rs:28:17
[01:17:47]    |
[01:17:47] LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a {
[01:17:47] 
[01:17:47] 
[01:17:47] error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
[01:17:47]   --> /checkout/src/test/ui/impl-trait/hidden-lifetimes.rs:45:70
[01:17:47]    |
[01:17:47] LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a {
[01:17:47]    |
[01:17:47]    |
[01:17:47] note: hidden type `std::rc::Rc<std::cell::RefCell<&'b T>>` captures the lifetime 'b as defined on the function body at 45:24
[01:17:47]   --> /checkout/src/test/ui/impl-trait/hidden-lifetimes.rs:45:24
[01:17:47]    |
[01:17:47] LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a {
[01:17:47] 
[01:17:47] error: aborting due to 2 previous errors
[01:17:47] 
[01:17:47] For more information about this error, try `rustc --explain E0700`.
---
[01:17:47] thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:512:22
[01:17:47] note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
[01:17:47] 
[01:17:47] 
[01:17:47] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/ui" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-6.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "6.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
[01:17:47] 
[01:17:47] 
[01:17:47] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:17:47] Build completed unsuccessfully in 0:04:52
[01:17:47] Build completed unsuccessfully in 0:04:52
[01:17:47] make: *** [check] Error 1
[01:17:47] Makefile:48: recipe for target 'check' failed
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:05b0cb48
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Fri May 17 23:22:29 UTC 2019
---
travis_time:end:0e03ab1c:start=1558135350289765692,finish=1558135350294189820,duration=4424128
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:0b2ab3d0
$ 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:037c34c7
travis_time:start:037c34c7
$ 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:00f50919
$ 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)

@matthewjasper matthewjasper force-pushed the extra-impl-trait-tests branch from 32c790c to 53e0474 Compare May 18, 2019 12:17
Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

Thanks!

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented May 28, 2019

📌 Commit 53e0474 has been approved by nikomatsakis

@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 May 28, 2019
@nikomatsakis
Copy link
Contributor

@bors rollup

Centril added a commit to Centril/rust that referenced this pull request May 28, 2019
…s, r=nikomatsakis

Add better tests for hidden lifetimes in impl trait

cc rust-lang#60670
Centril added a commit to Centril/rust that referenced this pull request May 28, 2019
…s, r=nikomatsakis

Add better tests for hidden lifetimes in impl trait

cc rust-lang#60670
Centril added a commit to Centril/rust that referenced this pull request May 28, 2019
…s, r=nikomatsakis

Add better tests for hidden lifetimes in impl trait

cc rust-lang#60670
bors added a commit that referenced this pull request May 28, 2019
Rollup of 9 pull requests

Successful merges:

 - #60742 (Allow const parameters in array sizes to be unified)
 - #60756 (Add better tests for hidden lifetimes in impl trait)
 - #60928 (Changes the type `mir::Mir` into `mir::Body`)
 - #61024 (tests: Centralize proc macros commonly used for testing)
 - #61157 (BufReader: In Seek impl, remove extra discard_buffer call)
 - #61195 (Special-case `.llvm` in mangler)
 - #61202 (Print PermissionExt::mode() in octal in Documentation Examples)
 - #61259 (Mailmap fixes)
 - #61273 (mention that MaybeUninit is a bit like Option)

Failed merges:

r? @ghost
@bors bors merged commit 53e0474 into rust-lang:master May 29, 2019
@matthewjasper matthewjasper deleted the extra-impl-trait-tests branch May 31, 2019 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

4 participants