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] better error message when returning refs to upvars #54802

Merged
merged 2 commits into from
Oct 10, 2018

Conversation

davidtwco
Copy link
Member

Fixes #53040.

r? @nikomatsakis

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 3, 2018
Copy link
Member Author

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

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

This PR achieves (approximately) the intended error from the issue for that test case but I'm not convinced it improves all of the other tests that it is affecting.

src/test/ui/issues/issue-49824.nll.stderr Show resolved Hide resolved
src/test/ui/nll/issue-53040.stderr Outdated Show resolved Hide resolved
| ||
| |return type of closure is [closure@$DIR/issue-40510-3.rs:18:9: 20:10 x:&'2 mut std::vec::Vec<()>]
| lifetime `'1` represents this closure's body
| - inferred to be a `FnMut` closure
LL | / || {
LL | | x.push(())
LL | | }
Copy link
Contributor

Choose a reason for hiding this comment

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

Here I suspect this will be a bit confusing because two closures are in play. We actually can probably tell that — if the statement is an assignment with a closure rvalue, then there is an "inner" and an "outer" closure, and maybe we can adjust the message to say something like:

creates a closure that captures x by reference; this inner closure is then returned from the outer closure, allowing x to escape the closure body

that wording doesn't feel 💯, though, and I don't know if it's easy to find the name x (we don't seem to be using it in other messages)

Maybe something like this?

creates a closure that contains a reference to a captured variable; this inner closure then escapes the closure body

Copy link
Member Author

Choose a reason for hiding this comment

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

Pushed a change with this.

Copy link
Member

Choose a reason for hiding this comment

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

Note that @nikomatsakis was suggesting in particular the phrases "inner closure" and "outer closure", in that there are two closures in play and he wanted some way that the diagnostic would distinguish between the two when discussing them.

I don't see any use of the word "inner" in the diff, so I don't think you quite encoded exactly what @nikomatsakis was asking for.

(But I also do think that what you've done is a vast improvement over what we had before...)

@davidtwco davidtwco changed the title WIP: [nll] better error message when returning refs to upvars [nll] better error message when returning refs to upvars Oct 5, 2018
@memoryruins memoryruins added the A-NLL Area: Non-lexical lifetimes (NLL) label Oct 6, 2018
/// Adds a suggestion to errors where a `impl Trait` is returned.
///
/// ```text
/// help: to allow this impl Trait to capture borrowed data with lifetime `'1`, add `'_` as
Copy link
Member

Choose a reason for hiding this comment

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

note to self: are we literally saying '_ when we mean it as a placeholder for a concrete lifetime like 'a? Or is it just supposed to be a replacement for the default of 'static ?

Copy link
Member

Choose a reason for hiding this comment

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

note to self and to @davidtwco : Wait, so now I don't get a "Submit review" prompt? what the hey...?

Copy link
Member Author

@davidtwco davidtwco Oct 8, 2018

Choose a reason for hiding this comment

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

This comment annotates a function that was added in a previous PR - I just added it in this PR because I noticed it was missing.

IIRC from that PR, we suggest a named lifetime if we have one and '_ otherwise.

@pnkfelix
Copy link
Member

pnkfelix commented Oct 8, 2018

@bors r+

@bors
Copy link
Contributor

bors commented Oct 8, 2018

📌 Commit b5ba1a0acb74c235cbe06a70ef6c5c1c2e2c0dda has been approved by pnkfelix

@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 8, 2018
@bors

This comment has been minimized.

@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 9, 2018
This commit improves the errors for `FnMut` closures where a reference
to a captured variable is escaping.
Now when a `FnMut` closure is returning a closure that contains a
reference to a captured variable, we provide an error that makes it more
clear what is happening.
@davidtwco
Copy link
Member Author

@bors r=pnkfelix

@bors
Copy link
Contributor

bors commented Oct 9, 2018

📌 Commit 98633b4 has been approved by pnkfelix

@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 9, 2018
@bors
Copy link
Contributor

bors commented Oct 10, 2018

⌛ Testing commit 98633b4 with merge 9930347c09c1daa97593944478864af1ebca033d...

@bors
Copy link
Contributor

bors commented Oct 10, 2018

💔 Test failed - status-travis

@rust-highfive
Copy link
Collaborator

The job dist-x86_64-linux-alt 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:15019c02:start=1539153340572864547,finish=1539153340581263607,duration=8399060
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:004b4524
$ 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:3210cfea
travis_time:start:3210cfea
$ 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:11d4f9d4
$ 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 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 10, 2018
@davidtwco
Copy link
Member Author

@bors retry

@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 10, 2018
@bors
Copy link
Contributor

bors commented Oct 10, 2018

⌛ Testing commit 98633b4 with merge e1041c6...

bors added a commit that referenced this pull request Oct 10, 2018
[nll] better error message when returning refs to upvars

Fixes #53040.

r? @nikomatsakis
@bors
Copy link
Contributor

bors commented Oct 10, 2018

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

@bors bors merged commit 98633b4 into rust-lang:master Oct 10, 2018
@davidtwco davidtwco deleted the issue-53040 branch October 10, 2018 17:32
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.

6 participants