Skip to content

Commit

Permalink
Run clippy on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
kchibisov committed Jun 8, 2022
1 parent 2c01e9e commit 2178a0f
Show file tree
Hide file tree
Showing 72 changed files with 376 additions and 312 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
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 -- -Dwarnings

- name: Build with serde enabled
shell: bash
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ And please only add new entries to the top of this list, right below the `# Unre
- **Breaking:** IME input on desktop platforms won't be received unless it's explicitly allowed via `Window::set_ime_allowed` and new `WindowEvent::Ime` events are handled.
- On macOS, `WindowEvent::Resized` is now emitted in `frameDidChange` instead of `windowDidResize`.
- **Breaking:** On X11, device events are now ignored for unfocused windows by default, use `EventLoopWindowTarget::set_device_event_filter` to set the filter level.
- Implemented `Default` on `EventLoop<()>`.

# 0.26.1 (2022-01-05)

Expand Down
2 changes: 2 additions & 0 deletions examples/control_flow.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::single_match)]

use std::{thread, time};

use simple_logger::SimpleLogger;
Expand Down
2 changes: 2 additions & 0 deletions examples/cursor.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::single_match)]

use simple_logger::SimpleLogger;
use winit::{
event::{ElementState, Event, KeyboardInput, WindowEvent},
Expand Down
2 changes: 2 additions & 0 deletions examples/cursor_grab.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::single_match)]

use simple_logger::SimpleLogger;
use winit::{
event::{DeviceEvent, ElementState, Event, KeyboardInput, ModifiersState, WindowEvent},
Expand Down
2 changes: 2 additions & 0 deletions examples/custom_events.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::single_match)]

#[cfg(not(target_arch = "wasm32"))]
fn main() {
use simple_logger::SimpleLogger;
Expand Down
2 changes: 2 additions & 0 deletions examples/drag_window.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::single_match)]

use simple_logger::SimpleLogger;
use winit::{
event::{
Expand Down
2 changes: 2 additions & 0 deletions examples/fullscreen.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::single_match)]

use std::io::{stdin, stdout, Write};

use simple_logger::SimpleLogger;
Expand Down
2 changes: 2 additions & 0 deletions examples/handling_close.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::single_match)]

use simple_logger::SimpleLogger;
use winit::{
event::{Event, KeyboardInput, WindowEvent},
Expand Down
2 changes: 2 additions & 0 deletions examples/ime.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::single_match)]

use log::LevelFilter;
use simple_logger::SimpleLogger;
use winit::{
Expand Down
2 changes: 2 additions & 0 deletions examples/min_max_size.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::single_match)]

use simple_logger::SimpleLogger;
use winit::{
dpi::LogicalSize,
Expand Down
2 changes: 1 addition & 1 deletion examples/minimize.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extern crate winit;
#![allow(clippy::single_match)]

use simple_logger::SimpleLogger;
use winit::event::{Event, VirtualKeyCode, WindowEvent};
Expand Down
2 changes: 2 additions & 0 deletions examples/monitor_list.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::single_match)]

use simple_logger::SimpleLogger;
use winit::{event_loop::EventLoop, window::WindowBuilder};

Expand Down
2 changes: 2 additions & 0 deletions examples/mouse_wheel.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::single_match)]

use simple_logger::SimpleLogger;
use winit::{
event::{Event, WindowEvent},
Expand Down
2 changes: 2 additions & 0 deletions examples/multithreaded.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::single_match)]

#[cfg(not(target_arch = "wasm32"))]
fn main() {
use std::{collections::HashMap, sync::mpsc, thread, time::Duration};
Expand Down
2 changes: 2 additions & 0 deletions examples/multiwindow.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::single_match)]

use std::collections::HashMap;

use simple_logger::SimpleLogger;
Expand Down
2 changes: 2 additions & 0 deletions examples/request_redraw.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::single_match)]

use simple_logger::SimpleLogger;
use winit::{
event::{ElementState, Event, WindowEvent},
Expand Down
10 changes: 6 additions & 4 deletions examples/request_redraw_threaded.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::single_match)]

#[cfg(not(target_arch = "wasm32"))]
fn main() {
use std::{thread, time};
Expand Down Expand Up @@ -28,10 +30,10 @@ fn main() {
control_flow.set_wait();

match event {
Event::WindowEvent { event, .. } => match event {
WindowEvent::CloseRequested => control_flow.set_exit(),
_ => (),
},
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => control_flow.set_exit(),
Event::RedrawRequested(_) => {
println!("\nredrawing!\n");
}
Expand Down
2 changes: 2 additions & 0 deletions examples/resizable.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::single_match)]

use simple_logger::SimpleLogger;
use winit::{
dpi::LogicalSize,
Expand Down
2 changes: 2 additions & 0 deletions examples/timer.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::single_match)]

use instant::Instant;
use std::time::Duration;

Expand Down
2 changes: 2 additions & 0 deletions examples/transparent.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::single_match)]

use simple_logger::SimpleLogger;
use winit::{
event::{Event, WindowEvent},
Expand Down
2 changes: 2 additions & 0 deletions examples/video_modes.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::single_match)]

use simple_logger::SimpleLogger;
use winit::event_loop::EventLoop;

Expand Down
3 changes: 3 additions & 0 deletions examples/web.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::single_match)]

use winit::{
event::{Event, WindowEvent},
event_loop::EventLoop,
Expand Down Expand Up @@ -43,6 +45,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
2 changes: 2 additions & 0 deletions examples/window.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::single_match)]

use simple_logger::SimpleLogger;
use winit::{
event::{Event, WindowEvent},
Expand Down
104 changes: 54 additions & 50 deletions examples/window_debug.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::single_match)]

// This example is used by developers to test various window functions.

use simple_logger::SimpleLogger;
Expand Down Expand Up @@ -58,61 +60,63 @@ fn main() {
_ => (),
},
Event::WindowEvent {
event: WindowEvent::KeyboardInput { input, .. },
event:
WindowEvent::KeyboardInput {
input:
KeyboardInput {
virtual_keycode: Some(key),
state: ElementState::Pressed,
..
},
..
},
..
} => match input {
KeyboardInput {
virtual_keycode: Some(key),
state: ElementState::Pressed,
..
} => match key {
VirtualKeyCode::E => {
fn area(size: PhysicalSize<u32>) -> u32 {
size.width * size.height
}

let monitor = window.current_monitor().unwrap();
if let Some(mode) = monitor
.video_modes()
.max_by(|a, b| area(a.size()).cmp(&area(b.size())))
{
window.set_fullscreen(Some(Fullscreen::Exclusive(mode)));
} else {
eprintln!("no video modes available");
}
}
VirtualKeyCode::F => {
if window.fullscreen().is_some() {
window.set_fullscreen(None);
} else {
let monitor = window.current_monitor();
window.set_fullscreen(Some(Fullscreen::Borderless(monitor)));
}
}
VirtualKeyCode::P => {
if window.fullscreen().is_some() {
window.set_fullscreen(None);
} else {
window.set_fullscreen(Some(Fullscreen::Borderless(None)));
}
}
VirtualKeyCode::M => {
minimized = !minimized;
window.set_minimized(minimized);
} => match key {
VirtualKeyCode::E => {
fn area(size: PhysicalSize<u32>) -> u32 {
size.width * size.height
}
VirtualKeyCode::Q => {
control_flow.set_exit();

let monitor = window.current_monitor().unwrap();
if let Some(mode) = monitor
.video_modes()
.max_by(|a, b| area(a.size()).cmp(&area(b.size())))
{
window.set_fullscreen(Some(Fullscreen::Exclusive(mode)));
} else {
eprintln!("no video modes available");
}
VirtualKeyCode::V => {
visible = !visible;
window.set_visible(visible);
}
VirtualKeyCode::F => {
if window.fullscreen().is_some() {
window.set_fullscreen(None);
} else {
let monitor = window.current_monitor();
window.set_fullscreen(Some(Fullscreen::Borderless(monitor)));
}
VirtualKeyCode::X => {
let is_maximized = window.is_maximized();
window.set_maximized(!is_maximized);
}
VirtualKeyCode::P => {
if window.fullscreen().is_some() {
window.set_fullscreen(None);
} else {
window.set_fullscreen(Some(Fullscreen::Borderless(None)));
}
_ => (),
},
}
VirtualKeyCode::M => {
minimized = !minimized;
window.set_minimized(minimized);
}
VirtualKeyCode::Q => {
control_flow.set_exit();
}
VirtualKeyCode::V => {
visible = !visible;
window.set_visible(visible);
}
VirtualKeyCode::X => {
let is_maximized = window.is_maximized();
window.set_maximized(!is_maximized);
}
_ => (),
},
Event::WindowEvent {
Expand Down
3 changes: 2 additions & 1 deletion examples/window_icon.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
extern crate image;
#![allow(clippy::single_match)]

use std::path::Path;

use simple_logger::SimpleLogger;
Expand Down
2 changes: 2 additions & 0 deletions examples/window_run_return.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::single_match)]

// Limit this example to only compatible platforms.
#[cfg(any(
target_os = "windows",
Expand Down
8 changes: 8 additions & 0 deletions src/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ impl<T> EventLoopBuilder<T> {
/// will fall back on X11. If this variable is set with any other value, winit will panic.
#[inline]
pub fn build(&mut self) -> EventLoop<T> {
// Certain platforms accept mutable reference in their API.
#[allow(clippy::unnecessary_mut_passed)]
EventLoop {
event_loop: platform_impl::EventLoop::new(&mut self.platform_specific),
_marker: PhantomData,
Expand Down Expand Up @@ -221,6 +223,12 @@ impl EventLoop<()> {
}
}

impl Default for EventLoop<()> {
fn default() -> Self {
Self::new()
}
}

impl<T> EventLoop<T> {
#[deprecated = "Use `EventLoopBuilder::<T>::with_user_event().build()` instead."]
pub fn with_user_event() -> EventLoop<T> {
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@

#![deny(rust_2018_idioms)]
#![deny(rustdoc::broken_intra_doc_links)]
#![deny(clippy::all)]
#![cfg_attr(feature = "cargo-clippy", deny(warnings))]
#![allow(clippy::missing_safety_doc)]

#[allow(unused_imports)]
#[macro_use]
Expand Down
10 changes: 4 additions & 6 deletions src/platform_impl/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ pub struct EventLoop<T: 'static> {
running: bool,
}

#[derive(Default, Debug, Copy, Clone, PartialEq, Hash)]
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub(crate) struct PlatformSpecificEventLoopAttributes {}

macro_rules! call_event_handler {
Expand Down Expand Up @@ -848,18 +848,16 @@ impl MonitorHandle {

pub fn video_modes(&self) -> impl Iterator<Item = monitor::VideoMode> {
let size = self.size().into();
let mut v = Vec::new();
// FIXME this is not the real refresh rate
// (it is guarunteed to support 32 bit color though)
v.push(monitor::VideoMode {
// (it is guaranteed to support 32 bit color though)
std::iter::once(monitor::VideoMode {
video_mode: VideoMode {
size,
bit_depth: 32,
refresh_rate: 60,
monitor: self.clone(),
},
});
v.into_iter()
})
}
}

Expand Down
Loading

0 comments on commit 2178a0f

Please sign in to comment.