Skip to content

Commit

Permalink
Run clippy on CI
Browse files Browse the repository at this point in the history
Fixes #1402.
  • Loading branch information
kchibisov committed Jun 7, 2022
1 parent 9253029 commit d0bce5a
Show file tree
Hide file tree
Showing 57 changed files with 405 additions and 404 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Expand Up @@ -17,7 +17,8 @@ jobs:
- name: Check Formatting
run: cargo +stable fmt --all -- --check

Tests:
tests:
name: Tests
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -62,6 +63,7 @@ jobs:
with:
rust-version: ${{ matrix.rust_version }}${{ matrix.platform.host }}
targets: ${{ matrix.platform.target }}
components: clippy

- name: Install Linux dependencies
if: (matrix.platform.os == 'ubuntu-latest')
Expand Down Expand Up @@ -93,6 +95,10 @@ jobs:
!contains(matrix.platform.target, 'wasm32'))
run: cargo $CMD test --verbose --target ${{ matrix.platform.target }} $OPTIONS --features $FEATURES

- name: Lint with clippy
shell: bash
if: (matrix.rust_version != 'nightly') && !contains(matrix.platform.options, '--no-default-features')
run: cargo clippy --all-targets --target ${{ matrix.platform.target }} $OPTIONS --features $FEATURES

- name: Build with serde enabled
shell: bash
Expand Down
7 changes: 3 additions & 4 deletions examples/fullscreen.rs
Expand Up @@ -34,8 +34,8 @@ fn main() {
event_loop.run(move |event, _, control_flow| {
control_flow.set_wait();

match event {
Event::WindowEvent { event, .. } => match event {
if let Event::WindowEvent { event, .. } = event {
match event {
WindowEvent::CloseRequested => control_flow.set_exit(),
WindowEvent::KeyboardInput {
input:
Expand Down Expand Up @@ -68,8 +68,7 @@ fn main() {
_ => (),
},
_ => (),
},
_ => {}
}
}
});
}
Expand Down
91 changes: 44 additions & 47 deletions examples/handling_close.rs
Expand Up @@ -23,62 +23,59 @@ fn main() {
};
control_flow.set_wait();

match event {
Event::WindowEvent { event, .. } => {
match event {
WindowEvent::CloseRequested => {
// `CloseRequested` is sent when the close button on the window is pressed (or
// through whatever other mechanisms the window manager provides for closing a
// window). If you don't handle this event, the close button won't actually do
// anything.
if let Event::WindowEvent { event, .. } = event {
match event {
WindowEvent::CloseRequested => {
// `CloseRequested` is sent when the close button on the window is pressed (or
// through whatever other mechanisms the window manager provides for closing a
// window). If you don't handle this event, the close button won't actually do
// anything.

// A common thing to do here is prompt the user if they have unsaved work.
// Creating a proper dialog box for that is far beyond the scope of this
// example, so here we'll just respond to the Y and N keys.
println!("Are you ready to bid your window farewell? [Y/N]");
close_requested = true;
// A common thing to do here is prompt the user if they have unsaved work.
// Creating a proper dialog box for that is far beyond the scope of this
// example, so here we'll just respond to the Y and N keys.
println!("Are you ready to bid your window farewell? [Y/N]");
close_requested = true;

// In applications where you can safely close the window without further
// action from the user, this is generally where you'd handle cleanup before
// closing the window. How to close the window is detailed in the handler for
// the Y key.
}
WindowEvent::KeyboardInput {
input:
KeyboardInput {
virtual_keycode: Some(virtual_code),
state: Released,
..
},
..
} => {
match virtual_code {
Y => {
if close_requested {
// This is where you'll want to do any cleanup you need.
println!("Buh-bye!");
// In applications where you can safely close the window without further
// action from the user, this is generally where you'd handle cleanup before
// closing the window. How to close the window is detailed in the handler for
// the Y key.
}
WindowEvent::KeyboardInput {
input:
KeyboardInput {
virtual_keycode: Some(virtual_code),
state: Released,
..
},
..
} => {
match virtual_code {
Y => {
if close_requested {
// This is where you'll want to do any cleanup you need.
println!("Buh-bye!");

// For a single-window application like this, you'd normally just
// break out of the event loop here. If you wanted to keep running the
// event loop (i.e. if it's a multi-window application), you need to
// drop the window. That closes it, and results in `Destroyed` being
// sent.
control_flow.set_exit();
}
// For a single-window application like this, you'd normally just
// break out of the event loop here. If you wanted to keep running the
// event loop (i.e. if it's a multi-window application), you need to
// drop the window. That closes it, and results in `Destroyed` being
// sent.
control_flow.set_exit();
}
N => {
if close_requested {
println!("Your window will continue to stay by your side.");
close_requested = false;
}
}
N => {
if close_requested {
println!("Your window will continue to stay by your side.");
close_requested = false;
}
_ => (),
}
_ => (),
}
_ => (),
}
_ => (),
}
_ => (),
}
});
}
12 changes: 6 additions & 6 deletions examples/min_max_size.rs
Expand Up @@ -19,12 +19,12 @@ fn main() {
control_flow.set_wait();
println!("{:?}", event);

match event {
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => control_flow.set_exit(),
_ => (),
if let Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} = event
{
control_flow.set_exit()
}
});
}
7 changes: 3 additions & 4 deletions examples/mouse_wheel.rs
Expand Up @@ -32,8 +32,8 @@ In other words, the deltas indicate the direction in which to move the content (
event_loop.run(move |event, _, control_flow| {
control_flow.set_wait();

match event {
Event::WindowEvent { event, .. } => match event {
if let Event::WindowEvent { event, .. } = event {
match event {
WindowEvent::CloseRequested => control_flow.set_exit(),
WindowEvent::MouseWheel { delta, .. } => match delta {
winit::event::MouseScrollDelta::LineDelta(x, y) => {
Expand All @@ -53,8 +53,7 @@ In other words, the deltas indicate the direction in which to move the content (
}
},
_ => (),
},
_ => (),
}
}
});
}
8 changes: 4 additions & 4 deletions examples/multithreaded.rs
Expand Up @@ -147,8 +147,9 @@ fn main() {
true => control_flow.set_wait(),
false => control_flow.set_exit(),
};
match event {
Event::WindowEvent { event, window_id } => match event {

if let Event::WindowEvent { event, window_id } = event {
match event {
WindowEvent::CloseRequested
| WindowEvent::Destroyed
| WindowEvent::KeyboardInput {
Expand All @@ -169,8 +170,7 @@ fn main() {
}
}
}
},
_ => {}
}
}
})
}
Expand Down
43 changes: 20 additions & 23 deletions examples/multiwindow.rs
Expand Up @@ -20,34 +20,31 @@ fn main() {
event_loop.run(move |event, event_loop, control_flow| {
control_flow.set_wait();

match event {
Event::WindowEvent { event, window_id } => {
match event {
WindowEvent::CloseRequested => {
println!("Window {:?} has received the signal to close", window_id);
if let Event::WindowEvent { event, window_id } = event {
match event {
WindowEvent::CloseRequested => {
println!("Window {:?} has received the signal to close", window_id);

// This drops the window, causing it to close.
windows.remove(&window_id);
// This drops the window, causing it to close.
windows.remove(&window_id);

if windows.is_empty() {
control_flow.set_exit();
}
if windows.is_empty() {
control_flow.set_exit();
}
WindowEvent::KeyboardInput {
input:
KeyboardInput {
state: ElementState::Pressed,
..
},
..
} => {
let window = Window::new(event_loop).unwrap();
windows.insert(window.id(), window);
}
_ => (),
}
WindowEvent::KeyboardInput {
input:
KeyboardInput {
state: ElementState::Pressed,
..
},
..
} => {
let window = Window::new(event_loop).unwrap();
windows.insert(window.id(), window);
}
_ => (),
}
_ => (),
}
})
}
7 changes: 3 additions & 4 deletions examples/request_redraw_threaded.rs
Expand Up @@ -28,10 +28,9 @@ fn main() {
control_flow.set_wait();

match event {
Event::WindowEvent { event, .. } => match event {
WindowEvent::CloseRequested => control_flow.set_exit(),
_ => (),
},
Event::WindowEvent { event, .. } if event == WindowEvent::CloseRequested => {
control_flow.set_exit()
}
Event::RedrawRequested(_) => {
println!("\nredrawing!\n");
}
Expand Down
9 changes: 4 additions & 5 deletions examples/resizable.rs
Expand Up @@ -22,8 +22,8 @@ fn main() {
event_loop.run(move |event, _, control_flow| {
control_flow.set_wait();

match event {
Event::WindowEvent { event, .. } => match event {
if let Event::WindowEvent { event, .. } = event {
match event {
WindowEvent::CloseRequested => control_flow.set_exit(),
WindowEvent::KeyboardInput {
input:
Expand All @@ -39,8 +39,7 @@ fn main() {
window.set_resizable(resizable);
}
_ => (),
},
_ => (),
};
}
}
});
}
12 changes: 6 additions & 6 deletions examples/transparent.rs
Expand Up @@ -21,12 +21,12 @@ fn main() {
control_flow.set_wait();
println!("{:?}", event);

match event {
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => control_flow.set_exit(),
_ => (),
if let Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} = event
{
control_flow.set_exit()
}
});
}
1 change: 1 addition & 0 deletions examples/web.rs
Expand Up @@ -43,6 +43,7 @@ mod wasm {
pub fn run() {
console_log::init_with_level(log::Level::Debug).expect("error initializing logger");

#[allow(clippy::main_recursion)]
super::main();
}

Expand Down

0 comments on commit d0bce5a

Please sign in to comment.