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

[NLL] Use new region infer errors when explaining borrows #55069

Merged
merged 4 commits into from
Oct 21, 2018

Conversation

matthewjasper
Copy link
Contributor

Use the new free region infer errors for explaining borrows

This gives at least some explanation for why a borrow is expected to
last for a certain free region. Also:

  • Reports E0373: "closure may outlive the current function" with NLL.
  • Special cases the case of returning a reference to (or value referencing) a local variable or temporary (E0515).
  • Special case assigning a reference to a local variable in a closure to a captured variable. (E0521)

Closes #51026 - regions-nested-fns-2.rs isn't changed to that diagnostic, since that would not be the correct error here.
Closes #51169
cc #53882 - The error is (IMO) better now, but it could be better when we trace lifetimes in these error messages.

r? @nikomatsakis cc @pnkfelix

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 14, 2018
@memoryruins memoryruins added the A-NLL Area: Non Lexical Lifetimes (NLL) label Oct 16, 2018
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.

This is awesome. I proposed some tweaks to wording. Thoughts?

@nikomatsakis
Copy link
Contributor

r=me but r? @pnkfelix on the one remaining question

@pnkfelix
Copy link
Member

@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented Oct 17, 2018

📌 Commit 22458404d6bb34a0754dd2614b0417a4ddb7b66c 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-review Status: Awaiting review from the assignee but also interested parties. labels Oct 17, 2018
@bors
Copy link
Contributor

bors commented Oct 18, 2018

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

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 18, 2018
@matthewjasper matthewjasper force-pushed the explain-free-region-liveness branch 2 times, most recently from f001861 to 4418569 Compare October 18, 2018 21:59
@matthewjasper
Copy link
Contributor Author

@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented Oct 18, 2018

📌 Commit 4418569d8feb686360a71bde2c6172af85196bbd 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 Oct 18, 2018
@bors
Copy link
Contributor

bors commented Oct 20, 2018

⌛ Testing commit 4418569d8feb686360a71bde2c6172af85196bbd with merge 1943e725a2e9dd16eca66aa63b642e9618a0382b...

@bors
Copy link
Contributor

bors commented Oct 20, 2018

💔 Test failed - status-appveyor

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 20, 2018
@rust-highfive
Copy link
Collaborator

The job dist-i586-gnu-i586-i686-musl 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:47:05] 1 error[E0621]: explicit lifetime required in the type of `x`
[00:47:05] -   --> $DIR/generator-region-requirements.rs:11:9
[00:47:05] +   --> $DIR/generator-region-requirements.rs:15:51
[00:47:05] 3    |
[00:47:05] 4 LL | fn dangle(x: &mut i32) -> &'static mut i32 {
[00:47:05] 5    |              -------- help: add explicit lifetime `'static` to the type of `x`: `&'static mut i32`
[00:47:05] 6 ...
[00:47:05] 6 ...
[00:47:05] - LL |         x
[00:47:05] -    |         ^ lifetime `'static` required
[00:47:05] + LL |             GeneratorState::Complete(c) => return c,
[00:47:05] +    |                                                   ^ lifetime `'static` required
[00:47:05] 10 error: aborting due to previous error
[00:47:05] 11 
[00:47:05] 
[00:47:05] 
[00:47:05] 
[00:47:05] The actual stderr differed from the expected stderr.
[00:47:05] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/generator/generator-region-requirements.nll/generator-region-requirements.nll.stderr
[00:47:05] To update references, rerun the tests and pass the `--bless` flag
[00:47:05] To only update this specific test, also pass `--test-args generator/generator-region-requirements.rs`
[00:47:05] 
[00:47:05] error in revision `nll`: 1 errors occurred comparing output.
[00:47:05] status: exit code: 1
[00:47:05] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/generator/generator-region-requirements.rs" "--target=i586-unknown-linux-gnu" "--cfg" "nll" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/generator/generator-region-requirements.nll/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/i586-unknown-linux-gnu/native/rust-test-helpers" "-Clinker=cc" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/generator/generator-region-requirements.nll/auxiliary" "-A" "unused"
[00:47:05] ------------------------------------------
[00:47:05] 
[00:47:05] ------------------------------------------
[00:47:05] stderr:
[00:47:05] stderr:
[00:47:05] ------------------------------------------
[00:47:05] {"message":"explicit lifetime required in the type of `x`","code":{"code":"E0621","explanation":"\nThis error code indicates a mismatch between the lifetimes appearing in the\nfunction signature (i.e., the parameter types and the return type) and the\ndata-flow found in the function body.\n\nErroneous code example:\n\n```compile_fail,E0621\nfn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 { // error: explicit lifetime\n                                             //        required in the type of\n                                             //        `y`\n    if x > y { x } else { y }\n}\n```\n\nIn the code above, the function is returning data borrowed from either `x` or\n`y`, but the `'a` annotation indicates that it is returning data only from `x`.\nTo fix the error, the signature and the body must be made to match. Typically,\nthis is done by updating the function signature. So, in this case, we change\nthe type of `y` to `&'a i32`, like so:\n\n```\nfn foo<'a>(x: &'a i32, y: &'a i32) -> &'a i32 {\n    if x > y { x } else { y }\n}\n```\n\nNow the signature indicates that the function data borrowed from either `x` or\n`y`. Alternatively, you could change the body to not return data from `y`:\n\n```\nfn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 {\n    x\n}\n```\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/generator/generator-region-requirements.rs","byte_start":364,"byte_end":365,"line_start":15,"line_end":15,"column_start":51,"column_end":52,"is_primary":true,"text":[{"text":"            GeneratorState::Complete(c) => return c,","highlight_start":51,"highlight_end":52}],"label":"lifetime `'static` required","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"add explicit lifetime `'static` to the type of `x`","code":null,"level":"help","spans":[{"file_name":"/checkout/src/test/ui/generator/generator-region-requirements.rs","byte_start":180,"byte_end":188,"line_start":8,"line_end":8,"column_start":14,"column_end":22,"is_primary":true,"text":[{"text":"fn dangle(x: &mut i32) -> &'static mut i32 {","highlight_start":14,"highlight_end":22}],"label":null,"suggested_replacement":"&'static mut i32","suggestion_applicability":"Unspecified","expansion":null}],"children":[],"rendered":null}],"rendered":"error[E0621]: explicit lifetime required in the type of `x`\n  --> /checkout/src/test/ui/generator/generator-region-requirements.rs:15:51\n   |\nLL | fn dangle(x: &mut i32) -> &'static mut i32 {\n   |              -------- help: add explicit lifetime `'static` to the type of `x`: `&'static mut i32`\n...\nLL |             GeneratorState::Complete(c) => return c,\n   |                                                   ^ lifetime `'static` required\n\n"}
[00:47:05] {"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error\n\n"}
[00:47:05] {"message":"For more information about this error, try `rustc --explain E0621`.","code":null,"level":"","spans":[],"children":[],"rendered":"For more information about this error, try `rustc --explain E0621`.\n"}
[00:47:05] ------------------------------------------
[00:47:05] 
[00:47:05] thread '[ui] ui/generator/generator-region-requirements.rs#nll' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:3284:9
[00:47:05] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[00:47:05] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[00:47:05] 
[00:47:05] ---- [ui] ui/nll/user-annotations/cast_static_lifetime.rs stdout ----
[00:47:05] diff of stderr:
[00:47:05] 
[00:47:05] 2   --> $DIR/cast_static_lifetime.rs:16:19
[00:47:05] 3    |
[00:47:05] 4 LL |     let y: &u32 = (&x) as &'static u32;
[00:47:05] -    |                   ^^^^ borrowed value does not live long enough
[00:47:05] +    |                   |
[00:47:05] +    |                   |
[00:47:05] +    |                   borrowed value does not live long enough
[00:47:05] +    |                   type annotation requires that `x` is borrowed for `'static`
[00:47:05] 6 LL | }
[00:47:05] 7    | - `x` dropped here while still borrowed
[00:47:05] -    |
[00:47:05] -    = note: borrowed value must be valid for the static lifetime...
[00:47:05] 11 error: aborting due to previous error
[00:47:05] 12 
[00:47:05] 
[00:47:05] 
[00:47:05] 
[00:47:05] The actual stderr differed from the expected stderr.
[00:47:05] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/nll/user-annotations/cast_static_lifetime/cast_static_lifetime.stderr
[00:47:05] To update references, rerun the tests and pass the `--bless` flag
[00:47:05] To only update this specific test, also pass `--test-args nll/user-annotations/cast_static_lifetime.rs`
[00:47:05] error: 1 errors occurred comparing output.
[00:47:05] status: exit code: 1
[00:47:05] status: exit code: 1
[00:47:05] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/nll/user-annotations/cast_static_lifetime.rs" "--target=i586-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/nll/user-annotations/cast_static_lifetime/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/i586-unknown-linux-gnu/native/rust-test-helpers" "-Clinker=cc" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/nll/user-annotations/cast_static_lifetime/auxiliary" "-A" "unused"
[00:47:05] ------------------------------------------
[00:47:05] 
[00:47:05] ------------------------------------------
[00:47:05] stderr:
[00:47:05] stderr:
[00:47:05] ------------------------------------------
[00:47:05] {"message":"`x` does not live long enough","code":{"code":"E0597","explanation":"\nThis error occurs because a borrow was made inside a variable which has a\ngreater lifetime than the borrowed one.\n\nExample of erroneous code:\n\n```compile_fail,E0597\nstruct Foo<'a> {\n    x: Option<&'a u32>,\n}\n\nlet mut x = Foo { x: None };\nlet y = 0;\nx.x = Some(&y); // error: `y` does not live long enough\n```\n\nIn here, `x` is created before `y` and therefore has a greater lifetime. Always\nkeep in mind that values in a scope are dropped in the opposite order they are\ncreated. So to fix the previous example, just make the `y` lifetime greater than\nthe `x`'s one:\n\n```\nstruct Foo<'a> {\n    x: Option<&'a u32>,\n}\n\nlet y = 0;\nlet mut x = Foo { x: None };\nx.x = Some(&y);\n```\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/nll/user-annotations/cast_static_lifetime.rs","byte_start":555,"byte_end":559,"line_start":16,"line_end":16,"column_start":19,"column_end":23,"is_primary":true,"text":[{"text":"    let y: &u32 = (&x) as &'static u32;","highlight_start":19,"highlight_end":23}],"label":"borrowed value does not live long enough","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"/checkout/src/test/ui/nll/user-annotations/cast_static_lifetime.rs","byte_start":577,"byte_end":578,"line_start":17,"line_end":17,"column_start":1,"column_end":2,"is_primary":false,"text":[{"text":"}","highlight_start":1,"highlight_end":2}],"label":"`x` dropped here while still borrowed","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"/checkout/src/test/ui/nll/user-annotations/cast_static_lifetime.rs","byte_start":555,"byte_end":575,"line_start":16,"line_end":16,"column_start":19,"column_end":39,"is_primary":false,"text":[{"text":"    let y: &u32 = (&x) as &'static u32;","highlight_start":19,"highlight_end":39}],"label":"type annotation requires that `x` is borrowed for `'static`","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"error[E0597]: `x` does not live long enough\n  --> /checkout/src/test/ui/nll/user-annotations/cast_static_lifetime.rs:16:19\n   |\nLL |     let y: &u32 = (&x) as &'static u32;\n   |                   ^^^^----------------\n   |                   |\n   |                   borrowed value does not live long enough\n   |                   type annotation requires that `x` is borrowed for `'static`\nLL | }\n   | - `x` dropped here while still borrowed\n\n"}
[00:47:05] {"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error\n\n"}
[00:47:05] {"message":"For more information about this error, try `rustc --explain E0597`.","code":null,"level":"","spans":[],"children":[],"rendered":"For more information about this error, try `rustc --explain E0597`.\n"}
[00:47:05] ------------------------------------------
[00:47:05] 
[00:47:05] thread '[ui] ui/nll/user-annotations/cast_static_lifetime.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:3284:9
[00:47:05] 
[00:47:05] 
[00:47:05] ---- [ui] ui/nll/user-annotations/normalization.rs stdout ----
[00:47:05] diff of stderr:
[00:47:05] 
[00:47:05] 2   --> $DIR/normalization.rs:12:31
[00:47:05] 3    |
[00:47:05] 4 LL |     let b: <() as Foo>::Out = &a; //~ ERROR
[00:47:05] -    |                               ^^ borrowed value does not live long enough
[00:47:05] +    |            ----------------   ^^ borrowed value does not live long enough
[00:47:05] +    |            |
[00:47:05] +    |            type annotation requires that `a` is borrowed for `'static`
[00:47:05] 6 LL | }
[00:47:05] 7    | - `a` dropped here while still borrowed
[00:47:05] -    |
[00:47:05] -    = note: borrowed value must be valid for the static lifetime...
[00:47:05] 11 error: aborting due to previous error
[00:47:05] 12 
[00:47:05] 
[00:47:05] 
[00:47:05] 
[00:47:05] The actual stderr differed from the expected stderr.
[00:47:05] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/nll/user-annotations/normalization/normalization.stderr
[00:47:05] To update references, rerun the tests and pass the `--bless` flag
[00:47:05] To only update this specific test, also pass `--test-args nll/user-annotations/normalization.rs`
[00:47:05] error: 1 errors occurred comparing output.
[00:47:05] status: exit code: 1
[00:47:05] status: exit code: 1
[00:47:05] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/nll/user-annotations/normalization.rs" "--target=i586-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/nll/user-annotations/normalization/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/i586-unknown-linux-gnu/native/rust-test-helpers" "-Clinker=cc" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/nll/user-annotations/normalization/auxiliary" "-A" "unused"
[00:47:05] ------------------------------------------
[00:47:05] 
[00:47:05] ------------------------------------------
[00:47:05] stderr:
[00:47:05] stderr:
[00:47:05] ------------------------------------------
[00:47:05] {"message":"`a` does not live long enough","code":{"code":"E0597","explanation":"\nThis error occurs because a borrow was made inside a variable which has a\ngreater lifetime than the borrowed one.\n\nExample of erroneous code:\n\n```compile_fail,E0597\nstruct Foo<'a> {\n    x: Option<&'a u32>,\n}\n\nlet mut x = Foo { x: None };\nlet y = 0;\nx.x = Some(&y); // error: `y` does not live long enough\n```\n\nIn here, `x` is created before `y` and therefore has a greater lifetime. Always\nkeep in mind that values in a scope are dropped in the opposite order they are\ncreated. So to fix the previous example, just make the `y` lifetime greater than\nthe `x`'s one:\n\n```\nstruct Foo<'a> {\n    x: Option<&'a u32>,\n}\n\nlet y = 0;\nlet mut x = Foo { x: None };\nx.x = Some(&y);\n```\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/nll/user-annotations/normalization.rs","byte_start":260,"byte_end":262,"line_start":12,"line_end":12,"column_start":31,"column_end":33,"is_primary":true,"text":[{"text":"    let b: <() as Foo>::Out = &a; //~ ERROR","highlight_start":31,"highlight_end":33}],"label":"borrowed value does not live long enough","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"/checkout/src/test/ui/nll/user-annotations/normalization.rs","byte_start":274,"byte_end":275,"line_start":13,"line_end":13,"column_start":1,"column_end":2,"is_primary":false,"text":[{"text":"}","highlight_start":1,"highlight_end":2}],"label":"`a` dropped here while still borrowed","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"/checkout/src/test/ui/nll/user-annotations/normalization.rs","byte_start":241,"byte_end":257,"line_start":12,"line_end":12,"column_start":12,"column_end":28,"is_primary":false,"text":[{"text":"    let b: <() as Foo>::Out = &a; //~ ERROR","highlight_start":12,"highlight_end":28}],"label":"type annotation requires that `a` is borrowed for `'static`","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"error[E0597]: `a` does not live long enough\n  --> /checkout/src/test/ui/nll/user-annotations/normalization.rs:12:31\n   |\nLL |     let b: <() as Foo>::Out = &a; //~ ERROR\n   |            ----------------   ^^ borrowed value does not live long enough\n   |            |\n   |            type annotation requires that `a` is borrowed for `'static`\nLL | }\n   | - `a` dropped here while still borrowed\n\n"}
[00:47:05] {"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error\n\n"}
[00:47:05] {"message":"For more information about this error, try `rustc --explain E0597`.","code":null,"level":"","spans":[],"children":[],"rendered":"For more information about this error, try `rustc --explain E0597`.\n"}
[00:47:05] ------------------------------------------
[00:47:05] 
[00:47:05] thread '[ui] ui/nll/user-annotations/normalization.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:3284:9
[00:47:05] 
---
[00:47:05] test result: FAILED. 4631 passed; 3 failed; 24 ignored; 0 measured; 0 filtered out
[00:47:05] 
[00:47:05] 
[00:47:05] 
[00:47:05] 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/i586-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-i586-unknown-linux-gnu" "--mode" "ui" "--target" "i586-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/checkout/obj/build/x86_64-unknown-linux-gnu/llvm/build/bin/FileCheck" "--linker" "cc" "--host-rustcflags" "-Crpath -O -Zunstable-options " "--target-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/i586-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--llvm-version" "8.0.0svn\n" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
[00:47:05] 
[00:47:05] 
[00:47:05] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test --target i586-unknown-linux-gnu,i686-unknown-linux-musl
[00:47:05] Build completed unsuccessfully in 0:43:53
---
travis_time:end:00264960:start=1540047072912473454,finish=1540047072919205154,duration=6731700
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:180ad742
$ 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:0456ac05
travis_time:start:0456ac05
$ 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:0e7f430c
$ 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)

Adds UseAsConst and UseAsStatic to replace Return in consts/statics.
Don't report the arguments to an overloaded operator as CallArguments.
Also don't report "escaping data" in these items.
@matthewjasper
Copy link
Contributor Author

@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented Oct 20, 2018

📌 Commit 5d1896b2b165966aee793f3c7c2f769cc08fb82f 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-review Status: Awaiting review from the assignee but also interested parties. labels Oct 20, 2018
@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:45:42] .................................................................................................... 1100/4659
[00:45:45] .................................................................................................... 1200/4659
[00:45:47] .................................................................................................... 1300/4659
[00:45:49] .................................................................................................... 1400/4659
[00:45:52] ......................................................................i.............F............... 1500/4659
[00:45:58] .................................................................................................... 1700/4659
[00:46:02] .................................................................................................... 1800/4659
[00:46:05] ...........................................................................i........................ 1900/4659
[00:46:09] .................................................................................................... 2000/4659

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 Oct 21, 2018

⌛ Testing commit 5d1896b2b165966aee793f3c7c2f769cc08fb82f with merge 6f8d54c93da893ef598344137cb3fc950997a35b...

@bors
Copy link
Contributor

bors commented Oct 21, 2018

💔 Test failed - status-appveyor

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 21, 2018
@rust-highfive
Copy link
Collaborator

The job dist-i586-gnu-i586-i686-musl 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:50:16] normalized stderr:
[00:50:16] error[E0621]: explicit lifetime required in the type of `x`
[00:50:16]   --> $DIR/generator-region-requirements.rs:15:51
[00:50:16]    |
[00:50:16] LL | fn dangle(x: &mut i32) -> &'static mut i32 {
[00:50:16]    |              -------- help: add explicit lifetime `'static` to the type of `x`: `&'static mut i32`
[00:50:16] ...
[00:50:16] LL |             GeneratorState::Complete(c) => return c,
[00:50:16]    |                                                   ^ lifetime `'static` required
[00:50:16] error: aborting due to previous error
[00:50:16] 
[00:50:16] For more information about this error, try `rustc --explain E0621`.
[00:50:16] 
[00:50:16] 
[00:50:16] 
[00:50:16] 
[00:50:16] The actual stderr differed from the expected stderr.
[00:50:16] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/generator/generator-region-requirements.nll/generator-region-requirements.nll.stderr
[00:50:16] To update references, rerun the tests and pass the `--bless` flag
[00:50:16] To only update this specific test, also pass `--test-args generator/generator-region-requirements.rs`
[00:50:16] 
[00:50:16] error in revision `nll`: 1 errors occurred comparing output.
[00:50:16] status: exit code: 1
[00:50:16] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/generator/generator-region-requirements.rs" "--target=i586-unknown-linux-gnu" "--cfg" "nll" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/generator/generator-region-requirements.nll/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/i586-unknown-linux-gnu/native/rust-test-helpers" "-Clinker=cc" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/generator/generator-region-requirements.nll/auxiliary" "-A" "unused"
[00:50:16] ------------------------------------------
[00:50:16] 
[00:50:16] ------------------------------------------
[00:50:16] stderr:
[00:50:16] stderr:
[00:50:16] ------------------------------------------
[00:50:16] {"message":"explicit lifetime required in the type of `x`","code":{"code":"E0621","explanation":"\nThis error code indicates a mismatch between the lifetimes appearing in the\nfunction signature (i.e., the parameter types and the return type) and the\ndata-flow found in the function body.\n\nErroneous code example:\n\n```compile_fail,E0621\nfn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 { // error: explicit lifetime\n                                             //        required in the type of\n                                             //        `y`\n    if x > y { x } else { y }\n}\n```\n\nIn the code above, the function is returning data borrowed from either `x` or\n`y`, but the `'a` annotation indicates that it is returning data only from `x`.\nTo fix the error, the signature and the body must be made to match. Typically,\nthis is done by updating the function signature. So, in this case, we change\nthe type of `y` to `&'a i32`, like so:\n\n```\nfn foo<'a>(x: &'a i32, y: &'a i32) -> &'a i32 {\n    if x > y { x } else { y }\n}\n```\n\nNow the signature indicates that the function data borrowed from either `x` or\n`y`. Alternatively, you could change the body to not return data from `y`:\n\n```\nfn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 {\n    x\n}\n```\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/generator/generator-region-requirements.rs","byte_start":364,"byte_end":365,"line_start":15,"line_end":15,"column_start":51,"column_end":52,"is_primary":true,"text":[{"text":"            GeneratorState::Complete(c) => return c,","highlight_start":51,"highlight_end":52}],"label":"lifetime `'static` required","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"add explicit lifetime `'static` to the type of `x`","code":null,"level":"help","spans":[{"file_name":"/checkout/src/test/ui/generator/generator-region-requirements.rs","byte_start":180,"byte_end":188,"line_start":8,"line_end":8,"column_start":14,"column_end":22,"is_primary":true,"text":[{"text":"fn dangle(x: &mut i32) -> &'static mut i32 {","highlight_start":14,"highlight_end":22}],"label":null,"suggested_replacement":"&'static mut i32","suggestion_applicability":"Unspecified","expansion":null}],"children":[],"rendered":null}],"rendered":"error[E0621]: explicit lifetime required in the type of `x`\n  --> /checkout/src/test/ui/generator/generator-region-requirements.rs:15:51\n   |\nLL | fn dangle(x: &mut i32) -> &'static mut i32 {\n   |              -------- help: add explicit lifetime `'static` to the type of `x`: `&'static mut i32`\n...\nLL |             GeneratorState::Complete(c) => return c,\n   |                                                   ^ lifetime `'static` required\n\n"}
[00:50:16] {"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error\n\n"}
[00:50:16] {"message":"For more information about this error, try `rustc --explain E0621`.","code":null,"level":"","spans":[],"children":[],"rendered":"For more information about this error, try `rustc --explain E0621`.\n"}
[00:50:16] ------------------------------------------
[00:50:16] 
[00:50:16] thread '[ui] ui/generator/generator-region-requirements.rs#nll' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:3284:9
[00:50:16] note: Run with `RUST_BACKTRACE=1` for a backtrace.
---
[00:50:16] 
[00:50:16] thread 'main' panicked at 'Some tests failed', tools/compiletest/src/main.rs:503:22
[00:50:16] 
[00:50:16] 
[00:50:16] 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/i586-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-i586-unknown-linux-gnu" "--mode" "ui" "--target" "i586-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/checkout/obj/build/x86_64-unknown-linux-gnu/llvm/build/bin/FileCheck" "--linker" "cc" "--host-rustcflags" "-Crpath -O -Zunstable-options " "--target-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/i586-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--llvm-version" "8.0.0svn\n" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
[00:50:16] 
[00:50:16] 
[00:50:16] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test --target i586-unknown-linux-gnu,i686-unknown-linux-musl
[00:50:16] Build completed unsuccessfully in 0:47:00
---
travis_time:end:13f77ce1:start=1540087140161480370,finish=1540087140170134568,duration=8654198
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:23423140
$ 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:04911d65
travis_time:start:04911d65
$ 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:073bbd94
$ 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)

@kennytm kennytm 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 Oct 21, 2018
This gives at least some explanation for why a borrow is expected to
last for a certain free region. Also:

* Reports E0373: "closure may outlive the current function" with NLL.
* Special cases the case of returning a reference to (or value
  referencing) a local variable or temporary (E0515).
* Special case assigning a reference to a local variable in a closure
  to a captured variable.
@matthewjasper
Copy link
Contributor Author

@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented Oct 21, 2018

📌 Commit 2a3969a 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 Oct 21, 2018
@bors
Copy link
Contributor

bors commented Oct 21, 2018

⌛ Testing commit 2a3969a with merge 31b97f7...

bors added a commit that referenced this pull request Oct 21, 2018
…nikomatsakis

[NLL] Use new region infer errors when explaining borrows

Use the new free region infer errors for explaining borrows

This gives at least some explanation for why a borrow is expected to
last for a certain free region. Also:

* Reports E0373: "closure may outlive the current function" with NLL.
* Special cases the case of returning a reference to (or value referencing) a local variable or temporary (E0515).
* Special case assigning a reference to a local variable in a closure to a captured variable. (E0521)

Closes #51026 - `regions-nested-fns-2.rs` isn't changed to that diagnostic, since that would not be the correct error here.
Closes #51169
cc #53882 - The error is (IMO) better now, but it could be better when we trace lifetimes in these error messages.

r? @nikomatsakis cc @pnkfelix
@bors
Copy link
Contributor

bors commented Oct 21, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing 31b97f7 to master...

@bors bors merged commit 2a3969a into rust-lang:master Oct 21, 2018
@matthewjasper matthewjasper deleted the explain-free-region-liveness branch October 21, 2018 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-NLL Area: Non Lexical Lifetimes (NLL) 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.

None yet

7 participants