From 31cfa82942984dc2614ea7d33b8819dd18e0c1b2 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Fri, 27 May 2022 16:07:36 +0200 Subject: [PATCH] Fix remaining clippy warnings by hand --- glutin/src/api/dlloader.rs | 7 +- glutin/src/api/egl/make_current_guard.rs | 2 +- glutin/src/api/egl/mod.rs | 209 ++++++++++----------- glutin/src/api/glx/make_current_guard.rs | 5 +- glutin/src/api/glx/mod.rs | 97 +++++----- glutin/src/api/ios/mod.rs | 1 - glutin/src/lib.rs | 26 +-- glutin/src/platform_impl/macos/helpers.rs | 20 +- glutin/src/platform_impl/macos/mod.rs | 6 +- glutin/src/platform_impl/mod.rs | 14 +- glutin/src/platform_impl/unix/x11.rs | 20 +- glutin/src/platform_impl/unix/x11/utils.rs | 4 +- glutin_egl_sys/src/lib.rs | 7 +- glutin_examples/examples/fullscreen.rs | 6 +- glutin_examples/examples/sharing.rs | 9 +- glutin_examples/examples/support/mod.rs | 8 + glutin_gles2_sys/src/lib.rs | 9 +- glutin_glx_sys/src/lib.rs | 6 + glutin_wgl_sys/src/lib.rs | 1 + 19 files changed, 233 insertions(+), 224 deletions(-) diff --git a/glutin/src/api/dlloader.rs b/glutin/src/api/dlloader.rs index fa35b03412e..40bbb414e24 100644 --- a/glutin/src/api/dlloader.rs +++ b/glutin/src/api/dlloader.rs @@ -42,11 +42,8 @@ impl SymWrapper { #[cfg(not(target_os = "windows"))] let lib = unsafe { Library::new(path) }; - if lib.is_ok() { - return Ok(SymWrapper { - inner: T::load_with(lib.as_ref().unwrap()), - _lib: Arc::new(lib.unwrap()), - }); + if let Ok(lib) = lib { + return Ok(SymWrapper { inner: T::load_with(&lib), _lib: Arc::new(lib) }); } } diff --git a/glutin/src/api/egl/make_current_guard.rs b/glutin/src/api/egl/make_current_guard.rs index 06911900b8e..ae078bd8e49 100644 --- a/glutin/src/api/egl/make_current_guard.rs +++ b/glutin/src/api/egl/make_current_guard.rs @@ -9,7 +9,7 @@ pub struct MakeCurrentGuard { possibly_invalid: Option, } -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] struct MakeCurrentGuardInner { old_draw_surface: ffi::egl::types::EGLSurface, old_read_surface: ffi::egl::types::EGLSurface, diff --git a/glutin/src/api/egl/mod.rs b/glutin/src/api/egl/mod.rs index 2745c17e35d..56ebf6b626c 100644 --- a/glutin/src/api/egl/mod.rs +++ b/glutin/src/api/egl/mod.rs @@ -7,116 +7,107 @@ target_os = "netbsd", target_os = "openbsd", ))] -#![allow(unused_variables)] -mod egl { - use super::ffi; - use crate::api::dlloader::{SymTrait, SymWrapper}; - use libloading; - use std::sync::{Arc, Mutex}; +use std::ffi::{CStr, CString}; +use std::ops::{Deref, DerefMut}; +use std::os::raw; +use std::sync::{Arc, Mutex}; + +use glutin_egl_sys as ffi; +use libloading; +#[cfg(unix)] +use libloading::os::unix as libloading_os; +#[cfg(windows)] +use libloading::os::windows as libloading_os; +#[cfg(any( + target_os = "android", + target_os = "windows", + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd", +))] +use winit::dpi; - #[cfg(unix)] - use libloading::os::unix as libloading_os; - #[cfg(windows)] - use libloading::os::windows as libloading_os; +use self::make_current_guard::MakeCurrentGuard; +use crate::api::dlloader::{SymTrait, SymWrapper}; +#[cfg(not(target_os = "windows"))] +use crate::Rect; +use crate::{ + Api, ContextError, CreationError, GlAttributes, GlRequest, PixelFormat, + PixelFormatRequirements, ReleaseBehavior, Robustness, +}; - #[derive(Clone)] - pub struct Egl(pub SymWrapper); +#[derive(Clone)] +pub struct Egl(pub SymWrapper); - /// Because `*const raw::c_void` doesn't implement `Sync`. - unsafe impl Sync for Egl {} +/// Because `*const raw::c_void` doesn't implement `Sync`. +unsafe impl Sync for Egl {} - type EglGetProcAddressType = libloading_os::Symbol< - unsafe extern "C" fn(*const std::os::raw::c_void) -> *const std::os::raw::c_void, - >; +type EglGetProcAddressType = libloading_os::Symbol< + unsafe extern "C" fn(*const std::os::raw::c_void) -> *const std::os::raw::c_void, +>; - lazy_static! { - static ref EGL_GET_PROC_ADDRESS: Arc>> = - Arc::new(Mutex::new(None)); - } +lazy_static! { + static ref EGL_GET_PROC_ADDRESS: Arc>> = + Arc::new(Mutex::new(None)); +} - impl SymTrait for ffi::egl::Egl { - fn load_with(lib: &libloading::Library) -> Self { - let f = move |s: &'static str| -> *const std::os::raw::c_void { - // Check if the symbol is available in the library directly. If - // it is, just return it. - match unsafe { - lib.get(std::ffi::CString::new(s.as_bytes()).unwrap().as_bytes_with_nul()) - } { - Ok(sym) => return *sym, - Err(_) => (), - }; - - let mut egl_get_proc_address = (*EGL_GET_PROC_ADDRESS).lock().unwrap(); - if egl_get_proc_address.is_none() { - unsafe { - let sym: libloading::Symbol< - unsafe extern "C" fn( - *const std::os::raw::c_void, - ) - -> *const std::os::raw::c_void, - > = lib.get(b"eglGetProcAddress").unwrap(); - *egl_get_proc_address = Some(sym.into_raw()); - } - } +impl SymTrait for ffi::egl::Egl { + fn load_with(lib: &libloading::Library) -> Self { + let f = move |s: &'static str| -> *const std::os::raw::c_void { + // Check if the symbol is available in the library directly. If + // it is, just return it. + if let Ok(sym) = unsafe { + lib.get(std::ffi::CString::new(s.as_bytes()).unwrap().as_bytes_with_nul()) + } { + return *sym; + } - // The symbol was not available in the library, so ask - // eglGetProcAddress for it. Note that eglGetProcAddress was - // only able to look up extension functions prior to EGL 1.5, - // hence this two-part dance. + let mut egl_get_proc_address = (*EGL_GET_PROC_ADDRESS).lock().unwrap(); + if egl_get_proc_address.is_none() { unsafe { - (egl_get_proc_address.as_ref().unwrap())( - std::ffi::CString::new(s.as_bytes()).unwrap().as_bytes_with_nul().as_ptr() - as *const std::os::raw::c_void, - ) + let sym: libloading::Symbol< + unsafe extern "C" fn( + *const std::os::raw::c_void, + ) + -> *const std::os::raw::c_void, + > = lib.get(b"eglGetProcAddress").unwrap(); + *egl_get_proc_address = Some(sym.into_raw()); } - }; + } - Self::load_with(f) - } + // The symbol was not available in the library, so ask + // eglGetProcAddress for it. Note that eglGetProcAddress was + // only able to look up extension functions prior to EGL 1.5, + // hence this two-part dance. + unsafe { + (egl_get_proc_address.as_ref().unwrap())( + std::ffi::CString::new(s.as_bytes()).unwrap().as_bytes_with_nul().as_ptr() + as *const std::os::raw::c_void, + ) + } + }; + + Self::load_with(f) } +} - impl Egl { - pub fn new() -> Result { - #[cfg(target_os = "windows")] - let paths = vec!["libEGL.dll", "atioglxx.dll"]; +impl Egl { + pub fn new() -> Result { + #[cfg(target_os = "windows")] + let paths = vec!["libEGL.dll", "atioglxx.dll"]; - #[cfg(not(target_os = "windows"))] - let paths = vec!["libEGL.so.1", "libEGL.so"]; + #[cfg(not(target_os = "windows"))] + let paths = vec!["libEGL.so.1", "libEGL.so"]; - SymWrapper::new(paths).map(Egl) - } + SymWrapper::new(paths).map(Egl) } } mod make_current_guard; -pub use self::egl::Egl; -use self::make_current_guard::MakeCurrentGuard; -#[cfg(not(target_os = "windows"))] -use crate::Rect; -use crate::{ - Api, ContextError, CreationError, GlAttributes, GlRequest, PixelFormat, - PixelFormatRequirements, ReleaseBehavior, Robustness, -}; - -use glutin_egl_sys as ffi; -use parking_lot::Mutex; -#[cfg(any( - target_os = "android", - target_os = "windows", - target_os = "linux", - target_os = "dragonfly", - target_os = "freebsd", - target_os = "netbsd", - target_os = "openbsd", -))] -use winit::dpi; - -use std::ffi::{CStr, CString}; -use std::ops::{Deref, DerefMut}; -use std::os::raw; - impl Deref for Egl { type Target = ffi::egl::Egl; @@ -158,7 +149,7 @@ pub enum NativeDisplay { pub struct Context { display: ffi::egl::types::EGLDisplay, context: ffi::egl::types::EGLContext, - surface: Option>, + surface: Option>, api: Api, pixel_format: PixelFormat, } @@ -249,7 +240,7 @@ fn get_native_display(native_display: &NativeDisplay) -> *const raw::c_void { } }; - let has_dp_extension = |e: &str| dp_extensions.iter().any(|s| &s == &e); + let has_dp_extension = |e: &str| dp_extensions.iter().any(|s| s == e); match *native_display { // Note: Some EGL implementations are missing the @@ -364,7 +355,7 @@ fn get_native_display(native_display: &NativeDisplay) -> *const raw::c_void { } #[allow(dead_code)] // Not all platforms use all -#[derive(Copy, Clone, PartialEq, Debug)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum SurfaceType { PBuffer, Window, @@ -376,8 +367,8 @@ impl Context { /// /// This function initializes some things and chooses the pixel format. /// - /// To finish the process, you must call `.finish(window)` on the - /// `ContextPrototype`. + /// To finish the process, you must call [`ContextPrototype::finish()`]. + #[allow(clippy::new_ret_no_self)] pub fn new<'a, F>( pf_reqs: &PixelFormatRequirements, opengl: &'a GlAttributes<&'a Context>, @@ -635,7 +626,7 @@ impl Drop for Context { guard.if_any_same_then_invalidate(surface, surface, self.context); let gl_finish_fn = self.get_proc_address("glFinish"); - assert!(gl_finish_fn != std::ptr::null()); + assert!(!gl_finish_fn.is_null()); let gl_finish_fn = std::mem::transmute::<_, extern "system" fn()>(gl_finish_fn); gl_finish_fn(); @@ -783,7 +774,7 @@ impl<'a> ContextPrototype<'a> { pub fn finish_surfaceless(self) -> Result { // FIXME: Also check for the GL_OES_surfaceless_context *CONTEXT* // extension - if !self.extensions.iter().any(|s| &s == &"EGL_KHR_surfaceless_context") { + if !self.extensions.iter().any(|s| s == "EGL_KHR_surfaceless_context") { Err(CreationError::NotSupported("EGL surfaceless not supported".to_string())) } else { self.finish_impl(None) @@ -803,11 +794,6 @@ impl<'a> ContextPrototype<'a> { let size: (u32, u32) = size.into(); let egl = EGL.as_ref().unwrap(); - let tex_fmt = if self.pixel_format.alpha_bits > 0 { - ffi::egl::TEXTURE_RGBA - } else { - ffi::egl::TEXTURE_RGB - }; let attrs = &[ ffi::egl::WIDTH as raw::c_int, size.0 as raw::c_int, @@ -936,7 +922,7 @@ impl<'a> ContextPrototype<'a> { Ok(Context { display: self.display, context, - surface: surface.map(Mutex::new), + surface: surface.map(parking_lot::Mutex::new), api: self.api, pixel_format: self.pixel_format, }) @@ -1113,7 +1099,7 @@ where .into_iter() .filter(|&config| { let mut min_swap_interval = 0; - let res = egl.GetConfigAttrib( + let _res = egl.GetConfigAttrib( display, config, ffi::egl::MIN_SWAP_INTERVAL as ffi::egl::types::EGLint, @@ -1125,7 +1111,7 @@ where } let mut max_swap_interval = 0; - let res = egl.GetConfigAttrib( + let _res = egl.GetConfigAttrib( display, config, ffi::egl::MAX_SWAP_INTERVAL as ffi::egl::types::EGLint, @@ -1201,7 +1187,7 @@ unsafe fn create_context( let mut context_attributes = Vec::with_capacity(10); let mut flags = 0; - if egl_version >= &(1, 5) || extensions.iter().any(|s| &s == &"EGL_KHR_create_context") { + if egl_version >= &(1, 5) || extensions.iter().any(|s| s == "EGL_KHR_create_context") { context_attributes.push(ffi::egl::CONTEXT_MAJOR_VERSION as i32); context_attributes.push(version.0 as i32); context_attributes.push(ffi::egl::CONTEXT_MINOR_VERSION as i32); @@ -1209,13 +1195,13 @@ unsafe fn create_context( // handling robustness let supports_robustness = egl_version >= &(1, 5) - || extensions.iter().any(|s| &s == &"EGL_EXT_create_context_robustness"); + || extensions.iter().any(|s| s == "EGL_EXT_create_context_robustness"); match gl_robustness { Robustness::NotRobust => (), Robustness::NoError => { - if extensions.iter().any(|s| &s == &"EGL_KHR_create_context_no_error") { + if extensions.iter().any(|s| s == "EGL_KHR_create_context_no_error") { context_attributes.push(ffi::egl::CONTEXT_OPENGL_NO_ERROR_KHR as raw::c_int); context_attributes.push(1); } @@ -1265,6 +1251,13 @@ unsafe fn create_context( if gl_debug && egl_version >= &(1, 5) { context_attributes.push(ffi::egl::CONTEXT_OPENGL_DEBUG as i32); context_attributes.push(ffi::egl::TRUE as i32); + + // TODO: using this flag sometimes generates an error + // there was a change in the specs that added this flag, so it + // may not be supported everywhere ; however it is + // not possible to know whether it is supported or + // not flags = flags | + // ffi::egl::CONTEXT_OPENGL_DEBUG_BIT_KHR as i32; } // In at least some configurations, the Android emulator’s GL diff --git a/glutin/src/api/glx/make_current_guard.rs b/glutin/src/api/glx/make_current_guard.rs index 67366b63a3b..5885a49d2a5 100644 --- a/glutin/src/api/glx/make_current_guard.rs +++ b/glutin/src/api/glx/make_current_guard.rs @@ -66,10 +66,7 @@ impl Drop for MakeCurrentGuard { None => (0, std::ptr::null()), }; - let display = match self.old_display { - old_display if old_display == std::ptr::null_mut() => self.display, - old_display => old_display, - }; + let display = if self.old_display.is_null() { self.display } else { self.old_display }; let res = unsafe { glx.MakeCurrent(display as *mut _, drawable, context) }; diff --git a/glutin/src/api/glx/mod.rs b/glutin/src/api/glx/mod.rs index 713d50c490b..232f9d2602b 100644 --- a/glutin/src/api/glx/mod.rs +++ b/glutin/src/api/glx/mod.rs @@ -8,65 +8,61 @@ #![cfg(feature = "x11")] mod make_current_guard; -mod glx { - use crate::api::dlloader::{SymTrait, SymWrapper}; - use glutin_glx_sys as ffi; - use std::ops::{Deref, DerefMut}; - - #[derive(Clone)] - pub struct Glx(SymWrapper); - - /// Because `*const raw::c_void` doesn't implement `Sync`. - unsafe impl Sync for Glx {} - - impl SymTrait for ffi::glx::Glx { - fn load_with(lib: &libloading::Library) -> Self { - Self::load_with(|sym| unsafe { - lib.get(std::ffi::CString::new(sym.as_bytes()).unwrap().as_bytes_with_nul()) - .map(|sym| *sym) - .unwrap_or(std::ptr::null_mut()) - }) - } - } - impl Glx { - pub fn new() -> Result { - let paths = vec!["libGL.so.1", "libGL.so"]; +use std::ffi::{CStr, CString}; +use std::ops::{Deref, DerefMut}; +use std::os::raw; +use std::sync::Arc; + +use glutin_glx_sys as ffi; +use winit::dpi; - SymWrapper::new(paths).map(Glx) - } - } +use self::make_current_guard::MakeCurrentGuard; +use crate::api::dlloader::{SymTrait, SymWrapper}; +use crate::platform::unix::x11::XConnection; +use crate::platform_impl::x11_utils::SurfaceType; +use crate::{ + Api, ContextError, CreationError, GlAttributes, GlProfile, GlRequest, PixelFormat, + PixelFormatRequirements, ReleaseBehavior, Robustness, +}; - impl Deref for Glx { - type Target = ffi::glx::Glx; +#[derive(Clone)] +pub struct Glx(SymWrapper); - fn deref(&self) -> &ffi::glx::Glx { - &self.0 - } +/// Because `*const raw::c_void` doesn't implement `Sync`. +unsafe impl Sync for Glx {} + +impl SymTrait for ffi::glx::Glx { + fn load_with(lib: &libloading::Library) -> Self { + Self::load_with(|sym| unsafe { + lib.get(std::ffi::CString::new(sym.as_bytes()).unwrap().as_bytes_with_nul()) + .map(|sym| *sym) + .unwrap_or(std::ptr::null_mut()) + }) } +} - impl DerefMut for Glx { - fn deref_mut(&mut self) -> &mut ffi::glx::Glx { - &mut self.0 - } +impl Glx { + pub fn new() -> Result { + let paths = vec!["libGL.so.1", "libGL.so"]; + + SymWrapper::new(paths).map(Glx) } } -pub use self::glx::Glx; -use self::make_current_guard::MakeCurrentGuard; -use crate::{ - Api, ContextError, CreationError, GlAttributes, GlProfile, GlRequest, PixelFormat, - PixelFormatRequirements, ReleaseBehavior, Robustness, -}; +impl Deref for Glx { + type Target = ffi::glx::Glx; -use crate::platform::unix::x11::XConnection; -use crate::platform_impl::x11_utils::SurfaceType; -use glutin_glx_sys as ffi; -use winit::dpi; + fn deref(&self) -> &ffi::glx::Glx { + &self.0 + } +} -use std::ffi::{CStr, CString}; -use std::os::raw; -use std::sync::Arc; +impl DerefMut for Glx { + fn deref_mut(&mut self) -> &mut ffi::glx::Glx { + &mut self.0 + } +} lazy_static! { pub static ref GLX: Option = Glx::new().ok(); @@ -81,7 +77,8 @@ pub struct Context { } impl Context { - // transparent is `None` if window is raw. + // transparent is [`None`] if window is raw. + #[allow(clippy::new_ret_no_self)] pub fn new<'a>( xconn: Arc, pf_reqs: &PixelFormatRequirements, @@ -223,7 +220,7 @@ impl Drop for Context { .unwrap(); let gl_finish_fn = self.get_proc_address("glFinish"); - assert!(gl_finish_fn != std::ptr::null()); + assert!(!gl_finish_fn.is_null()); let gl_finish_fn = std::mem::transmute::<_, extern "system" fn()>(gl_finish_fn); gl_finish_fn(); diff --git a/glutin/src/api/ios/mod.rs b/glutin/src/api/ios/mod.rs index 12668fed496..593a172e6f8 100644 --- a/glutin/src/api/ios/mod.rs +++ b/glutin/src/api/ios/mod.rs @@ -385,7 +385,6 @@ impl Context { let proc_name_c = CString::new(proc_name).expect("proc name contained interior nul byte"); let path = b"/System/Library/Frameworks/OpenGLES.framework/OpenGLES\0"; - // debug!("proc {} -> {:?}", proc_name, addr); unsafe { let lib = ffi::dlopen(path.as_ptr() as *const raw::c_char, ffi::RTLD_LAZY | ffi::RTLD_GLOBAL); diff --git a/glutin/src/lib.rs b/glutin/src/lib.rs index 1ac4d8c96dc..fa447cf928b 100644 --- a/glutin/src/lib.rs +++ b/glutin/src/lib.rs @@ -65,10 +65,8 @@ [`RawContextExt`]: os/unix/trait.RawContextExt.html " )] -#![deny( - missing_debug_implementations, - //missing_docs, -)] +#![deny(missing_debug_implementations)] +#![allow(clippy::missing_safety_doc, clippy::too_many_arguments)] #[cfg(any( target_os = "windows", @@ -117,13 +115,16 @@ pub struct ContextBuilder<'a, T: ContextCurrentState> { pub pf_reqs: PixelFormatRequirements, } +impl Default for ContextBuilder<'_, NotCurrent> { + fn default() -> Self { + Self { gl_attr: Default::default(), pf_reqs: Default::default() } + } +} + impl<'a> ContextBuilder<'a, NotCurrent> { /// Initializes a new `ContextBuilder` with default values. pub fn new() -> Self { - ContextBuilder { - pf_reqs: std::default::Default::default(), - gl_attr: std::default::Default::default(), - } + Default::default() } } @@ -440,10 +441,10 @@ pub enum GlRequest { impl GlRequest { /// Extract the desktop GL version, if any. - pub fn to_gl_version(&self) -> Option<(u8, u8)> { + pub fn to_gl_version(self) -> Option<(u8, u8)> { match self { - &GlRequest::Specific(Api::OpenGl, opengl_version) => Some(opengl_version), - &GlRequest::GlThenGles { opengl_version, .. } => Some(opengl_version), + GlRequest::Specific(Api::OpenGl, opengl_version) => Some(opengl_version), + GlRequest::GlThenGles { opengl_version, .. } => Some(opengl_version), _ => None, } } @@ -584,8 +585,9 @@ pub struct PixelFormatRequirements { /// The behavior when changing the current context. Default is `Flush`. pub release_behavior: ReleaseBehavior, - /// X11 only: set internally to insure a certain visual xid is used when + /// X11 only: set internally to ensure a certain visual xid is used when /// choosing the fbconfig. + #[allow(dead_code)] pub(crate) x11_visual_xid: Option, } diff --git a/glutin/src/platform_impl/macos/helpers.rs b/glutin/src/platform_impl/macos/helpers.rs index d247df4146f..26c01c48a69 100644 --- a/glutin/src/platform_impl/macos/helpers.rs +++ b/glutin/src/platform_impl/macos/helpers.rs @@ -1,3 +1,5 @@ +use std::cmp::Ordering; + use crate::{ CreationError, GlAttributes, GlProfile, GlRequest, PixelFormatRequirements, ReleaseBehavior, }; @@ -21,16 +23,16 @@ pub fn get_gl_profile( } } else if let Some(v) = version { // second, process exact requested version, if any - if v < (3, 2) { - if opengl.profile.is_none() && v <= (2, 1) { - Ok(NSOpenGLProfileVersionLegacy) - } else { - Err(CreationError::OpenGlVersionNotSupported) + match v.cmp(&(3, 2)) { + Ordering::Less => { + if opengl.profile.is_none() && v <= (2, 1) { + Ok(NSOpenGLProfileVersionLegacy) + } else { + Err(CreationError::OpenGlVersionNotSupported) + } } - } else if v == (3, 2) { - Ok(NSOpenGLProfileVersion3_2Core) - } else { - Ok(NSOpenGLProfileVersion4_1Core) + Ordering::Equal => Ok(NSOpenGLProfileVersion3_2Core), + Ordering::Greater => Ok(NSOpenGLProfileVersion4_1Core), } } else if let GlRequest::Latest = opengl.version { // now, find the latest supported version automatically; diff --git a/glutin/src/platform_impl/macos/mod.rs b/glutin/src/platform_impl/macos/mod.rs index bf072f1be32..3d12e35fd1a 100644 --- a/glutin/src/platform_impl/macos/mod.rs +++ b/glutin/src/platform_impl/macos/mod.rs @@ -126,11 +126,11 @@ impl Context { ); if transparent { - let mut opacity = 0; + let opacity = 0; CGLSetParameter( gl_context.CGLContextObj() as *mut _, kCGLCPSurfaceOpacity, - &mut opacity, + &opacity, ); } @@ -339,7 +339,7 @@ impl Drop for IdRef { impl Deref for IdRef { type Target = id; - fn deref<'a>(&'a self) -> &'a id { + fn deref(&self) -> &id { &self.0 } } diff --git a/glutin/src/platform_impl/mod.rs b/glutin/src/platform_impl/mod.rs index 82affa737de..4ad50fc5c85 100644 --- a/glutin/src/platform_impl/mod.rs +++ b/glutin/src/platform_impl/mod.rs @@ -1,8 +1,8 @@ -pub use self::platform_impl::*; +pub use self::platform::*; #[cfg(target_os = "windows")] #[path = "windows/mod.rs"] -mod platform_impl; +mod platform; #[cfg(any( target_os = "linux", target_os = "dragonfly", @@ -11,16 +11,16 @@ mod platform_impl; target_os = "openbsd", ))] #[path = "unix/mod.rs"] -mod platform_impl; +mod platform; #[cfg(target_os = "macos")] #[path = "macos/mod.rs"] -mod platform_impl; +mod platform; #[cfg(target_os = "android")] #[path = "android/mod.rs"] -mod platform_impl; +mod platform; #[cfg(target_os = "ios")] #[path = "ios/mod.rs"] -mod platform_impl; +mod platform; #[cfg(target_os = "emscripten")] #[path = "emscripten/mod.rs"] -mod platform_impl; +mod platform; diff --git a/glutin/src/platform_impl/unix/x11.rs b/glutin/src/platform_impl/unix/x11.rs index 51ce7ca741e..171a231ce8a 100644 --- a/glutin/src/platform_impl/unix/x11.rs +++ b/glutin/src/platform_impl/unix/x11.rs @@ -134,10 +134,10 @@ where // Stick with the earlier. (Some(Err(Lacks::Transparency)), Err(Lacks::Transparency)) => (), - (Some(Err(_)), Err(Lacks::XID)) => (), + (Some(Err(_)), Err(Lacks::Xid)) => (), // Lacking transparency is better than lacking the xid. - (Some(Err(Lacks::XID)), Err(Lacks::Transparency)) => { + (Some(Err(Lacks::Xid)), Err(Lacks::Transparency)) => { chosen_config_id = Some((config_id, visual_infos)); lacks_what = Some(this_lacks_what); } @@ -149,7 +149,7 @@ where Some(Err(Lacks::Transparency)) => log::warn!( "Glutin could not a find fb config with an alpha mask. Transparency may be broken." ), - Some(Err(Lacks::XID)) => panic!(), + Some(Err(Lacks::Xid)) => panic!(), None => unreachable!(), } @@ -375,14 +375,14 @@ impl Context { // If the preferred choice works, don't spend time testing // if the other works. if prefer_egl { - if let Some(_) = &*EGL { + if EGL.is_some() { return egl(builder_egl_u); - } else if let Some(_) = &*GLX { + } else if GLX.is_some() { return glx(builder_glx_u); } - } else if let Some(_) = &*GLX { + } else if GLX.is_some() { return glx(builder_glx_u); - } else if let Some(_) = &*EGL { + } else if EGL.is_some() { return egl(builder_egl_u); } @@ -391,10 +391,10 @@ impl Context { )); } else { if prefer_egl { - if let Some(_) = &*EGL { + if EGL.is_some() { return egl(builder_egl_u); } - } else if let Some(_) = &*GLX { + } else if GLX.is_some() { return glx(builder_glx_u); } @@ -404,7 +404,7 @@ impl Context { } } GlRequest::Specific(Api::OpenGlEs, _) => { - if let Some(_) = *EGL { + if EGL.is_some() { let builder = gl_attr.clone(); *builder_egl_u = Some(builder.map_sharing(|c| match c.context { X11Context::Egl(ref c) => c, diff --git a/glutin/src/platform_impl/unix/x11/utils.rs b/glutin/src/platform_impl/unix/x11/utils.rs index 40eeeb43a95..6fd7e2991c7 100644 --- a/glutin/src/platform_impl/unix/x11/utils.rs +++ b/glutin/src/platform_impl/unix/x11/utils.rs @@ -31,7 +31,7 @@ pub fn get_visual_info_from_xid(xconn: &Arc, xid: ffi::VisualID) -> #[derive(Clone, Copy, Debug)] pub enum Lacks { Transparency, - XID, + Xid, } /// Should always check for lack of xid before lack of transparency. @@ -43,7 +43,7 @@ pub fn examine_visual_info( ) -> Result<(), Lacks> { if let Some(want_xid) = want_xid { if visual_infos.visualid != want_xid { - return Err(Lacks::XID); + return Err(Lacks::Xid); } } diff --git a/glutin_egl_sys/src/lib.rs b/glutin_egl_sys/src/lib.rs index fac07d26f8d..b34af96edac 100644 --- a/glutin_egl_sys/src/lib.rs +++ b/glutin_egl_sys/src/lib.rs @@ -7,7 +7,12 @@ target_os = "netbsd", target_os = "openbsd" ))] -#![allow(non_camel_case_types)] +#![allow( + clippy::manual_non_exhaustive, + clippy::missing_safety_doc, + clippy::unnecessary_cast, + non_camel_case_types +)] pub mod egl { pub type khronos_utime_nanoseconds_t = super::khronos_utime_nanoseconds_t; diff --git a/glutin_examples/examples/fullscreen.rs b/glutin_examples/examples/fullscreen.rs index c0210b54ca1..7fcaac00aab 100644 --- a/glutin_examples/examples/fullscreen.rs +++ b/glutin_examples/examples/fullscreen.rs @@ -14,7 +14,7 @@ fn main() { let mut num = String::new(); stdin().read_line(&mut num).unwrap(); - let num = num.trim().parse().ok().expect("Please enter a number"); + let num = num.trim().parse().expect("Please enter a number"); let fullscreen = Some(match num { 1 => Fullscreen::Exclusive(prompt_for_video_mode(&prompt_for_monitor(&el))), @@ -90,7 +90,7 @@ fn prompt_for_monitor(el: &EventLoop<()>) -> MonitorHandle { let mut num = String::new(); stdin().read_line(&mut num).unwrap(); - let num = num.trim().parse().ok().expect("Please enter a number"); + let num = num.trim().parse().expect("Please enter a number"); let monitor = el.available_monitors().nth(num).expect("Please enter a valid ID"); println!("Using {:?}", monitor.name()); @@ -108,7 +108,7 @@ fn prompt_for_video_mode(monitor: &MonitorHandle) -> VideoMode { let mut num = String::new(); stdin().read_line(&mut num).unwrap(); - let num = num.trim().parse().ok().expect("Please enter a number"); + let num = num.trim().parse().expect("Please enter a number"); let video_mode = monitor.video_modes().nth(num).expect("Please enter a valid ID"); println!("Using {}", video_mode); diff --git a/glutin_examples/examples/sharing.rs b/glutin_examples/examples/sharing.rs index f87600d85e8..c830aa165a7 100644 --- a/glutin_examples/examples/sharing.rs +++ b/glutin_examples/examples/sharing.rs @@ -61,7 +61,6 @@ fn main() { glw.gl.BindFramebuffer(gl::DRAW_FRAMEBUFFER, 0); glw.gl.Viewport(0, 0, size.width as _, size.height as _); } - std::mem::drop(windowed_context); let headless_context = ct.get_current(headless_id).unwrap(); let glc = support::load(headless_context.headless()); @@ -81,7 +80,6 @@ fn main() { ); glc.gl.Viewport(0, 0, size.width as _, size.height as _); } - std::mem::drop(headless_context); el.run(move |event, _, control_flow| { println!("{:?}", event); @@ -89,10 +87,9 @@ fn main() { match event { Event::LoopDestroyed => unsafe { - let windowed_context = ct.get_current(windowed_id).unwrap(); + let _ = ct.get_current(windowed_id).unwrap(); glw.gl.DeleteFramebuffers(1, &window_fb); glw.gl.DeleteRenderbuffers(1, &render_buf); - std::mem::drop(windowed_context); let _ = ct.get_current(headless_id).unwrap(); glc.gl.DeleteFramebuffers(1, &context_fb); }, @@ -110,7 +107,6 @@ fn main() { size.height as _, ); glw.gl.Viewport(0, 0, size.width as _, size.height as _); - std::mem::drop(windowed_context); let _ = ct.get_current(headless_id).unwrap(); glc.gl.Viewport(0, 0, size.width as _, size.height as _); @@ -120,9 +116,8 @@ fn main() { _ => (), }, Event::RedrawRequested(_) => { - let headless_context = ct.get_current(headless_id).unwrap(); + let _ = ct.get_current(headless_id).unwrap(); glc.draw_frame([1.0, 0.5, 0.7, 1.0]); - std::mem::drop(headless_context); let windowed_context = ct.get_current(windowed_id).unwrap(); unsafe { diff --git a/glutin_examples/examples/support/mod.rs b/glutin_examples/examples/support/mod.rs index a14092ac957..4e283255bdd 100644 --- a/glutin_examples/examples/support/mod.rs +++ b/glutin_examples/examples/support/mod.rs @@ -3,6 +3,14 @@ use glutin::{self, PossiblyCurrent}; use std::ffi::CStr; pub mod gl { + #![allow( + clippy::manual_non_exhaustive, + clippy::too_many_arguments, + clippy::unused_unit, + clippy::upper_case_acronyms, + non_camel_case_types + )] + pub use self::Gles2 as Gl; include!(concat!(env!("OUT_DIR"), "/gl_bindings.rs")); } diff --git a/glutin_gles2_sys/src/lib.rs b/glutin_gles2_sys/src/lib.rs index 4a13fa65970..ee683e97fbe 100644 --- a/glutin_gles2_sys/src/lib.rs +++ b/glutin_gles2_sys/src/lib.rs @@ -1,5 +1,12 @@ #![cfg(target_os = "ios")] -#![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)] +#![allow( + clippy::missing_safety_doc, + clippy::too_many_arguments, + clippy::unused_unit, + non_camel_case_types, + non_snake_case, + non_upper_case_globals +)] pub mod gles { include!(concat!(env!("OUT_DIR"), "/gles2_bindings.rs")); diff --git a/glutin_glx_sys/src/lib.rs b/glutin_glx_sys/src/lib.rs index fadb62a0fa0..b411bacfbf5 100644 --- a/glutin_glx_sys/src/lib.rs +++ b/glutin_glx_sys/src/lib.rs @@ -5,6 +5,12 @@ target_os = "netbsd", target_os = "openbsd" ))] +#![allow( + clippy::manual_non_exhaustive, + clippy::missing_safety_doc, + clippy::redundant_static_lifetimes, + clippy::unused_unit +)] pub use self::glx::types::GLXContext; pub use x11_dl::xlib::*; diff --git a/glutin_wgl_sys/src/lib.rs b/glutin_wgl_sys/src/lib.rs index 42cdd5688dc..3686c496078 100644 --- a/glutin_wgl_sys/src/lib.rs +++ b/glutin_wgl_sys/src/lib.rs @@ -1,4 +1,5 @@ #![cfg(any(target_os = "windows"))] +#![allow(clippy::manual_non_exhaustive, clippy::missing_safety_doc, clippy::too_many_arguments)] /// WGL bindings pub mod wgl {