Run clippy on CI

Fixes #1402.
This commit is contained in:
Kirill Chibisov 2022-06-10 13:43:33 +03:00 committed by GitHub
parent 57981b533d
commit 10419ff441
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
72 changed files with 377 additions and 312 deletions

View file

@ -16,7 +16,7 @@ pub struct EventLoop<T: 'static> {
elw: RootEventLoopWindowTarget<T>,
}
#[derive(Default, Debug, Copy, Clone, PartialEq, Hash)]
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub(crate) struct PlatformSpecificEventLoopAttributes {}
impl<T> EventLoop<T> {

View file

@ -456,11 +456,8 @@ impl<T: 'static> Shared<T> {
ControlFlow::ExitWithCode(_) => State::Exit,
};
match *self.0.runner.borrow_mut() {
RunnerEnum::Running(ref mut runner) => {
runner.state = new_state;
}
_ => (),
if let RunnerEnum::Running(ref mut runner) = *self.0.runner.borrow_mut() {
runner.state = new_state;
}
}

View file

@ -22,10 +22,7 @@ pub enum State {
impl State {
pub fn is_exit(&self) -> bool {
match self {
State::Exit => true,
_ => false,
}
matches!(self, State::Exit)
}
pub fn control_flow(&self) -> ControlFlow {

View file

@ -44,11 +44,11 @@ impl Canvas {
Some(canvas) => canvas,
None => {
let window = web_sys::window()
.ok_or(os_error!(OsError("Failed to obtain window".to_owned())))?;
.ok_or_else(|| os_error!(OsError("Failed to obtain window".to_owned())))?;
let document = window
.document()
.ok_or(os_error!(OsError("Failed to obtain document".to_owned())))?;
.ok_or_else(|| os_error!(OsError("Failed to obtain document".to_owned())))?;
document
.create_element("canvas")
@ -94,10 +94,10 @@ impl Canvas {
self.raw().request_pointer_lock();
} else {
let window = web_sys::window()
.ok_or(os_error!(OsError("Failed to obtain window".to_owned())))?;
.ok_or_else(|| os_error!(OsError("Failed to obtain window".to_owned())))?;
let document = window
.document()
.ok_or(os_error!(OsError("Failed to obtain document".to_owned())))?;
.ok_or_else(|| os_error!(OsError("Failed to obtain document".to_owned())))?;
document.exit_pointer_lock();
}
Ok(())
@ -107,7 +107,7 @@ impl Canvas {
self.common
.raw
.set_attribute(attribute, value)
.expect(&format!("Set attribute: {}", attribute));
.unwrap_or_else(|err| panic!("error: {:?}\nSet attribute: {}", err, attribute))
}
pub fn position(&self) -> LogicalPosition<f64> {
@ -339,9 +339,7 @@ impl Common {
handler(event);
}) as Box<dyn FnMut(E)>);
let listener = EventListenerHandle::new(&self.raw, event_name, closure);
listener
EventListenerHandle::new(&self.raw, event_name, closure)
}
// The difference between add_event and add_user_event is that the latter has a special meaning

View file

@ -8,6 +8,8 @@ use std::rc::Rc;
use web_sys::{EventTarget, MouseEvent};
type MouseLeaveHandler = Rc<RefCell<Option<Box<dyn FnMut(i32)>>>>;
#[allow(dead_code)]
pub(super) struct MouseHandler {
on_mouse_leave: Option<EventListenerHandle<dyn FnMut(MouseEvent)>>,
@ -15,7 +17,7 @@ pub(super) struct MouseHandler {
on_mouse_move: Option<EventListenerHandle<dyn FnMut(MouseEvent)>>,
on_mouse_press: Option<EventListenerHandle<dyn FnMut(MouseEvent)>>,
on_mouse_release: Option<EventListenerHandle<dyn FnMut(MouseEvent)>>,
on_mouse_leave_handler: Rc<RefCell<Option<Box<dyn FnMut(i32)>>>>,
on_mouse_leave_handler: MouseLeaveHandler,
mouse_capture_state: Rc<RefCell<MouseCaptureState>>,
}
@ -175,8 +177,8 @@ impl MouseHandler {
.map_or(false, |target| target == EventTarget::from(canvas.clone()));
match &*mouse_capture_state {
// Don't handle hover events outside of canvas.
MouseCaptureState::NotCaptured if !is_over_canvas => return,
MouseCaptureState::OtherElement if !is_over_canvas => return,
MouseCaptureState::NotCaptured | MouseCaptureState::OtherElement
if !is_over_canvas => {}
// If hovering over the canvas, just send the cursor move event.
MouseCaptureState::NotCaptured
| MouseCaptureState::OtherElement

View file

@ -17,7 +17,7 @@ impl MediaQueryListHandle {
.ok()
.flatten()
.and_then(|mql| {
mql.add_listener_with_opt_callback(Some(&listener.as_ref().unchecked_ref()))
mql.add_listener_with_opt_callback(Some(listener.as_ref().unchecked_ref()))
.map(|_| mql)
.ok()
});

View file

@ -98,7 +98,7 @@ pub fn set_canvas_style_property(raw: &HtmlCanvasElement, property: &str, value:
let style = raw.style();
style
.set_property(property, value)
.expect(&format!("Failed to set {}", property));
.unwrap_or_else(|err| panic!("error: {:?}\nFailed to set {}", err, property))
}
pub fn is_fullscreen(canvas: &HtmlCanvasElement) -> bool {

View file

@ -65,13 +65,13 @@ impl ScaleChangeDetectorInternal {
);
let mql = MediaQueryListHandle::new(&media_query, closure);
if let Some(mql) = &mql {
assert_eq!(mql.mql().matches(), true);
assert!(mql.mql().matches());
}
mql
}
fn handler(&mut self, event: MediaQueryListEvent) {
assert_eq!(event.matches(), false);
assert!(!event.matches());
let mql = self
.mql
.take()

View file

@ -21,7 +21,7 @@ impl Timeout {
let handle = window
.set_timeout_with_callback_and_timeout_and_arguments_0(
&closure.as_ref().unchecked_ref(),
closure.as_ref().unchecked_ref(),
duration.as_millis() as i32,
)
.expect("Failed to set timeout");
@ -64,7 +64,7 @@ impl AnimationFrameRequest {
}) as Box<dyn FnMut()>);
let handle = window
.request_animation_frame(&closure.as_ref().unchecked_ref())
.request_animation_frame(closure.as_ref().unchecked_ref())
.expect("Failed to request animation frame");
AnimationFrameRequest {

View file

@ -36,11 +36,11 @@ impl Window {
let id = target.generate_id();
let canvas = backend::Canvas::create(platform_attr)?;
let mut canvas = Rc::new(RefCell::new(canvas));
let canvas = Rc::new(RefCell::new(canvas));
let register_redraw_request = Box::new(move || runner.request_redraw(RootWI(id)));
target.register(&mut canvas, id);
target.register(&canvas, id);
let runner = target.runner.clone();
let resize_notify_fn = Box::new(move |new_size| {
@ -77,7 +77,7 @@ impl Window {
Ok(window)
}
pub fn canvas<'a>(&'a self) -> Ref<'a, backend::Canvas> {
pub fn canvas(&self) -> Ref<'_, backend::Canvas> {
self.canvas.borrow()
}
@ -220,7 +220,7 @@ impl Window {
self.canvas
.borrow()
.set_cursor_grab(grab)
.map_err(|e| ExternalError::Os(e))
.map_err(ExternalError::Os)
}
#[inline]
@ -344,7 +344,7 @@ impl Window {
#[inline]
pub fn id(&self) -> WindowId {
return self.id;
self.id
}
#[inline]