Skip to content

Commit

Permalink
Clippy fixes (#2011)
Browse files Browse the repository at this point in the history
* windows: bump winapi version

* windows: address dark_mode FIXMEs

use now available winapi structures

* clippy: fix clippy::upper_case_acronyms warnings

* clippy: fix needless_arbitrary_self_type warnings

* clippy: fix clone_on_copy warnings

* clippy: fix unnecessary_mut_passed warnings

* clippy: fix identity_op warnings

* clippy: fix misc warnings

* prefix rustdoc lints with rustdoc::

the prefix was introduced in Rust 1.52

* windows: silence file_drop_handler is never read warning

* clippy: fix from_over_into warnings

and a bit of naming simplification

* clippy: fix missing_safety_doc warnings

* make dummy() functions const
  • Loading branch information
filnet committed Aug 30, 2021
1 parent 9e72396 commit 1b3b82a
Show file tree
Hide file tree
Showing 22 changed files with 119 additions and 143 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -58,7 +58,7 @@ features = ["display_link"]
parking_lot = "0.11"

[target.'cfg(target_os = "windows")'.dependencies.winapi]
version = "0.3.6"
version = "0.3.9"
features = [
"combaseapi",
"commctrl",
Expand Down
90 changes: 42 additions & 48 deletions src/dpi.rs
Expand Up @@ -211,9 +211,9 @@ impl<P: Pixel, X: Pixel> From<(X, X)> for LogicalPosition<P> {
}
}

impl<P: Pixel, X: Pixel> Into<(X, X)> for LogicalPosition<P> {
fn into(self: Self) -> (X, X) {
(self.x.cast(), self.y.cast())
impl<P: Pixel, X: Pixel> From<LogicalPosition<P>> for (X, X) {
fn from(p: LogicalPosition<P>) -> (X, X) {
(p.x.cast(), p.y.cast())
}
}

Expand All @@ -223,26 +223,23 @@ impl<P: Pixel, X: Pixel> From<[X; 2]> for LogicalPosition<P> {
}
}

impl<P: Pixel, X: Pixel> Into<[X; 2]> for LogicalPosition<P> {
fn into(self: Self) -> [X; 2] {
[self.x.cast(), self.y.cast()]
impl<P: Pixel, X: Pixel> From<LogicalPosition<P>> for [X; 2] {
fn from(p: LogicalPosition<P>) -> [X; 2] {
[p.x.cast(), p.y.cast()]
}
}

#[cfg(feature = "mint")]
impl<P: Pixel> From<mint::Point2<P>> for LogicalPosition<P> {
fn from(mint: mint::Point2<P>) -> Self {
Self::new(mint.x, mint.y)
fn from(p: mint::Point2<P>) -> Self {
Self::new(p.x, p.y)
}
}

#[cfg(feature = "mint")]
impl<P: Pixel> From<LogicalPosition<P>> for mint::Point2<P> {
fn from(winit: LogicalPosition<P>) -> Self {
mint::Point2 {
x: winit.x,
y: winit.y,
}
fn from(p: LogicalPosition<P>) -> Self {
mint::Point2 { x: p.x, y: p.y }
}
}

Expand Down Expand Up @@ -293,9 +290,9 @@ impl<P: Pixel, X: Pixel> From<(X, X)> for PhysicalPosition<P> {
}
}

impl<P: Pixel, X: Pixel> Into<(X, X)> for PhysicalPosition<P> {
fn into(self: Self) -> (X, X) {
(self.x.cast(), self.y.cast())
impl<P: Pixel, X: Pixel> From<PhysicalPosition<P>> for (X, X) {
fn from(p: PhysicalPosition<P>) -> (X, X) {
(p.x.cast(), p.y.cast())
}
}

Expand All @@ -305,26 +302,23 @@ impl<P: Pixel, X: Pixel> From<[X; 2]> for PhysicalPosition<P> {
}
}

impl<P: Pixel, X: Pixel> Into<[X; 2]> for PhysicalPosition<P> {
fn into(self: Self) -> [X; 2] {
[self.x.cast(), self.y.cast()]
impl<P: Pixel, X: Pixel> From<PhysicalPosition<P>> for [X; 2] {
fn from(p: PhysicalPosition<P>) -> [X; 2] {
[p.x.cast(), p.y.cast()]
}
}

#[cfg(feature = "mint")]
impl<P: Pixel> From<mint::Point2<P>> for PhysicalPosition<P> {
fn from(mint: mint::Point2<P>) -> Self {
Self::new(mint.x, mint.y)
fn from(p: mint::Point2<P>) -> Self {
Self::new(p.x, p.y)
}
}

#[cfg(feature = "mint")]
impl<P: Pixel> From<PhysicalPosition<P>> for mint::Point2<P> {
fn from(winit: PhysicalPosition<P>) -> Self {
mint::Point2 {
x: winit.x,
y: winit.y,
}
fn from(p: PhysicalPosition<P>) -> Self {
mint::Point2 { x: p.x, y: p.y }
}
}

Expand Down Expand Up @@ -375,9 +369,9 @@ impl<P: Pixel, X: Pixel> From<(X, X)> for LogicalSize<P> {
}
}

impl<P: Pixel, X: Pixel> Into<(X, X)> for LogicalSize<P> {
fn into(self: LogicalSize<P>) -> (X, X) {
(self.width.cast(), self.height.cast())
impl<P: Pixel, X: Pixel> From<LogicalSize<P>> for (X, X) {
fn from(s: LogicalSize<P>) -> (X, X) {
(s.width.cast(), s.height.cast())
}
}

Expand All @@ -387,25 +381,25 @@ impl<P: Pixel, X: Pixel> From<[X; 2]> for LogicalSize<P> {
}
}

impl<P: Pixel, X: Pixel> Into<[X; 2]> for LogicalSize<P> {
fn into(self: Self) -> [X; 2] {
[self.width.cast(), self.height.cast()]
impl<P: Pixel, X: Pixel> From<LogicalSize<P>> for [X; 2] {
fn from(s: LogicalSize<P>) -> [X; 2] {
[s.width.cast(), s.height.cast()]
}
}

#[cfg(feature = "mint")]
impl<P: Pixel> From<mint::Vector2<P>> for LogicalSize<P> {
fn from(mint: mint::Vector2<P>) -> Self {
Self::new(mint.x, mint.y)
fn from(v: mint::Vector2<P>) -> Self {
Self::new(v.x, v.y)
}
}

#[cfg(feature = "mint")]
impl<P: Pixel> From<LogicalSize<P>> for mint::Vector2<P> {
fn from(winit: LogicalSize<P>) -> Self {
fn from(s: LogicalSize<P>) -> Self {
mint::Vector2 {
x: winit.width,
y: winit.height,
x: s.width,
y: s.height,
}
}
}
Expand Down Expand Up @@ -454,9 +448,9 @@ impl<P: Pixel, X: Pixel> From<(X, X)> for PhysicalSize<P> {
}
}

impl<P: Pixel, X: Pixel> Into<(X, X)> for PhysicalSize<P> {
fn into(self: Self) -> (X, X) {
(self.width.cast(), self.height.cast())
impl<P: Pixel, X: Pixel> From<PhysicalSize<P>> for (X, X) {
fn from(s: PhysicalSize<P>) -> (X, X) {
(s.width.cast(), s.height.cast())
}
}

Expand All @@ -466,25 +460,25 @@ impl<P: Pixel, X: Pixel> From<[X; 2]> for PhysicalSize<P> {
}
}

impl<P: Pixel, X: Pixel> Into<[X; 2]> for PhysicalSize<P> {
fn into(self: Self) -> [X; 2] {
[self.width.cast(), self.height.cast()]
impl<P: Pixel, X: Pixel> From<PhysicalSize<P>> for [X; 2] {
fn from(s: PhysicalSize<P>) -> [X; 2] {
[s.width.cast(), s.height.cast()]
}
}

#[cfg(feature = "mint")]
impl<P: Pixel> From<mint::Vector2<P>> for PhysicalSize<P> {
fn from(mint: mint::Vector2<P>) -> Self {
Self::new(mint.x, mint.y)
fn from(v: mint::Vector2<P>) -> Self {
Self::new(v.x, v.y)
}
}

#[cfg(feature = "mint")]
impl<P: Pixel> From<PhysicalSize<P>> for mint::Vector2<P> {
fn from(winit: PhysicalSize<P>) -> Self {
fn from(s: PhysicalSize<P>) -> Self {
mint::Vector2 {
x: winit.width,
y: winit.height,
x: s.width,
y: s.height,
}
}
}
Expand Down
28 changes: 16 additions & 12 deletions src/event.rs
Expand Up @@ -131,7 +131,7 @@ impl<T: Clone> Clone for Event<'static, T> {
device_id: *device_id,
event: event.clone(),
},
NewEvents(cause) => NewEvents(cause.clone()),
NewEvents(cause) => NewEvents(*cause),
MainEventsCleared => MainEventsCleared,
RedrawRequested(wid) => RedrawRequested(*wid),
RedrawEventsCleared => RedrawEventsCleared,
Expand Down Expand Up @@ -358,8 +358,8 @@ impl Clone for WindowEvent<'static> {
fn clone(&self) -> Self {
use self::WindowEvent::*;
return match self {
Resized(size) => Resized(size.clone()),
Moved(pos) => Moved(pos.clone()),
Resized(size) => Resized(*size),
Moved(pos) => Moved(*pos),
CloseRequested => CloseRequested,
Destroyed => Destroyed,
DroppedFile(file) => DroppedFile(file.clone()),
Expand All @@ -377,7 +377,7 @@ impl Clone for WindowEvent<'static> {
is_synthetic: *is_synthetic,
},

ModifiersChanged(modifiers) => ModifiersChanged(modifiers.clone()),
ModifiersChanged(modifiers) => ModifiersChanged(*modifiers),
#[allow(deprecated)]
CursorMoved {
device_id,
Expand Down Expand Up @@ -437,7 +437,7 @@ impl Clone for WindowEvent<'static> {
value: *value,
},
Touch(touch) => Touch(*touch),
ThemeChanged(theme) => ThemeChanged(theme.clone()),
ThemeChanged(theme) => ThemeChanged(*theme),
ScaleFactorChanged { .. } => {
unreachable!("Static event can't be about scale factor changing")
}
Expand Down Expand Up @@ -538,12 +538,16 @@ impl<'a> WindowEvent<'a> {
pub struct DeviceId(pub(crate) platform_impl::DeviceId);

impl DeviceId {
/// Returns a dummy `DeviceId`, useful for unit testing. The only guarantee made about the return
/// value of this function is that it will always be equal to itself and to future values returned
/// by this function. No other guarantees are made. This may be equal to a real `DeviceId`.
/// Returns a dummy `DeviceId`, useful for unit testing.
///
/// # Safety
///
/// The only guarantee made about the return value of this function is that
/// it will always be equal to itself and to future values returned by this function.
/// No other guarantees are made. This may be equal to a real `DeviceId`.
///
/// **Passing this into a winit function will result in undefined behavior.**
pub unsafe fn dummy() -> Self {
pub const unsafe fn dummy() -> Self {
DeviceId(platform_impl::DeviceId::dummy())
}
}
Expand Down Expand Up @@ -998,9 +1002,9 @@ bitflags! {
// left and right modifiers are currently commented out, but we should be able to support
// them in a future release
/// The "shift" key.
const SHIFT = 0b100 << 0;
// const LSHIFT = 0b010 << 0;
// const RSHIFT = 0b001 << 0;
const SHIFT = 0b100;
// const LSHIFT = 0b010;
// const RSHIFT = 0b001;
/// The "control" key.
const CTRL = 0b100 << 3;
// const LCTRL = 0b010 << 3;
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Expand Up @@ -130,7 +130,7 @@
//! [`raw_window_handle`]: ./window/struct.Window.html#method.raw_window_handle

#![deny(rust_2018_idioms)]
#![deny(broken_intra_doc_links)]
#![deny(rustdoc::broken_intra_doc_links)]

#[allow(unused_imports)]
#[macro_use]
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/android/mod.rs
Expand Up @@ -443,7 +443,7 @@ impl<T: 'static> EventLoopWindowTarget<T> {
pub struct WindowId;

impl WindowId {
pub fn dummy() -> Self {
pub const fn dummy() -> Self {
WindowId
}
}
Expand All @@ -452,7 +452,7 @@ impl WindowId {
pub struct DeviceId;

impl DeviceId {
pub fn dummy() -> Self {
pub const fn dummy() -> Self {
DeviceId
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/ios/mod.rs
Expand Up @@ -91,7 +91,7 @@ pub struct DeviceId {
}

impl DeviceId {
pub unsafe fn dummy() -> Self {
pub const unsafe fn dummy() -> Self {
DeviceId {
uiscreen: std::ptr::null_mut(),
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/ios/window.rs
Expand Up @@ -611,7 +611,7 @@ pub struct WindowId {
}

impl WindowId {
pub unsafe fn dummy() -> Self {
pub const unsafe fn dummy() -> Self {
WindowId {
window: std::ptr::null_mut(),
}
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/linux/mod.rs
Expand Up @@ -141,7 +141,7 @@ pub enum WindowId {
}

impl WindowId {
pub unsafe fn dummy() -> Self {
pub const unsafe fn dummy() -> Self {
#[cfg(feature = "wayland")]
return WindowId::Wayland(wayland::WindowId::dummy());
#[cfg(all(not(feature = "wayland"), feature = "x11"))]
Expand All @@ -158,7 +158,7 @@ pub enum DeviceId {
}

impl DeviceId {
pub unsafe fn dummy() -> Self {
pub const unsafe fn dummy() -> Self {
#[cfg(feature = "wayland")]
return DeviceId::Wayland(wayland::DeviceId::dummy());
#[cfg(all(not(feature = "wayland"), feature = "x11"))]
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/linux/wayland/mod.rs
Expand Up @@ -22,7 +22,7 @@ mod window;
pub struct DeviceId;

impl DeviceId {
pub unsafe fn dummy() -> Self {
pub const unsafe fn dummy() -> Self {
DeviceId
}
}
Expand All @@ -31,7 +31,7 @@ impl DeviceId {
pub struct WindowId(usize);

impl WindowId {
pub unsafe fn dummy() -> Self {
pub const unsafe fn dummy() -> Self {
WindowId(0)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/linux/x11/mod.rs
Expand Up @@ -490,7 +490,7 @@ impl<'a> Deref for DeviceInfo<'a> {
pub struct WindowId(ffi::Window);

impl WindowId {
pub unsafe fn dummy() -> Self {
pub const unsafe fn dummy() -> Self {
WindowId(0)
}
}
Expand All @@ -499,7 +499,7 @@ impl WindowId {
pub struct DeviceId(c_int);

impl DeviceId {
pub unsafe fn dummy() -> Self {
pub const unsafe fn dummy() -> Self {
DeviceId(0)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/macos/mod.rs
Expand Up @@ -33,7 +33,7 @@ pub(crate) use crate::icon::NoIcon as PlatformIcon;
pub struct DeviceId;

impl DeviceId {
pub unsafe fn dummy() -> Self {
pub const unsafe fn dummy() -> Self {
DeviceId
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/macos/window.rs
Expand Up @@ -51,7 +51,7 @@ use objc::{
pub struct Id(pub usize);

impl Id {
pub unsafe fn dummy() -> Self {
pub const unsafe fn dummy() -> Self {
Id(0)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/web/device.rs
Expand Up @@ -2,7 +2,7 @@
pub struct Id(pub i32);

impl Id {
pub unsafe fn dummy() -> Self {
pub const unsafe fn dummy() -> Self {
Id(0)
}
}

0 comments on commit 1b3b82a

Please sign in to comment.