Stream: t-compiler/wg-nll

Topic: pr-53088


Matthew Jasper (Aug 06 2018 at 20:37, on Zulip):

@nikomatsakis Changes are implemented now. Not sure how well it works for long type names

Matthew Jasper (Aug 06 2018 at 20:37, on Zulip):
error: unsatisfied lifetime constraints
  --> $DIR/issue-49824.rs:22:9
   |
LL |       || {
   |       --
   |       ||
   |       |return type of closure is [closure@$DIR/issue-49824.rs:22:9: 24:10 x:&'2 mut i32]
   |       lifetime `'1` represents this closure's body
LL | /         || {
LL | |             let _y = &mut x;
LL | |         }
   | |_________^ requires that `'1` must outlive `'2`
   |
   = note: closure implements `FnMut`, so references to captured variables can't escape the closure

error: aborting due to previous error
nikomatsakis (Aug 06 2018 at 20:38, on Zulip):

well

nikomatsakis (Aug 06 2018 at 20:38, on Zulip):

I think the problem there is probably that we should try to identify that case

nikomatsakis (Aug 06 2018 at 20:38, on Zulip):

if nothing else, this version tells me what the problem is quite precisely though :)

nikomatsakis (Aug 06 2018 at 20:38, on Zulip):

in particular, the closure holds on to a reference to x

nikomatsakis (Aug 06 2018 at 20:39, on Zulip):

(also, I'm not 100% convinced this test should fail to compile)

nikomatsakis (Aug 06 2018 at 20:39, on Zulip):

that .. kind of seems like a bug

nikomatsakis (Aug 06 2018 at 20:39, on Zulip):

but not related to your PR, obviously

nikomatsakis (Aug 06 2018 at 20:39, on Zulip):

anyway, TL;DR I still consider that an improvement on what was there before, because it gives you enough information to solve the problem, if you know how to interpret it; but it's not a final goal in that we should break it down for the user more

nikomatsakis (Aug 06 2018 at 20:40, on Zulip):

(we should probably also investigate why issue-49824.rs is failing to compile, which seems like an NLL-complete bug)

nikomatsakis (Aug 06 2018 at 20:40, on Zulip):

I feel like we maybe had a bug on this?

Matthew Jasper (Aug 06 2018 at 20:41, on Zulip):

I think there is a recent one opened by Felix

Matthew Jasper (Aug 06 2018 at 20:43, on Zulip):

#53040

nikomatsakis (Aug 06 2018 at 20:44, on Zulip):

ah yes and I see I wrote this which seems relevant too :)

nikomatsakis (Aug 06 2018 at 20:44, on Zulip):

https://github.com/rust-lang/rust/issues/49824#issuecomment-384391152

nikomatsakis (Aug 06 2018 at 20:45, on Zulip):

ok so

nikomatsakis (Aug 06 2018 at 20:46, on Zulip):

I would say we should try to identify this case and give a nice error

nikomatsakis (Aug 06 2018 at 20:46, on Zulip):

it seems sort of related to https://github.com/rust-lang/rust/issues/51026 as well

nikomatsakis (Aug 06 2018 at 20:46, on Zulip):

though it may not be precisely the same scenario

nikomatsakis (Aug 06 2018 at 20:47, on Zulip):

specifically I think the scenario would be:

nikomatsakis (Aug 06 2018 at 20:47, on Zulip):
nikomatsakis (Aug 06 2018 at 20:48, on Zulip):
nikomatsakis (Aug 06 2018 at 20:48, on Zulip):

then we want to say something like "this closure captures x by reference but then escapes its creating stack frame"

nikomatsakis (Aug 06 2018 at 20:48, on Zulip):

and suggest using "move"

nikomatsakis (Aug 06 2018 at 20:49, on Zulip):

actually the message from borrowck-escaping-closure-error-1 is probably exactly what we want

nikomatsakis (Aug 06 2018 at 20:49, on Zulip):

so maybe this really is the same case

nikomatsakis (Aug 06 2018 at 20:49, on Zulip):
error[E0373]: closure may outlive the current function, but it borrows `books`, which is owned by the current function
  --> $DIR/borrowck-escaping-closure-error-1.rs:23:11
   |
LL |     spawn(|| books.push(4));
   |           ^^ ----- `books` is borrowed here
   |           |
   |           may outlive borrowed value `books`
help: to force the closure to take ownership of `books` (and any other referenced variables), use the `move` keyword
   |
LL |     spawn(move || books.push(4));
   |           ^^^^^^^
nikomatsakis (Aug 06 2018 at 20:49, on Zulip):

probably what we want is to to skip the "...and the other region is the closure body" check

nikomatsakis (Aug 06 2018 at 20:49, on Zulip):

and just print something like whenever the other region is "some free region"

nikomatsakis (Aug 06 2018 at 20:50, on Zulip):

@Matthew Jasper does that make sense?

Matthew Jasper (Aug 06 2018 at 20:57, on Zulip):

Yes. You might want to leave a note for this somewhere so it doesn't get lost.

nikomatsakis (Aug 06 2018 at 20:58, on Zulip):

I left it in the issue https://github.com/rust-lang/rust/issues/51026, which is assigned to you actually

nikomatsakis (Aug 06 2018 at 21:19, on Zulip):

@Matthew Jasper so looking at https://github.com/rust-lang/rust/issues/51354, I think that is also a case where this error message would apply

Last update: Nov 22 2019 at 01:00UTC