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

Regression from beta: closure may outlive the current function, but it borrows `...`, which is owned by the current function #24364

Closed
tomaka opened this Issue Apr 13, 2015 · 3 comments

Comments

Projects
None yet
4 participants
@tomaka
Copy link
Contributor

tomaka commented Apr 13, 2015

As reported in this thread, the two examples here no longer compile with the nightly but they do compile with the beta (tested with the 2015-04-12 nightly).

examples/displacement_mapping.rs:200:25: 237:6 error: closure may outlive the current function, but it borrows `opengl_texture`, which is owned by the current function [E0373]
examples/displacement_mapping.rs:200     support::start_loop(|| {
examples/displacement_mapping.rs:201         // building the uniforms
examples/displacement_mapping.rs:202         let uniforms = uniform! {
examples/displacement_mapping.rs:203             inner_level: 64.0f32,
examples/displacement_mapping.rs:204             outer_level: 64.0f32,
examples/displacement_mapping.rs:205             projection_matrix: camera.get_perspective(),
                                     ...
examples/displacement_mapping.rs:212:30: 212:44 note: `opengl_texture` is borrowed here
examples/displacement_mapping.rs:212             height_texture: &opengl_texture,
                                                                  ^~~~~~~~~~~~~~
<glium macros>:1:1: 12:46 note: in expansion of uniform!
examples/displacement_mapping.rs:202:24: 215:11 note: expansion site
examples/displacement_mapping.rs:200:25: 237:6 help: to force the closure to take ownership of `opengl_texture` (and any other referenced variables), use the `move` keyword, as shown:
examples/displacement_mapping.rs:        support::start_loop(move || {
examples/displacement_mapping.rs:            // building the uniforms
examples/displacement_mapping.rs:            let uniforms = uniform! {
examples/displacement_mapping.rs:                inner_level: 64.0f32,
examples/displacement_mapping.rs:                outer_level: 64.0f32,
examples/displacement_mapping.rs:                projection_matrix: camera.get_perspective(),
                                     ...

I didn't manage to reproduce on a small scale, so I'll explain a bit the code of displacement_mapping.rs:

  • At line 32 we create a struct of type CompressedTexture2d.
  • The type &'a CompressedTexture2d implements the trait IntoUniformValue<'a>. This trait can turn the reference into a UniformValue<'a>.
  • Line 200 we enter a closure. The support::start_loop function has this signature: fn start_loop<F>(mut callback: F) where F: FnMut() -> Action.
  • Lines 202-215 we borrow &'a the texture, call into_uniform_value() and store the UniformValue<'a> in a Vec.
  • Lines 220-225 uses &uniforms (only borrows it to see its content, doesn't do anything special with its lifetime).

More precisely, the uniform! macro invokation does the following:

{
    let uniforms = UniformsStorage::new("inner_level", 64.0f32);
    let uniforms = uniforms.add("outer_level", 64.0f32);
    ...
    let uniforms = uniforms.add("height_texture", &opengl_texture);
    let uniforms = uniforms.add("elevation", 0.3f32);
    let uniforms = uniforms.add("color_texture", &opengl_texture);
    uniforms
}

See the definition of UniformsStorage here.

@brson

This comment has been minimized.

Copy link
Contributor

brson commented May 28, 2015

I'm untagging all pre-1.0 regressions to repurpose it for stable regressions.

@pnkfelix

This comment has been minimized.

Copy link
Member

pnkfelix commented May 28, 2015

@brson from skimming the description this might be a regression against 1.0 -- it is described as code that compiled in the beta but did not compile in nightly....

(As an aside, perhaps we should have distinct tags for regressions against the stable channel versus regressions against the beta channel. Or maybe not, perhaps both need equal prioritization...)

@tomaka

This comment has been minimized.

Copy link
Contributor Author

tomaka commented Aug 19, 2015

I'm closing this as 1.0 is old now. Fixing a regression from beta to 1.0 doesn't really make sense anymore.

@tomaka tomaka closed this Aug 19, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.