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] borrows that must be valid for a free lifetime should explain why #54229

Merged
merged 12 commits into from Sep 23, 2018

Conversation

Projects
None yet
8 participants
@davidtwco
Member

davidtwco commented Sep 14, 2018

Fixes #52534.

r? @nikomatsakis

@memoryruins memoryruins added the A-NLL label Sep 14, 2018

@rust-highfive

This comment was marked as outdated.

Show comment
Hide comment
@rust-highfive

rust-highfive Sep 14, 2018

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:04:39] travis_fold:start:tidy
travis_time:start:tidy
tidy check
[00:04:40] tidy error: /checkout/src/librustc_mir/borrow_check/error_reporting.rs:541: line longer than 100 chars
[00:04:40] tidy error: /checkout/src/librustc_mir/borrow_check/mod.rs:591: line longer than 100 chars
[00:04:40] tidy error: /checkout/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs:423: line longer than 100 chars
[00:04:40] tidy error: /checkout/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs:424: line longer than 100 chars
[00:04:41] some tidy checks failed
[00:04:41] 
[00:04:41] 
[00:04:41] 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:41] 
[00:04:41] 
[00:04:41] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:04:41] Build completed unsuccessfully in 0:00:48
[00:04:41] Build completed unsuccessfully in 0:00:48
[00:04:41] make: *** [tidy] Error 1
[00:04:41] Makefile:79: recipe for target 'tidy' failed

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:0bfae0cc
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
---
travis_time:end:06ec06ce:start=1536933379470402990,finish=1536933379474680766,duration=4277776
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:130c9838
$ 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 -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:02dcef0e
travis_time:start:02dcef0e
$ 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:03c6f89d
$ 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)

Collaborator

rust-highfive commented Sep 14, 2018

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:04:39] travis_fold:start:tidy
travis_time:start:tidy
tidy check
[00:04:40] tidy error: /checkout/src/librustc_mir/borrow_check/error_reporting.rs:541: line longer than 100 chars
[00:04:40] tidy error: /checkout/src/librustc_mir/borrow_check/mod.rs:591: line longer than 100 chars
[00:04:40] tidy error: /checkout/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs:423: line longer than 100 chars
[00:04:40] tidy error: /checkout/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs:424: line longer than 100 chars
[00:04:41] some tidy checks failed
[00:04:41] 
[00:04:41] 
[00:04:41] 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:41] 
[00:04:41] 
[00:04:41] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:04:41] Build completed unsuccessfully in 0:00:48
[00:04:41] Build completed unsuccessfully in 0:00:48
[00:04:41] make: *** [tidy] Error 1
[00:04:41] Makefile:79: recipe for target 'tidy' failed

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:0bfae0cc
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
---
travis_time:end:06ec06ce:start=1536933379470402990,finish=1536933379474680766,duration=4277776
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:130c9838
$ 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 -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:02dcef0e
travis_time:start:02dcef0e
$ 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:03c6f89d
$ 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.

Show comment
Hide comment
@rust-highfive

rust-highfive Sep 14, 2018

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:13:20]    Compiling rustc_traits v0.0.0 (file:///checkout/src/librustc_traits)
[00:14:07] error: method is never used: `universal_regions_outlived_by`
[00:14:07]    --> librustc_mir/borrow_check/nll/region_infer/mod.rs:655:5
[00:14:07]     |
[00:14:07] 655 | /     pub fn universal_regions_outlived_by<'a>(
[00:14:07] 656 | |         &'a self,
[00:14:07] 657 | |         r: RegionVid
[00:14:07] 658 | |     ) -> impl Iterator<Item = RegionVid> + 'a {
[00:14:07] 659 | |         let borrow_scc = self.constraint_sccs.scc(r);
[00:14:07] 660 | |         self.scc_values.universal_regions_outlived_by(borrow_scc)
[00:14:07]     | |_____^
[00:14:07]     |
[00:14:07]     = note: `-D dead-code` implied by `-D warnings`
[00:14:07] 
[00:14:07] 
[00:14:07] error: aborting due to previous error
[00:14:07] 
[00:14:07] error: Could not compile `rustc_mir`.
[00:14:07] warning: build failed, waiting for other jobs to finish...
[00:14:51] error: build failed
[00:14:51] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" " jemalloc" "--manifest-path" "/checkout/src/rustc/Cargo.toml" "--message-format" "json"
[00:14:51] expected success, got: exit code: 101
[00:14:51] thread 'main' panicked at 'cargo must succeed', bootstrap/compile.rs:1155:9
[00:14:51] travis_fold:end:stage0-rustc

[00:14:51] travis_time:end:stage0-rustc:start=1536934182315591359,finish=1536934734686578937,duration=552370987578


[00:14:51] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap build
[00:14:51] Build completed unsuccessfully in 0:10:05
[00:14:51] Makefile:28: recipe for target 'all' failed
[00:14:51] make: *** [all] Error 1

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:0b3373a6
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)

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)

Collaborator

rust-highfive commented Sep 14, 2018

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:13:20]    Compiling rustc_traits v0.0.0 (file:///checkout/src/librustc_traits)
[00:14:07] error: method is never used: `universal_regions_outlived_by`
[00:14:07]    --> librustc_mir/borrow_check/nll/region_infer/mod.rs:655:5
[00:14:07]     |
[00:14:07] 655 | /     pub fn universal_regions_outlived_by<'a>(
[00:14:07] 656 | |         &'a self,
[00:14:07] 657 | |         r: RegionVid
[00:14:07] 658 | |     ) -> impl Iterator<Item = RegionVid> + 'a {
[00:14:07] 659 | |         let borrow_scc = self.constraint_sccs.scc(r);
[00:14:07] 660 | |         self.scc_values.universal_regions_outlived_by(borrow_scc)
[00:14:07]     | |_____^
[00:14:07]     |
[00:14:07]     = note: `-D dead-code` implied by `-D warnings`
[00:14:07] 
[00:14:07] 
[00:14:07] error: aborting due to previous error
[00:14:07] 
[00:14:07] error: Could not compile `rustc_mir`.
[00:14:07] warning: build failed, waiting for other jobs to finish...
[00:14:51] error: build failed
[00:14:51] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" " jemalloc" "--manifest-path" "/checkout/src/rustc/Cargo.toml" "--message-format" "json"
[00:14:51] expected success, got: exit code: 101
[00:14:51] thread 'main' panicked at 'cargo must succeed', bootstrap/compile.rs:1155:9
[00:14:51] travis_fold:end:stage0-rustc

[00:14:51] travis_time:end:stage0-rustc:start=1536934182315591359,finish=1536934734686578937,duration=552370987578


[00:14:51] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap build
[00:14:51] Build completed unsuccessfully in 0:10:05
[00:14:51] Makefile:28: recipe for target 'all' failed
[00:14:51] make: *** [all] Error 1

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:0b3373a6
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)

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)

@nikomatsakis

This comment has been minimized.

Show comment
Hide comment
@nikomatsakis
Contributor

nikomatsakis commented Sep 14, 2018

@bors

This comment was marked as outdated.

Show comment
Hide comment
@bors

bors Sep 14, 2018

Contributor

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

Contributor

bors commented Sep 14, 2018

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

@davidtwco

This comment was marked as outdated.

Show comment
Hide comment
@davidtwco

davidtwco Sep 14, 2018

Member

Rebased.

Member

davidtwco commented Sep 14, 2018

Rebased.

@bors

This comment was marked as outdated.

Show comment
Hide comment
@bors

bors Sep 16, 2018

Contributor

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

Contributor

bors commented Sep 16, 2018

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

@davidtwco

This comment was marked as outdated.

Show comment
Hide comment
@davidtwco

davidtwco Sep 16, 2018

Member

Rebased.

Member

davidtwco commented Sep 16, 2018

Rebased.

@bors

This comment was marked as outdated.

Show comment
Hide comment
@bors

bors Sep 18, 2018

Contributor

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

Contributor

bors commented Sep 18, 2018

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

@davidtwco

This comment has been minimized.

Show comment
Hide comment
@davidtwco

davidtwco Sep 18, 2018

Member

Rebased.

Member

davidtwco commented Sep 18, 2018

Rebased.

@davidtwco davidtwco changed the title from WIP: [nll] borrows that must be valid for a free lifetime should explain why to [nll] borrows that must be valid for a free lifetime should explain why Sep 18, 2018

@nikomatsakis

Seems good overall

Show resolved Hide resolved src/librustc/util/ppaux.rs Outdated
Show outdated Hide outdated src/test/ui/issues/issue-30438-c.nll.stderr Outdated
Show resolved Hide resolved src/librustc_mir/borrow_check/error_reporting.rs
Show resolved Hide resolved src/librustc_mir/borrow_check/error_reporting.rs Outdated
Show resolved Hide resolved src/librustc_mir/borrow_check/error_reporting.rs Outdated
Show outdated Hide outdated src/librustc_mir/borrow_check/error_reporting.rs Outdated
Show outdated Hide outdated src/test/ui/nll/borrowed-universal-error-2.stderr Outdated
Show resolved Hide resolved src/librustc_mir/borrow_check/error_reporting.rs Outdated
pub fn has_name(&self) -> bool {
match *self {
RegionKind::ReEarlyBound(ebr) => ebr.has_name(),
RegionKind::ReLateBound(_, br) => br.is_named(),

This comment has been minimized.

@estebank

estebank Sep 19, 2018

Contributor

Aside: The difference above is... unfortunate.

@estebank

estebank Sep 19, 2018

Contributor

Aside: The difference above is... unfortunate.

This comment has been minimized.

@davidtwco

davidtwco Sep 19, 2018

Member

I'm not sure I understand what you mean?

@davidtwco

davidtwco Sep 19, 2018

Member

I'm not sure I understand what you mean?

This comment has been minimized.

@estebank

estebank Sep 19, 2018

Contributor

has_name vs is_named

@estebank

estebank Sep 19, 2018

Contributor

has_name vs is_named

Show resolved Hide resolved src/test/ui/nll/issue-52534.stderr Outdated
Show resolved Hide resolved src/test/ui/nll/issue-52534.stderr Outdated
@pnkfelix

This comment has been minimized.

Show comment
Hide comment
@pnkfelix

pnkfelix Sep 20, 2018

Member

I looked over the PR. I think all of @nikomatsakis notes have been addressed (as well as @estebank 's), and it looks good to me too.

Member

pnkfelix commented Sep 20, 2018

I looked over the PR. I think all of @nikomatsakis notes have been addressed (as well as @estebank 's), and it looks good to me too.

@pnkfelix

This comment was marked as outdated.

Show comment
Hide comment
@pnkfelix
Member

pnkfelix commented Sep 20, 2018

@bors r+

@bors

This comment was marked as outdated.

Show comment
Hide comment
@bors

bors Sep 20, 2018

Contributor

📌 Commit 874e379 has been approved by pnkfelix

Contributor

bors commented Sep 20, 2018

📌 Commit 874e379 has been approved by pnkfelix

@bors

This comment was marked as outdated.

Show comment
Hide comment
@bors

bors Sep 22, 2018

Contributor

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

Contributor

bors commented Sep 22, 2018

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

@davidtwco

This comment was marked as outdated.

Show comment
Hide comment
@davidtwco

davidtwco Sep 23, 2018

Member

@bors r=pnkfelix

Member

davidtwco commented Sep 23, 2018

@bors r=pnkfelix

@bors

This comment was marked as outdated.

Show comment
Hide comment
@bors

bors Sep 23, 2018

Contributor

📌 Commit 125607f has been approved by pnkfelix

Contributor

bors commented Sep 23, 2018

📌 Commit 125607f has been approved by pnkfelix

davidtwco added some commits Sep 9, 2018

Refactor explain_borrow to return explanation.
Previously, explain_borrow would emit an error with the explanation of
the a borrow. Now, it returns a enum with what the explanation for the
borrow is and any relevant spans or information such that the calling
code can choose to emit the same note/suggestion as before by calling
the emit method on the new enum.
Refactor region naming for control of diagnostics.
Previously, region naming would always highlight the source of the
region name it found. Now, region naming returns the name as part
of a larger structure that encodes the source of the region naming
such that a region name can be optionally added to the diagnostic.
Improve non-closure, reference in-and-out errors.
For cases where there are references in the parameters and in the the
outputs that do not match, and where no closures are involved, this
commit introduces an improved error that mentions (or synthesizes)
a name for the regions involved to better illustrate why the borrow
does not live long enough.
Improve borrow errors for closures.
Adds improved messages for closures where returned type
does not match the inferred return lifetime of the closure.
Improve 'dropped here' note.
Start mentioning function name that the variable is valid within in
notes to provide context.
Added multiple parameter closure test.
New test has multiple parameters in a closure with longer names in order
to clarify the issues relating to odd spans.
Fixed off-by-one span.
Fixes the off-by-one span issue where closure argument spans were
pointing to the token after the argument.
Added note about dangling references.
This error can only occur within a function when a borrow of data owned
within the function is returned; and when there are arguments that could
have been returned instead. Therefore, it is always applicable to add a
specific note that links to the relevant rust documentation about
dangling references.
Renamed ppaux highlight region hook.
Changed `highlight_region_with_region` function(s) to
`highlight_region_with_bound_region` to be more specific and less
ambigious.
Correctly handle named lifetimes.
Enhances annotation logic to properly consider named lifetimes where
lifetime elision rules that were previously implemented would not apply.

Further, adds new help and note messages to diagnostics and highlights
only lifetime when dealing with named lifetimes.
Only annotate if borrow is returned.
Error now correctly checks whether the borrow that does not live
long enough is being returned before annotating the error with the
arguments and return type from the signature - as this would not be
relevant if the borrow was not being returned.
@davidtwco

This comment has been minimized.

Show comment
Hide comment
@davidtwco

davidtwco Sep 23, 2018

Member

@bors r=pnkfelix

Member

davidtwco commented Sep 23, 2018

@bors r=pnkfelix

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Sep 23, 2018

Contributor

📌 Commit b342f00 has been approved by pnkfelix

Contributor

bors commented Sep 23, 2018

📌 Commit b342f00 has been approved by pnkfelix

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Sep 23, 2018

Contributor

⌛️ Testing commit b342f00 with merge f49f6e7...

Contributor

bors commented Sep 23, 2018

⌛️ Testing commit b342f00 with merge f49f6e7...

bors added a commit that referenced this pull request Sep 23, 2018

Auto merge of #54229 - davidtwco:issue-52534, r=pnkfelix
[nll] borrows that must be valid for a free lifetime should explain why

Fixes #52534.

r? @nikomatsakis
@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Sep 23, 2018

Contributor

☀️ Test successful - status-appveyor, status-travis
Approved by: pnkfelix
Pushing f49f6e7 to master...

Contributor

bors commented Sep 23, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: pnkfelix
Pushing f49f6e7 to master...

@bors bors merged commit b342f00 into rust-lang:master Sep 23, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details

pnkfelix added a commit to pnkfelix/rust that referenced this pull request Sep 24, 2018

match reason {
Liveness { local, location, in_loop } => {
match find_use::find(mir, regioncx, tcx, region_sub, context.loc) {

This comment has been minimized.

@pnkfelix

pnkfelix Sep 28, 2018

Member

pnkfelix's brain, five days after code lands: "Hey, this isn't indented right... hmm and maybe I might have chosen a name besides emit for that method over there... who reviewed this, anyway !?!?! Oh. Oh. It was me. I reviewed it..." 😆

@pnkfelix

pnkfelix Sep 28, 2018

Member

pnkfelix's brain, five days after code lands: "Hey, this isn't indented right... hmm and maybe I might have chosen a name besides emit for that method over there... who reviewed this, anyway !?!?! Oh. Oh. It was me. I reviewed it..." 😆

@davidtwco davidtwco deleted the davidtwco:issue-52534 branch Sep 28, 2018

topecongiro added a commit to topecongiro/rustfmt that referenced this pull request Oct 6, 2018

@topecongiro topecongiro referenced this pull request Oct 6, 2018

Merged

Cargo update #3079

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment