fix for issues #51351 and #52113#52620
Conversation
src/test/ui/nll/issue-51351.rs
Outdated
There was a problem hiding this comment.
Is this referring to the right issue?
There was a problem hiding this comment.
sorry, just copy & paste...
There was a problem hiding this comment.
I think it'd be nice to put this into a fn, along with a somewhat more extensive comment that (at minimum) cites the issue number.
There was a problem hiding this comment.
I think a comment like this would be good:
Finds late-bound regions that do not appear in the parameter listing and adds them to the indices vector. Typically, we identify late-bound regions as we process the inputs and outputs of the closure/function. However, sometimes there are late-bound regions which do not appear in the fn parameters but which are nonetheless in scope. The simplest case of this are unused functions, like fn foo<'a>() { } (see eg., #51351). Despite not being used, users can still reference these regions (e.g., let x: &'a u32 = &22;), so we need to create entries for them and store them in the indices map. This code iterates over the complete set of late-bound regions and checks for any that we have not yet seen, adding them to the inputs vector.
There was a problem hiding this comment.
Nit: I was thinking we could check indices to detect if the region already exists, but I guess in that case we'd have to create the liberated_region first. Still, we are doing that already below...
There was a problem hiding this comment.
Hmm, thinking a bit more about this, something seems a touch off. In particular, if we are looking at a closure, the added_from_input_and_output is going to contain late-bound regions from the closure's inputs and outputs. But here we are comparing against late-bound regions bound on the closure owner (closure_base_def_id).
I think comparing against entries in indices would be more robust. The diff would basically be to remove added_from_input_and_output and instead do:
let liberated_region = ...;
if !indices.contains_key(&liberated_region) {
let region_vid = self.infcx.next_nll_region_var(FR);
indices.insert_late_bound_region(liberated_region, region_vid.to_region_vid());
}There was a problem hiding this comment.
As I noted on Zulip, in the case of a closure, this code needs to execute earlier -- that is, the late-bound regions on the closure's creator are not local free regions, so they must be created up above, before the first_local_index variable is assigned.
There was a problem hiding this comment.
I think we only want to do this here if self.mir_def_id != closure_base_def_id -- i.e., if this is a closure/generator -- otherwise, we want to do it in the location you originally had it.
|
The job Click to expand the log.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 |
c668a8b to
2e7a62a
Compare
There was a problem hiding this comment.
I wonder why is this nice error only in compare mode
|
The job Click to expand the log.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 |
nikomatsakis
left a comment
There was a problem hiding this comment.
Looks awesome! I just had some documentation nits.
There was a problem hiding this comment.
can this be reverted?
There was a problem hiding this comment.
Nit: I would call this for_each_late_bound_region -- fold suggests to me that we are propagating a result back. I'd probably even call it for_each_late_bound_region_defined_on but I sort of have a penchant for long names. ;)
There was a problem hiding this comment.
Also a comment is a good idea, something like:
Iterates over the late-bound regions defined on fn_def_id and invokes `` with the liberated form of each one.
There was a problem hiding this comment.
This merits a comment. Something like
If this is a closure or generator, then the late-bound regions from the enclosing function are actually external regions to us. For example, here, 'a is not local to the closure c (although it is local to the fn foo):
fn foo<'a>() {
let c = || {
let x: &'a u32 = ...;
}
}
There was a problem hiding this comment.
Similarly, I would put a comment here like
Converse of above, if this is a function then the late-bound regions declared on its signature are local to the fn.
src/test/ui/nll/issue-51351.rs
Outdated
There was a problem hiding this comment.
Short comment documenting the purpose of the test would be nice:
Regression test for #51351 and #52133: In the case of #51351, late-bound regions (like 'a) that were unused within the arguments of a function were overlooked and could case an ICE. In the case of #52133, LBR defined on the creator function needed to be added to the free regions of the closure, as they were not present in the closure's generic declarations otherwise.
|
@bors delegate=mikhail-m1 @mikhail-m1 -- I delegated to you, so once the nits are fixed, you can feel free to write "r=nikomatsakis" to bors =) |
|
✌️ @mikhail-m1 can now approve this pull request |
|
@bors r=nikomatsakis |
|
📌 Commit bb66d70 has been approved by |
fix simple case of issue #51351 and #52133 r? @nikomatsakis
|
☀️ Test successful - status-appveyor, status-travis |
Fix wrong issue number in the test name I made a mistake in previous PR rust-lang#52620, second issue number was wrong, changing from rust-lang#52133 to rust-lang#52113 r? @kennytm
Fix wrong issue number in the test name I made a mistake in previous PR rust-lang#52620, second issue number was wrong, changing from rust-lang#52133 to rust-lang#52113 r? @kennytm
Fix wrong issue number in the test name I made a mistake in previous PR rust-lang#52620, second issue number was wrong, changing from rust-lang#52133 to rust-lang#52113 r? @kennytm
Fix wrong issue number in the test name I made a mistake in previous PR rust-lang#52620, second issue number was wrong, changing from rust-lang#52133 to rust-lang#52113 r? @kennytm
fix for #51351 and #52113
r? @nikomatsakis