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

[WIP] Rollup of three NLL PR's #54532

Closed
wants to merge 19 commits into from
Closed

Conversation

pnkfelix
Copy link
Member

mikhail-m1 and others added 19 commits September 23, 2018 16:31
This allows treating the "fake" match borrows differently from shared
borrows.
As we are now creating borrows of places that may not be valid for
borrow checking matches, these have to be removed to avoid generating
broken code.
This name better reflects the asymmetry of this function.
When dropping a self-borrowing struct we shouldn't add a "values in a
scope are dropped in the opposite order they are defined" message,
since there is only one value being dropped.
Previously, we would split the drop access into multiple checks for each
field of a struct/tuple/closure and through `Box` dereferences. This
changes this to check if the borrow is accessed by the drop in
places_conflict.

This also allows us to handle enums in a simpler way, since we don't
have to construct any new places.
… test this PR.

DO NOT LAND WITH THIS COMMIT.
@rust-highfive
Copy link
Collaborator

r? @davidtwco

(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 Sep 24, 2018
@pnkfelix pnkfelix changed the title Rollup of three NLL PR's [WIP] Rollup of three NLL PR's Sep 24, 2018
@pnkfelix
Copy link
Member Author

(marking as [WIP] while I run test bulids atop specific targets like WASM, as demonstrated in cd69fb0.)

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-5.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.
[00:52:38] ....................................................................................................
[00:52:41] ......................................................i.............................................
[00:52:44] ....................................................................................................
[00:52:47] ....................................................................................................
[00:52:49] ...iiiiiiiii........................................................................................
[00:52:55] ....................................................................................................
[00:52:58] .......................................................................................i............
[00:53:01] ....................................................................................................
[00:53:04] ..........................................i.i..ii...................................................
---
[00:57:24] ....................................................................................................
[00:57:32] ....................................................................................................
[00:57:40] ....................................................................................................
[00:57:45] ....................................................................................................
[00:57:48] ......................F.............................................................................
[00:57:54] ...i................................................................................................
[00:57:57] ....................................................................................................
[00:58:00] ....................................................................................................
[00:58:02] ..................i.ii.ii.ii.............................i..........................................
[00:58:02] ..................i.ii.ii.ii.............................i..........................................
[00:58:03] ..................
[00:58:03] failures:
[00:58:03] 
[00:58:03] ---- [ui (nll)] ui/span/borrowck-ref-into-rvalue.rs stdout ----
[00:58:03] diff of stderr:
[00:58:03] 
[00:58:03] - error[E0597]: borrowed value does not live long enough
[00:58:03] + error[E0714]: temporary value dropped while borrowed
[00:58:03] 3    |
[00:58:03] 3    |
[00:58:03] 4 LL |     match Some("Hello".to_string()) {
[00:58:03] 
[00:58:03] -    |           ^^^^^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough
[00:58:03] +    |           ^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
[00:58:03] 6 ...
[00:58:03] 7 LL |     }
[00:58:03] -    |     - temporary value only lives until here
[00:58:03] +    |     - temporary value is freed at the end of this statement
[00:58:03] 9 LL |     println!("{}", *msg);
[00:58:03] 11    |
[00:58:03] 
[00:58:03] 13 
[00:58:03] 14 error: aborting due to previous error
[00:58:03] 14 error: aborting due to previous error
[00:58:03] 15 
[00:58:03] - For more information about this error, try `rustc --explain E0597`.
[00:58:03] + For more information about this error, try `rustc --explain E0714`.
[00:58:03] 17 
[00:58:03] 
[00:58:03] 
[00:58:03] The actual stderr differed from the expected stderr.
[00:58:03] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/span/borrowck-ref-into-rvalue.nll/borrowck-ref-into-rvalue.nll.stderr
[00:58:03] To update references, rerun the tests and pass the `--bless` flag
[00:58:03] To only update this specific test, also pass `--test-args span/borrowck-ref-into-rvalue.rs`
[00:58:03] error: 1 errors occurred comparing output.
[00:58:03] status: exit code: 1
[00:58:03] status: exit code: 1
[00:58:03] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/span/borrowck-ref-into-rvalue.rs" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/span/borrowck-ref-into-rvalue.nll/a" "-Zborrowck=mir" "-Ztwo-phase-borrows" "-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/span/borrowck-ref-into-rvalue.nll/auxiliary" "-A" "unused"
[00:58:03] ------------------------------------------
[00:58:03] 
[00:58:03] ------------------------------------------
[00:58:03] stderr:
[00:58:03] stderr:
[00:58:03] ------------------------------------------
[00:58:03] {"message":"temporary value dropped while borrowed","code":{"code":"E0714","explanation":"\nThis error indicates that a temporary value is being dropped\nwhile a borrow is still in active use.\n\nErroneous code example:\n\n```compile_fail,E0714\n# #![feature(nll)]\nfn foo() -> i32 { 22 }\nfn bar(x: &i32) -> &i32 { x }\nlet p = bar(&foo());\n         // ------ creates a temporary\nlet q = *p;\n```\n\nHere, the expression `&foo()` is borrowing the expression\n`foo()`. As `foo()` is call to a function, and not the name of\na variable, this creates a **temporary** -- that temporary stores\nthe return value from `foo()` so that it can be borrowed.\nSo you might imagine that `let p = bar(&foo())` is equivalent\nto this:\n\n```compile_fail,E0597\n# fn foo() -> i32 { 22 }\n# fn bar(x: &i32) -> &i32 { x }\nlet p = {\n  let tmp = foo(); // the temporary\n  bar(&tmp)\n}; // <-- tmp is freed as we exit this block\nlet q = p;\n```\n\nWhenever a temporary is created, it is automatically dropped (freed)\naccording to fixed rules. Ordinarily, the temporary is dropped\nat the end of the enclosing statement -- in this case, after the `let`.\nThis is illustrated in the example above by showing that `tmp` would\nbe freed as we exit the block.\n\nTo fix this problem, you need to create a local variable\nto store the value in rather than relying on a temporary.\nFor example, you might change the original program to\nthe following:\n\n```\nfn foo() -> i32 { 22 }\nfn bar(x: &i32) -> &i32 { x }\nlet value = foo(); // dropped at the end of the enclosing block\nlet p = bar(&value);\nlet q = *p;\n```\n\nBy introducing the explicit `let value`, we allocate storage\nthat will last until the end of the enclosing block (when `value`\ngoes out of scope). When we borrow `&value`, we are borrowing a\nlocal variable that already exists, and hence no temporary is created.\n\nTemporaries are not always dropped at the end of the enclosing\nstatement. In simple cases where the `&` expression is immediately\nstored into a variable, the compiler will automatically extend\nthe lifetime of the temporary until the end of the enclosinb\nblock. Therefore, an alternative way to fix the original\nprogram is to write `let tmp = &foo()` and not `let tmp = foo()`:\n\n```\nfn foo() -> i32 { 22 }\nfn bar(x: &i32) -> &i32 { x }\nlet value = &foo();\nlet p = bar(value);\nlet q = *p;\n```\n\nHere, we are still borrowing `foo()`, but as the borrow is assigned\ndirectly into a variable, the temporary will not be dropped until\nthe end of the enclosing block. Similar rules apply when temporaries\nare stored into aggregate structures like a tuple or struct:\n\n```\n// Here, two temporaries are created, but\n// as they are stored directly into `value`,\n// they are not dropped until the end of the\n// enclosing block.\nfn foo() -> i32 { 22 }\nlet value = (&foo(), &foo());\n```\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/span/borrowck-ref-into-rvalue.rs","byte_start":502,"byte_end":527,"line_start":13,"line_end":13,"column_start":11,"column_end":36,"is_primary":true,"text":[{"text":"    match Some(\"Hello\".to_string()) {","highlight_start":11,"highlight_end":36}],"label":"creates a temporary which is freed while still in use","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"/checkout/src/test/ui/span/borrowck-ref-into-rvalue.rs","byte_start":680,"byte_end":681,"line_start":19,"line_end":19,"column_start":5,"column_end":6,"is_primary":false,"text":[{"text":"    }","highlight_start":5,"highlight_end":6}],"label":"temporary value is freed at the end of this statement","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"/checkout/src/test/ui/span/borrowck-ref-into-rvalue.rs","byte_start":701,"byte_end":705,"line_start":20,"line_end":20,"column_start":20,"column_end":24,"is_primary":false,"text":[{"text":"    println!(\"{}\", *msg);","highlight_start":20,"highlight_end":24}],"label":"borrow later used here","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"consider using a `let` binding to create a longer lived value","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"error[E0714]: temporary value dropped while borrowed\n  --> /checkout/src/test/ui/span/borrowck-ref-into-rvalue.rs:13:11\n   |\nLL |     match Some(\"Hello\".to_string()) {\n   |           ^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use\n...\nLL |     }\n   |     - temporary value is freed at the end of this statement\nLL |     println!(\"{}\", *msg);\n   |                    ---- borrow later used here\n   |\n   = note: consider using a `let` binding to create a longer lived value\n\n"}
[00:58:03] {"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error\n\n"}
[00:58:03] {"message":"For more information about this error, try `rustc --explain E0714`.","code":null,"level":"","spans":[],"children":[],"rendered":"For more information about this error, try `rustc --explain E0714`.\n"}
[00:58:03] ------------------------------------------
[00:58:03] 
[00:58:03] thread '[ui (nll)] ui/span/borrowck-ref-into-rvalue.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:3238:9
[00:58:03] note: Run with `RUST_BACKTRACE=1` for a backtrace.
---
[00:58:03] 
[00:58:03] thread 'main' panicked at 'Some tests failed', tools/compiletest/src/main.rs:496:22
[00:58:03] 
[00:58:03] 
[00:58:03] 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-5.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Zunstable-options " "--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" "5.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" "--compare-mode" "nll"
[00:58:03] 
[00:58:03] 
[00:58:03] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[00:58:03] Build completed unsuccessfully in 0:13:46
[00:58:03] Build completed unsuccessfully in 0:13:46
[00:58:03] Makefile:58: recipe for target 'check' failed
[00:58:03] make: *** [check] Error 1

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:04c83124
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
---
travis_time:end:12681d38:start=1537808522617549537,finish=1537808522621259350,duration=3709813
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:084a090b
$ 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:180bf48c
travis_time:start:180bf48c
$ 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:0f571afc
$ 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)

@bors
Copy link
Contributor

bors commented Sep 24, 2018

☔ The latest upstream changes (presumably #54509) made this pull request unmergeable. Please resolve the merge conflicts.

@pnkfelix
Copy link
Member Author

Both #54509 and #53438 landed so this "rollup" does not need to stay open. I'll just focus my attention on getting #54164 landed on its own.

@pnkfelix pnkfelix closed this Sep 25, 2018
@Centril Centril added the rollup A PR which is a rollup label Oct 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rollup A PR which is a rollup S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants