From e7e99235bf49d0b56d6ba29bf5353d1bacb5d354 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/mod.rs | 161 +++++++++++----------- glutin/src/api/glx/make_current_guard.rs | 5 +- glutin/src/api/glx/mod.rs | 72 +++++----- glutin/src/lib.rs | 23 ++-- 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 | 14 +- glutin_egl_sys/src/lib.rs | 7 +- glutin_examples/examples/fullscreen.rs | 6 +- glutin_examples/examples/sharing.rs | 5 - glutin_examples/examples/support/mod.rs | 8 ++ glutin_glx_sys/src/lib.rs | 6 + glutin_wgl_sys/src/lib.rs | 1 + 15 files changed, 180 insertions(+), 175 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/mod.rs b/glutin/src/api/egl/mod.rs index 5c530d91d0c..9e77beb1bcd 100644 --- a/glutin/src/api/egl/mod.rs +++ b/glutin/src/api/egl/mod.rs @@ -7,91 +7,85 @@ 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 crate::api::dlloader::{SymTrait, SymWrapper}; +use libloading; +use std::sync::{Arc, Mutex}; - #[cfg(unix)] - use libloading::os::unix as libloading_os; - #[cfg(windows)] - use libloading::os::windows as libloading_os; +#[cfg(unix)] +use libloading::os::unix as libloading_os; +#[cfg(windows)] +use libloading::os::windows as libloading_os; - #[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; @@ -101,7 +95,6 @@ use crate::{ }; use glutin_egl_sys as ffi; -use parking_lot::Mutex; #[cfg(any( target_os = "android", target_os = "windows", @@ -158,7 +151,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, #[cfg(target_os = "android")] @@ -251,7 +244,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 @@ -378,8 +371,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>, @@ -683,7 +676,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(); @@ -831,7 +824,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) @@ -851,11 +844,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, @@ -984,7 +972,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, #[cfg(target_os = "android")] @@ -1163,7 +1151,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, @@ -1175,7 +1163,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, @@ -1251,7 +1239,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); @@ -1259,13 +1247,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); } @@ -1315,6 +1303,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 7fcfbb4cc1f..6535e6ad72e 100644 --- a/glutin/src/api/glx/mod.rs +++ b/glutin/src/api/glx/mod.rs @@ -8,51 +8,49 @@ #![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()) - }) - } + +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"]; +impl Glx { + pub fn new() -> Result { + let paths = vec!["libGL.so.1", "libGL.so"]; - SymWrapper::new(paths).map(Glx) - } + SymWrapper::new(paths).map(Glx) } +} - impl Deref for Glx { - type Target = ffi::glx::Glx; +impl Deref for Glx { + type Target = ffi::glx::Glx; - fn deref(&self) -> &ffi::glx::Glx { - &self.0 - } + fn deref(&self) -> &ffi::glx::Glx { + &self.0 } +} - impl DerefMut for Glx { - fn deref_mut(&mut self) -> &mut ffi::glx::Glx { - &mut self.0 - } +impl DerefMut for Glx { + fn deref_mut(&mut self) -> &mut ffi::glx::Glx { + &mut self.0 } } -pub use self::glx::Glx; use self::make_current_guard::MakeCurrentGuard; use crate::{ Api, ContextError, CreationError, GlAttributes, GlProfile, GlRequest, PixelFormat, @@ -61,7 +59,6 @@ use crate::{ use crate::platform::unix::x11::XConnection; use crate::platform_impl::x11_utils::SurfaceType; -use glutin_glx_sys as ffi; use winit::dpi; use std::ffi::{CStr, CString}; @@ -81,7 +78,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 +221,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/lib.rs b/glutin/src/lib.rs index 6c54d58f443..d496c9bfdda 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() } } @@ -436,10 +437,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, } } 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..57eb42cf59a 100644 --- a/glutin/src/platform_impl/unix/x11.rs +++ b/glutin/src/platform_impl/unix/x11.rs @@ -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_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..396074ad55a 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); @@ -92,7 +90,6 @@ fn main() { let windowed_context = 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 _); @@ -122,7 +118,6 @@ fn main() { Event::RedrawRequested(_) => { let headless_context = 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_glx_sys/src/lib.rs b/glutin_glx_sys/src/lib.rs index fadb62a0fa0..bdc0d8c25e8 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::unused_unit, + clippy::redundant_static_lifetimes +)] 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..8b0d74de451 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::too_many_arguments, clippy::missing_safety_doc)] /// WGL bindings pub mod wgl {