-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.L-irrefutable_let_patternsLint: irrefutable_let_patternsLint: irrefutable_let_patternsT-langRelevant to the language teamRelevant to the language team
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.
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.L-irrefutable_let_patternsLint: irrefutable_let_patternsLint: irrefutable_let_patternsT-langRelevant to the language teamRelevant to the language team
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity