-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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: unexpected "free region `` does not outlive" error #49824
Comments
Context: Closures desugar to a struct. Sometimes this struct will have requirements that are placed on its creator. It's the closure's job to infer those requirements. The creator then tries to check it they are met. Example: fn foo(mut x: Vec<&'a u32>, y: &'b u32) {
let c = || {
x.push(y);
};
c();
} The closure here desugars to something like let c = ClosureStruct { x: &mut x, y: &y };
c(); where struct ClosureStruct<'x, 'y, 'a, 'b> {
x: &'x mut Vec<&'a u32>,
y: &'y &'b u32
}
impl FnOnce for ClosureStruct { .. } In the course of type-checking that impl, we will check that This is what the Lines 2032 to 2094 in 6c53749
There are lots of tests in
The closure in that function, for example, apparently defines no external requirements: rust/src/test/ui/nll/closure-requirements/return-wrong-bound-region.stderr Lines 13 to 22 in 6c53749
Anyway, the way to start here is to (a) create a minimized test and (b) dump out the region requirements and then perhaps (c) start trying to see where they are coming from. |
My reduced test case is ...
If I borrow x immutable the issue does not trigger. Dumping region requirements I get ...
|
@spastorino by the way, in case you are not already aware of this: If you pass the
(That is just general info that can sometimes be useful when staring at compiler output, not necessarily something that will solve this particular problem...) |
In particular, by adding
|
Hmm, this might be a case where the check is actually working as intended, though the error message is not great. In particular, the outer closure is returning the inner closure -- the way the inference works, the inner closure is inferred to a Either of these two variants works. If you use #![feature(rustc_attrs)]
#![feature(nll)]
#[rustc_regions]
fn main() {
let mut x = 0;
|| {
move || {
let _y = &mut x;
}
};
} Or, if we do not return the closure: #![feature(rustc_attrs)]
#![feature(nll)]
#[rustc_regions]
fn main() {
let mut x = 0;
|| {
|| {
let _y = &mut x;
};
};
} I'm not sure which is more in the spirit of the original test. Probably the latter. |
I'm not sure what's left to do here. I guess maybe alter the test case? It seems like NLL is generating the correct error. |
Marking as a Preview 2 blocker just because it's so ridiculously simple. Let's get this done. I'll assign to myself. |
I am experiencing this while trying to work with tokio and futures. Let me know if there is anything I can do as a workaround or if you would like to see me elaborate on the rest of the code:
let server = listener
.incoming()
.map_err(|e| eprintln!("accept failed = {:?}", e))
.for_each(move |sock| {
let (reader, writer) = sock.split();
let req: Vec<u8> = Vec::new();
let task = io::read_exact(reader, req)
.and_then(|(_res, rq)| {
...
io::write_all(writer, RESPONSE_PREAMBLE)
})
.map(|(w, _e)| {
...
let jpg: Box<[u8]> = wr.into_inner().unwrap().into_boxed_slice();
io::write_all(w, jpg)
})
.then(|_| Ok(()));
tokio::executor::spawn(task)
}); |
@canselcik Are you still seeing this error message? I would expect it to have changed somewhat, for one thing. From what I can tell -- at least in the original example -- this indicated a legitimate error in the test. |
The current error message from @spastorino's test case is:
which needs work but is a lot better than the original =) |
this has gotten good enough that we think we just need to make sure it has a test somewhere. |
Submitted #52793 with the test that is remaining for this issue. |
Add test for NLL: unexpected "free region `` does not outlive" error Fixes rust-lang#49824. r? @pnkfelix @nikomatsakis
In the test
borrowck/borrowck-describe-lvalue.rs
, when using NLL by default for MIR borrowck, I started getting the odd error "Free region does not outlive" error below:Seems like a bug.
The text was updated successfully, but these errors were encountered: