rust-windowing / winit

Window handling library in pure Rust
https://docs.rs/winit/
Apache License 2.0
4.87k stars 910 forks source link

Event loop being interpreted as a global variable #3969

Closed code-Cells closed 4 weeks ago

code-Cells commented 4 weeks ago

Description

I tried running the https://docs.rs/winit/latest/winit/index.html example as is and keep getting the error message

  --> src/main.rs:43:1
   |
43 | let event_loop = EventLoop::new().unwrap();
   | ^^^ consider using `const` or `static` instead of `let` for global variables

Because of the lines below, it makes no sense for it to be a global variable.

event_loop.set_control_flow(ControlFlow::Poll);
event_loop.set_control_flow(ControlFlow::Wait);

Took some time researching, but didn't manage to fiend an issue about this. Is this a known one?

Also tried 0.30.1, and got the same problem.

OS and window mananger

Linux Mint 21.3 x11 cinnamon

Winit version

0.30.5

kchibisov commented 4 weeks ago

put them inside fn main() { /* your code here */ }.

madsmtm commented 4 weeks ago

To expand a little bit, the example is using the common rustdoc convention of eliding the main function in examples which Rust otherwise requires.

I have been thinking though, perhaps it would make sense to not do that here? Opened https://github.com/rust-windowing/winit/pull/3971 for that.