Open
Description
use glium::Display;
let display = Display::new(builder, context, &event_loop).unwrap();
if let gl_window = display.gl_window() {
let window = gl_window.window();
platform.attach_window(&mut gui_display, window, HiDpiMode::Default);
}
return display;
The current output is:
warning: irrefutable `if let` pattern
--> imgui-example\src\main.rs:153:5
|
153 | / if let gl_window = display.gl_window() {
154 | | let window = gl_window.window();
155 | | platform.attach_window(&mut gui_display, window, HiDpiMode::Default);
156 | | }
| |_____^
|
= note: `#[warn(irrefutable_let_patterns)]` on by default
= note: this pattern will always match, so the `if let` is useless
= help: consider replacing the `if let` with a `let`
Following the suggestion breaks the code, because lifetime in gl_window
could be used in Drop
of gl_window
while display is still being used.
I am not even sure if this can be reasonably implemented, so it is more of an question/sugestion what you think about scoping with if let
over manual call Drop
, or wrapping with block like this:
use glium::Display;
let display = Display::new(builder, context, &event_loop).unwrap();
{
let gl_window = display.gl_window();
let window = gl_window.window();
platform.attach_window(&mut gui_display, window, HiDpiMode::Default);
}
return display;
n my opinion if let
scoping is the shortest, and best explains the scope, without looking like too artificial scope.