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

Improve "Doesn't live long enough" error #37554

Merged
merged 1 commit into from
Nov 12, 2016
Merged

Conversation

mikhail-m1
Copy link
Contributor

case with temporary variable

issue #36279 part of #35233

r? @jonathandturner

@sophiajt
Copy link
Contributor

sophiajt commented Nov 5, 2016

Hmm, this doesn't look quite right. It looks like we're getting rid of the temporary value message altogether. Instead, I think we want to use the same style of fixed we used before.

For example, instead of this:

error: borrowed value does not live long enough
  --> <anon>:11:17
   |
11 |     for line in std::io::stdin().lock().lines().map(|l| l.unwrap()) {
   |                 ^^^^^^^^^^^^^^^^ temporary value created here
...
18 |     }
   |     - temporary value dropped before borrower
   |
   = note: values in a scope are dropped in the opposite order they are created

Have this:

error: borrowed value does not live long enough
  --> <anon>:11:17
   |
11 |     for line in std::io::stdin().lock().lines().map(|l| l.unwrap()) {
   |                 ---------------- temporary value created here
...
18 |     }
   |     ^ temporary value dropped before borrower
   |
   = note: values in a scope are dropped in the opposite order they are created

@sophiajt
Copy link
Contributor

sophiajt commented Nov 5, 2016

Though I noticed that sometimes we don't put the error on the last one. Like this example:

error: `r` does not live long enough
  --> <anon>:21:9
   |
18 |     r.listen(Box::new(|| {
   |                       -- capture occurs here
...
21 |         r.something();
   |         ^ does not live long enough
22 |     }));
23 | }
   | - borrowed value dropped before borrower

Still, I think with the temporary value, the fix I'm showing reads okay

@mikhail-m1
Copy link
Contributor Author

@jonathandturner I did not noticed the loss of 'temporary' in error. It's easy to fix. But I reread #36279, is it about split temporary and local variables? And was it already completed?
I could rework case with closure, just give me required output.

@sophiajt
Copy link
Contributor

sophiajt commented Nov 8, 2016

@mikhail-m1 - I think that's an older error before we made the message wording better for temporaries.

I think the only step left for temporaries is to switch which is primary and which is secondary.

case with temporary variable
@alexcrichton
Copy link
Member

@jonathandturner does the most recent iteration look good to you?

@sophiajt
Copy link
Contributor

Looks good!

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Nov 12, 2016

📌 Commit cfdf763 has been approved by jonathandturner

@bors
Copy link
Contributor

bors commented Nov 12, 2016

⌛ Testing commit cfdf763 with merge acce384...

bors added a commit that referenced this pull request Nov 12, 2016
Improve "Doesn't live long enough" error

case with temporary variable

issue #36279 part of #35233

r? @jonathandturner
@bors bors merged commit cfdf763 into rust-lang:master Nov 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants