Skip to content

Commit

Permalink
Add test showcasing lifetime issue of AsUniformValue for Texture2d
Browse files Browse the repository at this point in the history
Currently this fails to compile with:
```
error[E0515]: cannot return value referencing function parameter `texture`
   --> tests/texture_creation.rs:103:9
    |
103 |         texture.as_uniform_value()
    |         -------^^^^^^^^^^^^^^^^^^^
    |         |
    |         returns a value referencing data owned by the current function
    |         `texture` is borrowed here

error: aborting due to previous error

For more information about this error, try `rustc --explain E0515`.
```
  • Loading branch information
strohel committed Aug 10, 2021
1 parent 2c6caf9 commit 9212005
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/texture_creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,29 @@ fn texture_2d_creation() {
display.assert_no_error(None);
}

#[test]
fn texture_2d_as_uniform_value_lifetime() {
let display = support::build_display();

let texture = glium::texture::Texture2d::new(&display, vec![
vec![(0, 0, 0, 0), (0, 0, 0, 0)],
vec![(0, 0, 0, 0), (0, 0, 0, 0)],
vec![(0, 0, 0, 0), (0, 0, 0, 0u8)],
]).unwrap();

// A function that takes texture reference should be able to return UniformValue (with lifetime
// inherited from the reference).
fn get_uniforms(texture: &glium::texture::Texture2d) -> glium::uniforms::UniformValue {
use glium::uniforms::AsUniformValue;
texture.as_uniform_value()
}

let uniforms = get_uniforms(&texture);
assert!(matches!(uniforms, glium::uniforms::UniformValue::Texture2d(..)));

display.assert_no_error(None);
}

#[test]
fn empty_texture2d_u8u8u8u8() {
let display = support::build_display();
Expand Down

0 comments on commit 9212005

Please sign in to comment.