Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run clippy on CI #2315

Merged
merged 1 commit into from Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 -- -Dwarnings

- name: Build with serde enabled
shell: bash
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -53,6 +53,8 @@ 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<()>`.
- Implemented `Eq` for `Fullscreen`, `Theme`, and `UserAttentionType`.

# 0.26.1 (2022-01-05)

Expand Down
2 changes: 2 additions & 0 deletions examples/control_flow.rs
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
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 a 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<()> {
kchibisov marked this conversation as resolved.
Show resolved Hide resolved
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
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))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clippy enables the cargo-clippy feature on all crates when running through it, automatically denying all rustc warnings in this instance. However, this implies warnings from clippy::all (that lint group should only include warn/deny lints) and the #![deny(clippy::all)] is thus superfluous.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deny clippy all means that it'll error on clippy warnings instead of treating them as warnings.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that's also what #![cfg_attr(feature = "cargo-clippy", deny(warnings))] does :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think those about rustc warnings, and not clippy onces? I think it was like that in the past, at least.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it and it includes all warnings, including clippy ones.

#![allow(clippy::missing_safety_doc)]

#[allow(unused_imports)]
#[macro_use]
Expand Down
10 changes: 4 additions & 6 deletions src/platform_impl/android/mod.rs
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 @@ -846,18 +846,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