diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fe81bafcb3..0237e0a0f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,8 @@ on: - '.github/workflows/ci.yml' jobs: - Check_Formatting: + check-formatting: + name: Check formatting runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 @@ -25,7 +26,8 @@ jobs: - name: Check Formatting run: cargo +stable fmt --all -- --check - Tests: + tests: + name: Tests strategy: fail-fast: false matrix: @@ -70,6 +72,7 @@ jobs: with: rust-version: ${{ matrix.rust_version }}${{ matrix.platform.host }} targets: ${{ matrix.platform.target }} + components: clippy - name: Install GCC Multilib if: (matrix.platform.os == 'ubuntu-latest') && contains(matrix.platform.target, 'i686') @@ -84,6 +87,11 @@ jobs: if: matrix.platform.target != 'wasm32-unknown-unknown' run: cd glutin && cargo doc --no-deps --target ${{ matrix.platform.target }} $OPTIONS --features $FEATURES --document-private-items + - name: Lint with clippy + shell: bash + if: matrix.rust_version != 'nightly' + run: cargo clippy --workspace --all-targets --target ${{ matrix.platform.target }} $OPTIONS --features $FEATURES -- -Dwarnings + - name: Build glutin shell: bash run: cd glutin && cargo $WEB build --verbose --target ${{ matrix.platform.target }} $OPTIONS --features $FEATURES @@ -104,7 +112,6 @@ jobs: if: (!contains(matrix.platform.target, 'ios') && !contains(matrix.platform.target, 'wasm32')) run: cd glutin && cargo $WEB test --verbose --target ${{ matrix.platform.target }} $OPTIONS --features $FEATURES - - name: Build with serde enabled shell: bash run: cd glutin && cargo $WEB build --verbose --target ${{ matrix.platform.target }} $OPTIONS --features serde,$FEATURES diff --git a/glutin/src/api/dlloader.rs b/glutin/src/api/dlloader.rs index fa35b03412..40bbb414e2 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 06911900b8..ae078bd8e4 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 fad3fb8912..34a6e1138b 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(|i| Egl(i)) - } + 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, } @@ -199,10 +190,8 @@ unsafe fn bind_and_get_api<'a>( } } GlRequest::Specific(Api::OpenGlEs, version) => { - if egl_version >= (1, 2) { - if egl.BindAPI(ffi::egl::OPENGL_ES_API) == 0 { - return Err(CreationError::OpenGlVersionNotSupported); - } + if egl_version >= (1, 2) && egl.BindAPI(ffi::egl::OPENGL_ES_API) == 0 { + return Err(CreationError::OpenGlVersionNotSupported); } Ok((Some(version), Api::OpenGlEs)) } @@ -246,12 +235,12 @@ fn get_native_display(native_display: &NativeDisplay) -> *const raw::c_void { vec![] } else { let p = CStr::from_ptr(p); - let list = String::from_utf8(p.to_bytes().to_vec()).unwrap_or_else(|_| format!("")); + let list = String::from_utf8(p.to_bytes().to_vec()).unwrap_or_default(); list.split(' ').map(|e| e.to_string()).collect::>() } }; - let has_dp_extension = |e: &str| dp_extensions.iter().find(|s| s == &e).is_some(); + let has_dp_extension = |e: &str| dp_extensions.iter().any(|s| s == e); match *native_display { // Note: Some EGL implementations are missing the @@ -366,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, @@ -378,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>, @@ -408,14 +397,14 @@ impl Context { let extensions = if egl_version >= (1, 2) { let p = unsafe { CStr::from_ptr(egl.QueryString(display, ffi::egl::EXTENSIONS as i32)) }; - let list = String::from_utf8(p.to_bytes().to_vec()).unwrap_or_else(|_| format!("")); + let list = String::from_utf8(p.to_bytes().to_vec()).unwrap_or_default(); list.split(' ').map(|e| e.to_string()).collect::>() } else { vec![] }; // binding the right API and choosing the version - let (version, api) = unsafe { bind_and_get_api(&opengl, egl_version)? }; + let (version, api) = unsafe { bind_and_get_api(opengl, egl_version)? }; let (config_id, pixel_format) = unsafe { choose_fbconfig( @@ -529,7 +518,7 @@ impl Context { if ret == 0 { match unsafe { egl.GetError() } as u32 { - ffi::egl::CONTEXT_LOST => return Err(ContextError::ContextLost), + ffi::egl::CONTEXT_LOST => Err(ContextError::ContextLost), err => { panic!("swap_buffers: eglSwapBuffers failed (eglGetError returned 0x{:x})", err) } @@ -573,7 +562,7 @@ impl Context { if ret == ffi::egl::FALSE { match unsafe { egl.GetError() } as u32 { - ffi::egl::CONTEXT_LOST => return Err(ContextError::ContextLost), + ffi::egl::CONTEXT_LOST => Err(ContextError::ContextLost), err => { panic!("swap_buffers: eglSwapBuffers failed (eglGetError returned 0x{:x})", err) } @@ -631,13 +620,13 @@ impl Drop for Context { // to ensure it actually gets destroyed. This requires making the // this context current. let mut guard = MakeCurrentGuard::new(self.display, surface, surface, self.context) - .map_err(|err| ContextError::OsError(err)) + .map_err(ContextError::OsError) .unwrap(); 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(); @@ -785,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().find(|s| s == &"EGL_KHR_surfaceless_context").is_none() { + 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) @@ -805,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, @@ -879,46 +863,44 @@ impl<'a> ContextPrototype<'a> { } else { return Err(CreationError::OpenGlVersionNotSupported); } + } else if let Ok(ctx) = create_context( + self.display, + &self.egl_version, + &self.extensions, + self.api, + (3, 2), + self.config_id, + self.opengl.debug, + self.opengl.robustness, + share, + ) { + ctx + } else if let Ok(ctx) = create_context( + self.display, + &self.egl_version, + &self.extensions, + self.api, + (3, 1), + self.config_id, + self.opengl.debug, + self.opengl.robustness, + share, + ) { + ctx + } else if let Ok(ctx) = create_context( + self.display, + &self.egl_version, + &self.extensions, + self.api, + (1, 0), + self.config_id, + self.opengl.debug, + self.opengl.robustness, + share, + ) { + ctx } else { - if let Ok(ctx) = create_context( - self.display, - &self.egl_version, - &self.extensions, - self.api, - (3, 2), - self.config_id, - self.opengl.debug, - self.opengl.robustness, - share, - ) { - ctx - } else if let Ok(ctx) = create_context( - self.display, - &self.egl_version, - &self.extensions, - self.api, - (3, 1), - self.config_id, - self.opengl.debug, - self.opengl.robustness, - share, - ) { - ctx - } else if let Ok(ctx) = create_context( - self.display, - &self.egl_version, - &self.extensions, - self.api, - (1, 0), - self.config_id, - self.opengl.debug, - self.opengl.robustness, - share, - ) { - ctx - } else { - return Err(CreationError::OpenGlVersionNotSupported); - } + return Err(CreationError::OpenGlVersionNotSupported); } }; @@ -926,7 +908,7 @@ impl<'a> ContextPrototype<'a> { // VSync defaults to enabled; disable it if it was not requested. if !self.opengl.vsync { let _guard = MakeCurrentGuard::new(self.display, surface, surface, context) - .map_err(|err| CreationError::OsError(err))?; + .map_err(CreationError::OsError)?; let egl = EGL.as_ref().unwrap(); unsafe { @@ -940,7 +922,7 @@ impl<'a> ContextPrototype<'a> { Ok(Context { display: self.display, context, - surface: surface.map(|s| Mutex::new(s)), + surface: surface.map(parking_lot::Mutex::new), api: self.api, pixel_format: self.pixel_format, }) @@ -1117,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, @@ -1129,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, @@ -1205,9 +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().find(|s| s == &"EGL_KHR_create_context").is_some() - { + 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); @@ -1215,13 +1195,13 @@ unsafe fn create_context( // handling robustness let supports_robustness = egl_version >= &(1, 5) - || extensions.iter().find(|s| s == &"EGL_EXT_create_context_robustness").is_some(); + || extensions.iter().any(|s| s == "EGL_EXT_create_context_robustness"); match gl_robustness { Robustness::NotRobust => (), Robustness::NoError => { - if extensions.iter().find(|s| s == &"EGL_KHR_create_context_no_error").is_some() { + 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); } @@ -1232,7 +1212,7 @@ unsafe fn create_context( context_attributes .push(ffi::egl::CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY as raw::c_int); context_attributes.push(ffi::egl::NO_RESET_NOTIFICATION as raw::c_int); - flags = flags | ffi::egl::CONTEXT_OPENGL_ROBUST_ACCESS as raw::c_int; + flags |= ffi::egl::CONTEXT_OPENGL_ROBUST_ACCESS as raw::c_int; } else { return Err(CreationError::RobustnessNotSupported); } @@ -1243,7 +1223,7 @@ unsafe fn create_context( context_attributes .push(ffi::egl::CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY as raw::c_int); context_attributes.push(ffi::egl::NO_RESET_NOTIFICATION as raw::c_int); - flags = flags | ffi::egl::CONTEXT_OPENGL_ROBUST_ACCESS as raw::c_int; + flags |= ffi::egl::CONTEXT_OPENGL_ROBUST_ACCESS as raw::c_int; } } @@ -1252,7 +1232,7 @@ unsafe fn create_context( context_attributes .push(ffi::egl::CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY as raw::c_int); context_attributes.push(ffi::egl::LOSE_CONTEXT_ON_RESET as raw::c_int); - flags = flags | ffi::egl::CONTEXT_OPENGL_ROBUST_ACCESS as raw::c_int; + flags |= ffi::egl::CONTEXT_OPENGL_ROBUST_ACCESS as raw::c_int; } else { return Err(CreationError::RobustnessNotSupported); } @@ -1263,16 +1243,14 @@ unsafe fn create_context( context_attributes .push(ffi::egl::CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY as raw::c_int); context_attributes.push(ffi::egl::LOSE_CONTEXT_ON_RESET as raw::c_int); - flags = flags | ffi::egl::CONTEXT_OPENGL_ROBUST_ACCESS as raw::c_int; + flags |= ffi::egl::CONTEXT_OPENGL_ROBUST_ACCESS as raw::c_int; } } } - if gl_debug { - if egl_version >= &(1, 5) { - context_attributes.push(ffi::egl::CONTEXT_OPENGL_DEBUG as i32); - context_attributes.push(ffi::egl::TRUE as i32); - } + 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 diff --git a/glutin/src/api/glx/make_current_guard.rs b/glutin/src/api/glx/make_current_guard.rs index 67366b63a3..5885a49d2a 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 3367b7bb96..232f9d2602 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(|i| Glx(i)) - } - } +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, @@ -219,11 +216,11 @@ impl Drop for Context { unsafe { // See `drop` for `crate::api::egl::Context` for rationale. let mut guard = MakeCurrentGuard::new(&self.xconn, self.drawable, self.context) - .map_err(|err| ContextError::OsError(err)) + .map_err(ContextError::OsError) .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(); @@ -385,8 +382,8 @@ impl<'a> ContextPrototype<'a> { // vsync let swap_mode = if self.opengl.vsync { 1 } else { 0 }; - let _guard = MakeCurrentGuard::new(&self.xconn, window, context) - .map_err(|err| CreationError::OsError(err))?; + let _guard = + MakeCurrentGuard::new(&self.xconn, window, context).map_err(CreationError::OsError)?; if check_ext(&self.extensions, "GLX_EXT_swap_control") && extra_functions.SwapIntervalEXT.is_loaded() @@ -493,8 +490,7 @@ fn create_context( ); attributes .push(ffi::glx_extra::NO_RESET_NOTIFICATION_ARB as raw::c_int); - flags = - flags | ffi::glx_extra::CONTEXT_ROBUST_ACCESS_BIT_ARB as raw::c_int; + flags |= ffi::glx_extra::CONTEXT_ROBUST_ACCESS_BIT_ARB as raw::c_int; } Robustness::RobustLoseContextOnReset | Robustness::TryRobustLoseContextOnReset => { @@ -504,8 +500,7 @@ fn create_context( ); attributes .push(ffi::glx_extra::LOSE_CONTEXT_ON_RESET_ARB as raw::c_int); - flags = - flags | ffi::glx_extra::CONTEXT_ROBUST_ACCESS_BIT_ARB as raw::c_int; + flags |= ffi::glx_extra::CONTEXT_ROBUST_ACCESS_BIT_ARB as raw::c_int; } Robustness::NotRobust => (), Robustness::NoError => (), @@ -521,7 +516,7 @@ fn create_context( } if debug { - flags = flags | ffi::glx_extra::CONTEXT_DEBUG_BIT_ARB as raw::c_int; + flags |= ffi::glx_extra::CONTEXT_DEBUG_BIT_ARB as raw::c_int; } flags @@ -574,7 +569,7 @@ unsafe fn choose_fbconfig( if let Some(xid) = pf_reqs.x11_visual_xid { // getting the visual infos - let fvi = crate::platform_impl::x11_utils::get_visual_info_from_xid(&xconn, xid); + let fvi = crate::platform_impl::x11_utils::get_visual_info_from_xid(xconn, xid); out.push(ffi::glx::X_VISUAL_TYPE as raw::c_int); out.push(fvi.class as raw::c_int); @@ -716,7 +711,7 @@ unsafe fn choose_fbconfig( ) { Ok((config_id, visual_infos)) => { let config = *configs.offset(config_id as isize); - let config = config.clone(); + let config = config; (xconn.xlib.XFree)(configs as *mut _); (config, visual_infos) @@ -760,7 +755,7 @@ unsafe fn choose_fbconfig( /// Checks if `ext` is available. fn check_ext(extensions: &str, ext: &str) -> bool { - extensions.split(' ').find(|&s| s == ext).is_some() + extensions.split(' ').any(|s| s == ext) } fn load_extensions( diff --git a/glutin/src/api/ios/mod.rs b/glutin/src/api/ios/mod.rs index 4bf10ec85f..593a172e6f 100644 --- a/glutin/src/api/ios/mod.rs +++ b/glutin/src/api/ios/mod.rs @@ -155,7 +155,7 @@ pub struct Context { fn validate_version(version: u8) -> Result { let version = version as ffi::NSUInteger; - if version >= ffi::kEAGLRenderingAPIOpenGLES1 && version <= ffi::kEAGLRenderingAPIOpenGLES3 { + if (ffi::kEAGLRenderingAPIOpenGLES1..=ffi::kEAGLRenderingAPIOpenGLES3).contains(&version) { Ok(version) } else { Err(CreationError::OsError(format!( @@ -384,13 +384,12 @@ impl Context { pub fn get_proc_address(&self, proc_name: &str) -> *const core::ffi::c_void { 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"; - let addr = unsafe { + + unsafe { let lib = ffi::dlopen(path.as_ptr() as *const raw::c_char, ffi::RTLD_LAZY | ffi::RTLD_GLOBAL); ffi::dlsym(lib, proc_name_c.as_ptr()) as *const _ - }; - // debug!("proc {} -> {:?}", proc_name, addr); - addr + } } #[inline] diff --git a/glutin/src/api/osmesa/mod.rs b/glutin/src/api/osmesa/mod.rs index 89c07658eb..13035f98ed 100644 --- a/glutin/src/api/osmesa/mod.rs +++ b/glutin/src/api/osmesa/mod.rs @@ -80,7 +80,7 @@ impl OsMesaContext { match opengl.robustness { Robustness::RobustNoResetNotification | Robustness::RobustLoseContextOnReset => { - return Err(CreationError::RobustnessNotSupported.into()); + return Err(CreationError::RobustnessNotSupported); } _ => (), } diff --git a/glutin/src/api/wgl/mod.rs b/glutin/src/api/wgl/mod.rs index 7cd633cdf2..027845efd7 100644 --- a/glutin/src/api/wgl/mod.rs +++ b/glutin/src/api/wgl/mod.rs @@ -102,11 +102,10 @@ impl Context { let data = CStr::from_ptr(data).to_bytes().to_vec(); String::from_utf8(data).unwrap() } else { - format!("") + String::new() }; - let use_arb_for_pixel_format = - extensions.split(' ').find(|&i| i == "WGL_ARB_pixel_format").is_some(); + let use_arb_for_pixel_format = extensions.split(' ').any(|i| i == "WGL_ARB_pixel_format"); // calling SetPixelFormat, if not already done let mut pixel_format_id = GetPixelFormat(hdc); @@ -139,7 +138,7 @@ impl Context { let gl_library = load_opengl32_dll()?; // handling vsync - if extensions.split(' ').find(|&i| i == "WGL_EXT_swap_control").is_some() { + if extensions.split(' ').any(|i| i == "WGL_EXT_swap_control") { let _guard = CurrentContextGuard::make_current(hdc, context.0)?; if extra_functions.SwapIntervalEXT(if opengl.vsync { 1 } else { 0 }) == 0 { @@ -236,7 +235,7 @@ unsafe fn create_context( if let Some((extra_functions, _pf_reqs, opengl, extensions)) = extra { share = opengl.sharing.unwrap_or(std::ptr::null_mut()); - if extensions.split(' ').find(|&i| i == "WGL_ARB_create_context").is_some() { + if extensions.split(' ').any(|i| i == "WGL_ARB_create_context") { let mut attributes = Vec::new(); match opengl.version { @@ -248,11 +247,7 @@ unsafe fn create_context( attributes.push(minor as raw::c_int); } GlRequest::Specific(Api::OpenGlEs, (major, minor)) => { - if extensions - .split(' ') - .find(|&i| i == "WGL_EXT_create_context_es2_profile") - .is_some() - { + if extensions.split(' ').any(|i| i == "WGL_EXT_create_context_es2_profile") { attributes.push(gl::wgl_extra::CONTEXT_PROFILE_MASK_ARB as raw::c_int); attributes.push(gl::wgl_extra::CONTEXT_ES2_PROFILE_BIT_EXT as raw::c_int); } else { @@ -276,8 +271,7 @@ unsafe fn create_context( } if let Some(profile) = opengl.profile { - if extensions.split(' ').find(|&i| i == "WGL_ARB_create_context_profile").is_some() - { + if extensions.split(' ').any(|i| i == "WGL_ARB_create_context_profile") { let flag = match profile { GlProfile::Compatibility => { gl::wgl_extra::CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB @@ -298,11 +292,7 @@ unsafe fn create_context( let mut flags = 0; // robustness - if extensions - .split(' ') - .find(|&i| i == "WGL_ARB_create_context_robustness") - .is_some() - { + if extensions.split(' ').any(|i| i == "WGL_ARB_create_context_robustness") { match opengl.robustness { Robustness::RobustNoResetNotification | Robustness::TryRobustNoResetNotification => { @@ -311,8 +301,7 @@ unsafe fn create_context( as raw::c_int, ); attributes.push(gl::wgl_extra::NO_RESET_NOTIFICATION_ARB as raw::c_int); - flags = - flags | gl::wgl_extra::CONTEXT_ROBUST_ACCESS_BIT_ARB as raw::c_int; + flags |= gl::wgl_extra::CONTEXT_ROBUST_ACCESS_BIT_ARB as raw::c_int; } Robustness::RobustLoseContextOnReset | Robustness::TryRobustLoseContextOnReset => { @@ -321,8 +310,7 @@ unsafe fn create_context( as raw::c_int, ); attributes.push(gl::wgl_extra::LOSE_CONTEXT_ON_RESET_ARB as raw::c_int); - flags = - flags | gl::wgl_extra::CONTEXT_ROBUST_ACCESS_BIT_ARB as raw::c_int; + flags |= gl::wgl_extra::CONTEXT_ROBUST_ACCESS_BIT_ARB as raw::c_int; } Robustness::NotRobust => (), Robustness::NoError => (), @@ -338,7 +326,7 @@ unsafe fn create_context( } if opengl.debug { - flags = flags | gl::wgl_extra::CONTEXT_DEBUG_BIT_ARB as raw::c_int; + flags |= gl::wgl_extra::CONTEXT_DEBUG_BIT_ARB as raw::c_int; } flags @@ -376,13 +364,11 @@ unsafe fn create_context( ))); } - if !share.is_null() { - if gl::wgl::ShareLists(share as *const raw::c_void, ctx) == 0 { - return Err(CreationError::OsError(format!( - "wglShareLists failed: {}", - std::io::Error::last_os_error() - ))); - } + if !share.is_null() && gl::wgl::ShareLists(share as *const raw::c_void, ctx) == 0 { + return Err(CreationError::OsError(format!( + "wglShareLists failed: {}", + std::io::Error::last_os_error() + ))); }; Ok(ContextWrapper(ctx as HGLRC)) @@ -556,7 +542,7 @@ unsafe fn choose_arb_pixel_format_id( out.push(gl::wgl_extra::PIXEL_TYPE_ARB as raw::c_int); if pf_reqs.float_color_buffer { - if extensions.split(' ').find(|&i| i == "WGL_ARB_pixel_format_float").is_some() { + if extensions.split(' ').any(|i| i == "WGL_ARB_pixel_format_float") { out.push(gl::wgl_extra::TYPE_RGBA_FLOAT_ARB as raw::c_int); } else { return Err(()); @@ -601,7 +587,7 @@ unsafe fn choose_arb_pixel_format_id( out.push(if double_buffer { 1 } else { 0 }); if let Some(multisampling) = pf_reqs.multisampling { - if extensions.split(' ').find(|&i| i == "WGL_ARB_multisample").is_some() { + if extensions.split(' ').any(|i| i == "WGL_ARB_multisample") { out.push(gl::wgl_extra::SAMPLE_BUFFERS_ARB as raw::c_int); out.push(if multisampling == 0 { 0 } else { 1 }); out.push(gl::wgl_extra::SAMPLES_ARB as raw::c_int); @@ -616,10 +602,10 @@ unsafe fn choose_arb_pixel_format_id( // WGL_*_FRAMEBUFFER_SRGB might be assumed to be true if not listed; // so it's best to list it out and set its value as necessary. - if extensions.split(' ').find(|&i| i == "WGL_ARB_framebuffer_sRGB").is_some() { + if extensions.split(' ').any(|i| i == "WGL_ARB_framebuffer_sRGB") { out.push(gl::wgl_extra::FRAMEBUFFER_SRGB_CAPABLE_ARB as raw::c_int); out.push(pf_reqs.srgb as raw::c_int); - } else if extensions.split(' ').find(|&i| i == "WGL_EXT_framebuffer_sRGB").is_some() { + } else if extensions.split(' ').any(|i| i == "WGL_EXT_framebuffer_sRGB") { out.push(gl::wgl_extra::FRAMEBUFFER_SRGB_CAPABLE_EXT as raw::c_int); out.push(pf_reqs.srgb as raw::c_int); } else if pf_reqs.srgb { @@ -629,7 +615,7 @@ unsafe fn choose_arb_pixel_format_id( match pf_reqs.release_behavior { ReleaseBehavior::Flush => (), ReleaseBehavior::None => { - if extensions.split(' ').find(|&i| i == "WGL_ARB_context_flush_control").is_some() { + if extensions.split(' ').any(|i| i == "WGL_ARB_context_flush_control") { out.push(gl::wgl_extra::CONTEXT_RELEASE_BEHAVIOR_ARB as raw::c_int); out.push(gl::wgl_extra::CONTEXT_RELEASE_BEHAVIOR_NONE_ARB as raw::c_int); } @@ -692,7 +678,7 @@ unsafe fn choose_arb_pixel_format( stereoscopy: get_info(gl::wgl_extra::STEREO_ARB) != 0, double_buffer: get_info(gl::wgl_extra::DOUBLE_BUFFER_ARB) != 0, multisampling: { - if extensions.split(' ').find(|&i| i == "WGL_ARB_multisample").is_some() { + if extensions.split(' ').any(|i| i == "WGL_ARB_multisample") { match get_info(gl::wgl_extra::SAMPLES_ARB) { 0 => None, a => Some(a as u16), @@ -701,9 +687,9 @@ unsafe fn choose_arb_pixel_format( None } }, - srgb: if extensions.split(' ').find(|&i| i == "WGL_ARB_framebuffer_sRGB").is_some() { + srgb: if extensions.split(' ').any(|i| i == "WGL_ARB_framebuffer_sRGB") { get_info(gl::wgl_extra::FRAMEBUFFER_SRGB_CAPABLE_ARB) != 0 - } else if extensions.split(' ').find(|&i| i == "WGL_EXT_framebuffer_sRGB").is_some() { + } else if extensions.split(' ').any(|i| i == "WGL_EXT_framebuffer_sRGB") { get_info(gl::wgl_extra::FRAMEBUFFER_SRGB_CAPABLE_EXT) != 0 } else { false diff --git a/glutin/src/lib.rs b/glutin/src/lib.rs index 1ac4d8c96d..458c5930ea 100644 --- a/glutin/src/lib.rs +++ b/glutin/src/lib.rs @@ -65,10 +65,9 @@ [`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_attr(feature = "cargo-clippy", deny(warnings))] #[cfg(any( target_os = "windows", @@ -117,13 +116,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 +442,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 +586,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/android/mod.rs b/glutin/src/platform_impl/android/mod.rs index 594914300e..4ecaf668be 100644 --- a/glutin/src/platform_impl/android/mod.rs +++ b/glutin/src/platform_impl/android/mod.rs @@ -48,7 +48,7 @@ impl Context { .and_then(|p| p.finish(nwin))?; let ctx = Arc::new(AndroidContext { egl_context, stopped: Some(Mutex::new(false)) }); - let context = Context(ctx.clone()); + let context = Context(ctx); Ok((win, context)) } diff --git a/glutin/src/platform_impl/macos/helpers.rs b/glutin/src/platform_impl/macos/helpers.rs index d247df4146..26c01c48a6 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 10ae4bd98e..3d12e35fd1 100644 --- a/glutin/src/platform_impl/macos/mod.rs +++ b/glutin/src/platform_impl/macos/mod.rs @@ -14,7 +14,7 @@ use core_foundation::string::CFString; use objc::runtime::{BOOL, NO}; use crate::platform::macos::WindowExtMacOS; -use winit; + use winit::dpi; use winit::event_loop::EventLoopWindowTarget; use winit::window::{Window, WindowBuilder}; @@ -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 a99870e09f..7d6c795393 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,13 +11,13 @@ 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; diff --git a/glutin/src/platform_impl/unix/mod.rs b/glutin/src/platform_impl/unix/mod.rs index 8ed39a4608..e133c2ef89 100644 --- a/glutin/src/platform_impl/unix/mod.rs +++ b/glutin/src/platform_impl/unix/mod.rs @@ -70,7 +70,7 @@ impl Context { Context::OsMesa(_) => Ok(()), _ => { let msg = "Cannot share an OSMesa context with a non-OSMesa context"; - return Err(CreationError::PlatformSpecific(msg.into())); + Err(CreationError::PlatformSpecific(msg.into())) } }, #[cfg(feature = "x11")] @@ -78,7 +78,7 @@ impl Context { Context::X11(_) => Ok(()), _ => { let msg = "Cannot share an X11 context with a non-X11 context"; - return Err(CreationError::PlatformSpecific(msg.into())); + Err(CreationError::PlatformSpecific(msg.into())) } }, #[cfg(feature = "wayland")] @@ -86,7 +86,7 @@ impl Context { Context::Wayland(_) => Ok(()), _ => { let msg = "Cannot share a Wayland context with a non-Wayland context"; - return Err(CreationError::PlatformSpecific(msg.into())); + Err(CreationError::PlatformSpecific(msg.into())) } }, } @@ -149,8 +149,8 @@ impl Context { Context::Wayland(ref ctx) => ctx, _ => unreachable!(), }); - return wayland::Context::new_headless(&el, pf_reqs, &gl_attr, size) - .map(|ctx| Context::Wayland(ctx)); + return wayland::Context::new_headless(el, pf_reqs, &gl_attr, size) + .map(Context::Wayland); } #[cfg(feature = "x11")] if el.is_x11() { @@ -159,8 +159,7 @@ impl Context { Context::X11(ref ctx) => ctx, _ => unreachable!(), }); - return x11::Context::new_headless(&el, pf_reqs, &gl_attr, size) - .map(|ctx| Context::X11(ctx)); + return x11::Context::new_headless(el, pf_reqs, &gl_attr, size).map(Context::X11); } panic!("glutin was not compiled with support for this display server") } @@ -364,7 +363,7 @@ impl<'a, T: ContextCurrentState> HeadlessContextExt for crate::ContextBuilder<'a _ => unreachable!(), }); osmesa::OsMesaContext::new(&pf_reqs, &gl_attr, size) - .map(|context| Context::OsMesa(context)) + .map(Context::OsMesa) .map(|context| crate::Context { context, phantom: PhantomData }) } @@ -441,7 +440,7 @@ impl<'a, T: ContextCurrentState> RawContextExt for crate::ContextBuilder<'a, T> _ => unreachable!(), }); wayland::Context::new_raw_context(display_ptr, surface, width, height, &pf_reqs, &gl_attr) - .map(|context| Context::Wayland(context)) + .map(Context::Wayland) .map(|context| crate::Context { context, phantom: PhantomData }) .map(|context| crate::RawContext { context, window: () }) } @@ -464,7 +463,7 @@ impl<'a, T: ContextCurrentState> RawContextExt for crate::ContextBuilder<'a, T> _ => unreachable!(), }); x11::Context::new_raw_context(xconn, xwin, &pf_reqs, &gl_attr) - .map(|context| Context::X11(context)) + .map(Context::X11) .map(|context| crate::Context { context, phantom: PhantomData }) .map(|context| crate::RawContext { context, window: () }) } diff --git a/glutin/src/platform_impl/unix/wayland.rs b/glutin/src/platform_impl/unix/wayland.rs index 45228e6ff0..bfebe469c6 100644 --- a/glutin/src/platform_impl/unix/wayland.rs +++ b/glutin/src/platform_impl/unix/wayland.rs @@ -8,7 +8,7 @@ use crate::{ use crate::platform::unix::{EventLoopWindowTargetExtUnix, WindowExtUnix}; use glutin_egl_sys as ffi; pub use wayland_client::sys::client::wl_display; -use winit; + use winit::dpi; use winit::event_loop::EventLoopWindowTarget; use winit::window::{Window, WindowBuilder}; @@ -190,6 +190,6 @@ impl Context { #[inline] pub fn get_pixel_format(&self) -> PixelFormat { - (**self).get_pixel_format().clone() + (**self).get_pixel_format() } } diff --git a/glutin/src/platform_impl/unix/x11.rs b/glutin/src/platform_impl/unix/x11.rs index 9e2ef8f887..171a231ce8 100644 --- a/glutin/src/platform_impl/unix/x11.rs +++ b/glutin/src/platform_impl/unix/x11.rs @@ -13,7 +13,7 @@ use crate::{ }; use glutin_glx_sys as ffi; -use winit; + use winit::dpi; use winit::event_loop::EventLoopWindowTarget; use winit::window::{Window, WindowBuilder}; @@ -110,7 +110,7 @@ where }; let this_lacks_what = x11_utils::examine_visual_info( - &xconn, + xconn, visual_infos, transparent == Some(true), pf_reqs.x11_visual_xid, @@ -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!(), } @@ -178,7 +178,7 @@ impl Context { size: Option>, ) -> Result { Self::try_then_fallback(|fallback| { - Self::new_headless_impl(el, pf_reqs, gl_attr, size.clone(), fallback) + Self::new_headless_impl(el, pf_reqs, gl_attr, size, fallback) }) } @@ -291,7 +291,7 @@ impl Context { transparent: Option, ) -> Result, CreationError> { let select_config = |cs, display| { - select_config(&xconn, transparent, pf_reqs, cs, |config_id| { + select_config(xconn, transparent, pf_reqs, cs, |config_id| { let xid = egl::get_native_visual_id(display, *config_id) as ffi::VisualID; if xid == 0 { return None; @@ -316,7 +316,7 @@ impl Context { _ => panic!("context already exists but is wrong type"), })); Ok(Prototype::Glx(GlxContext::new( - Arc::clone(&xconn), + Arc::clone(xconn), pf_reqs, builder_u.as_ref().unwrap(), screen_id, @@ -375,17 +375,15 @@ 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 { - 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 { - return egl(builder_egl_u); } + } else if GLX.is_some() { + return glx(builder_glx_u); + } else if EGL.is_some() { + return egl(builder_egl_u); } return Err(CreationError::NotSupported( @@ -393,13 +391,11 @@ impl Context { )); } else { if prefer_egl { - if let Some(_) = &*EGL { + if EGL.is_some() { return egl(builder_egl_u); } - } else { - if let Some(_) = &*GLX { - return glx(builder_glx_u); - } + } else if GLX.is_some() { + return glx(builder_glx_u); } return Err(CreationError::NotSupported( @@ -408,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, @@ -482,7 +478,7 @@ impl Context { // getting the `visual_infos` (a struct that contains information about // the visual to use) let visual_infos = match context { - Prototype::Glx(ref p) => p.get_visual_infos().clone(), + Prototype::Glx(ref p) => *p.get_visual_infos(), Prototype::Egl(ref p) => { utils::get_visual_info_from_xid(&xconn, p.get_native_visual_id() as ffi::VisualID) } @@ -554,7 +550,7 @@ impl Context { // start the context building process let context = Self::new_first_stage( - &xconn, + xconn, &pf_reqs, gl_attr, screen_id, diff --git a/glutin/src/platform_impl/unix/x11/utils.rs b/glutin/src/platform_impl/unix/x11/utils.rs index adc9bacffc..6fd7e2991c 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); } } @@ -63,7 +63,7 @@ pub fn examine_visual_info( } } - return Ok(()); + Ok(()) } pub use super::select_config; diff --git a/glutin/src/platform_impl/windows/mod.rs b/glutin/src/platform_impl/windows/mod.rs index e629441c1e..8870c328ec 100644 --- a/glutin/src/platform_impl/windows/mod.rs +++ b/glutin/src/platform_impl/windows/mod.rs @@ -11,7 +11,7 @@ use crate::platform::windows::WindowExtWindows; use glutin_egl_sys as ffi; use winapi::shared::windef::{HGLRC, HWND}; -use winit; + use winit::dpi; use winit::event_loop::EventLoopWindowTarget; use winit::platform::windows::WindowBuilderExtWindows; @@ -77,7 +77,7 @@ impl Context { } _ => unreachable!(), }); - unsafe { WglContext::new(&pf_reqs, &gl_attr_wgl, hwnd).map(Context::Wgl) } + unsafe { WglContext::new(pf_reqs, &gl_attr_wgl, hwnd).map(Context::Wgl) } } // We must use EGL. (Some(_), Some(_)) => { @@ -89,14 +89,14 @@ impl Context { }); EglContext::new( - &pf_reqs, + pf_reqs, &gl_attr_egl, NativeDisplay::Other(Some(std::ptr::null())), EglSurfaceType::Window, |c, _| Ok(c[0]), ) .and_then(|p| p.finish(hwnd)) - .map(|c| Context::Egl(c)) + .map(Context::Egl) } // Try EGL, fallback to WGL. (None, Some(_)) => { @@ -104,7 +104,7 @@ impl Context { let gl_attr_wgl = gl_attr.clone().map_sharing(|_| unreachable!()); if let Ok(c) = EglContext::new( - &pf_reqs, + pf_reqs, &gl_attr_egl, NativeDisplay::Other(Some(std::ptr::null())), EglSurfaceType::Window, @@ -115,7 +115,7 @@ impl Context { Ok(Context::Egl(c)) } else { unsafe { - WglContext::new(&pf_reqs, &gl_attr_wgl, hwnd).map(Context::Wgl) + WglContext::new(pf_reqs, &gl_attr_wgl, hwnd).map(Context::Wgl) } } } @@ -127,7 +127,7 @@ impl Context { Context::HiddenWindowWgl(_, ref c) | Context::Wgl(ref c) => c.get_hglrc(), _ => panic!(), }); - unsafe { WglContext::new(&pf_reqs, &gl_attr_wgl, hwnd).map(Context::Wgl) } + unsafe { WglContext::new(pf_reqs, &gl_attr_wgl, hwnd).map(Context::Wgl) } } } } @@ -162,7 +162,7 @@ impl Context { |c, _| Ok(c[0]), ) .and_then(|prototype| prototype.finish_pbuffer(size)) - .map(|ctx| Context::EglPbuffer(ctx)); + .map(Context::EglPbuffer); if let Ok(context) = context { return Ok(context); @@ -175,7 +175,7 @@ impl Context { .with_visible(false) .with_inner_size(size) .with_drag_and_drop(false); - Self::new_windowed(wb, &el, pf_reqs, gl_attr).map(|(win, context)| match context { + Self::new_windowed(wb, el, pf_reqs, gl_attr).map(|(win, context)| match context { Context::Egl(context) => Context::HiddenWindowEgl(win, context), Context::Wgl(context) => Context::HiddenWindowWgl(win, context), _ => unreachable!(), diff --git a/glutin_egl_sys/src/lib.rs b/glutin_egl_sys/src/lib.rs index fac07d26f8..e6eed6da7d 100644 --- a/glutin_egl_sys/src/lib.rs +++ b/glutin_egl_sys/src/lib.rs @@ -7,7 +7,13 @@ 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 +)] +#![cfg_attr(feature = "cargo-clippy", deny(warnings))] pub mod egl { pub type khronos_utime_nanoseconds_t = super::khronos_utime_nanoseconds_t; diff --git a/glutin_examples/examples/buffer_age.rs b/glutin_examples/examples/buffer_age.rs index 5be0f01f39..1d7df20723 100644 --- a/glutin_examples/examples/buffer_age.rs +++ b/glutin_examples/examples/buffer_age.rs @@ -15,14 +15,14 @@ fn main() { println!("Pixel format of the window's GL context: {:?}", windowed_context.get_pixel_format()); - let gl = support::load(&windowed_context.context()); + let gl = support::load(windowed_context.context()); el.run(move |event, _, control_flow| { println!("{:?}", event); *control_flow = ControlFlow::Wait; match event { - Event::LoopDestroyed => return, + Event::LoopDestroyed => (), Event::WindowEvent { event, .. } => match event { WindowEvent::Resized(physical_size) => windowed_context.resize(physical_size), WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit, diff --git a/glutin_examples/examples/damage.rs b/glutin_examples/examples/damage.rs index dbad180b5f..8479a469b4 100644 --- a/glutin_examples/examples/damage.rs +++ b/glutin_examples/examples/damage.rs @@ -39,7 +39,7 @@ fn main() { println!("Pixel format of the window's GL context: {:?}", windowed_context.get_pixel_format()); - let gl = support::load(&windowed_context.context()); + let gl = support::load(windowed_context.context()); let mut color = Color::new(); @@ -51,7 +51,7 @@ fn main() { *control_flow = ControlFlow::Wait; match event { - Event::LoopDestroyed => return, + Event::LoopDestroyed => (), Event::WindowEvent { event, .. } => match event { WindowEvent::Resized(physical_size) => windowed_context.resize(physical_size), WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit, diff --git a/glutin_examples/examples/fullscreen.rs b/glutin_examples/examples/fullscreen.rs index 9fe2290957..7fcaac00aa 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))), @@ -32,7 +32,7 @@ fn main() { let windowed_context = unsafe { windowed_context.make_current().unwrap() }; - let gl = support::load(&windowed_context.context()); + let gl = support::load(windowed_context.context()); el.run(move |event, _, control_flow| { *control_flow = ControlFlow::Wait; @@ -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/headless.rs b/glutin_examples/examples/headless.rs index a6cb3836f0..519b6bf685 100644 --- a/glutin_examples/examples/headless.rs +++ b/glutin_examples/examples/headless.rs @@ -14,7 +14,7 @@ fn build_context_surfaceless( el: &EventLoop<()>, ) -> Result, CreationError> { use glutin::platform::unix::HeadlessContextExt; - cb.build_surfaceless(&el) + cb.build_surfaceless(el) } fn build_context_headless( @@ -22,7 +22,7 @@ fn build_context_headless( el: &EventLoop<()>, ) -> Result, CreationError> { let size_one = PhysicalSize::new(1, 1); - cb.build_headless(&el, size_one) + cb.build_headless(el, size_one) } #[cfg(target_os = "linux")] diff --git a/glutin_examples/examples/multiwindow.rs b/glutin_examples/examples/multiwindow.rs index 05872cf375..0a13168940 100644 --- a/glutin_examples/examples/multiwindow.rs +++ b/glutin_examples/examples/multiwindow.rs @@ -16,7 +16,7 @@ fn main() { let wb = WindowBuilder::new().with_title(title); let windowed_context = ContextBuilder::new().build_windowed(wb, &el).unwrap(); let windowed_context = unsafe { windowed_context.make_current().unwrap() }; - let gl = support::load(&windowed_context.context()); + let gl = support::load(windowed_context.context()); let window_id = windowed_context.window().id(); let context_id = ct.insert(ContextCurrentWrapper::PossiblyCurrent( ContextWrapper::Windowed(windowed_context), diff --git a/glutin_examples/examples/raw_context.rs b/glutin_examples/examples/raw_context.rs index 81ee3d40cd..367c22c659 100644 --- a/glutin_examples/examples/raw_context.rs +++ b/glutin_examples/examples/raw_context.rs @@ -25,7 +25,7 @@ mod this_example { let mut transparency = String::new(); std::io::stdin().read_line(&mut transparency).unwrap(); let transparency = transparency.trim().parse().unwrap_or_else(|_| { - println!("Unknown input, assumming true."); + println!("Unknown input, assuming true."); true }); @@ -112,7 +112,6 @@ File a PR if you are interested in implementing the latter. match event { Event::LoopDestroyed => { Takeable::take(&mut raw_context); // Make sure it drops first - return; } Event::WindowEvent { event, .. } => match event { WindowEvent::Resized(physical_size) => raw_context.resize(physical_size), diff --git a/glutin_examples/examples/sharing.rs b/glutin_examples/examples/sharing.rs index 8e8f43ee49..c830aa165a 100644 --- a/glutin_examples/examples/sharing.rs +++ b/glutin_examples/examples/sharing.rs @@ -41,7 +41,7 @@ fn main() { "Pixel format of the window's GL context: {:?}", windowed_context.windowed().get_pixel_format() ); - let glw = support::load(&windowed_context.windowed().context()); + let glw = support::load(windowed_context.windowed().context()); let render_buf = make_renderbuf(&glw, size); @@ -61,10 +61,9 @@ 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()); + let glc = support::load(headless_context.headless()); let mut context_fb = 0; unsafe { @@ -81,24 +80,19 @@ 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); *control_flow = ControlFlow::Wait; match event { - Event::LoopDestroyed => { - unsafe { - 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); - } - return; - } + Event::LoopDestroyed => unsafe { + let _ = ct.get_current(windowed_id).unwrap(); + glw.gl.DeleteFramebuffers(1, &window_fb); + glw.gl.DeleteRenderbuffers(1, &render_buf); + let _ = ct.get_current(headless_id).unwrap(); + glc.gl.DeleteFramebuffers(1, &context_fb); + }, Event::WindowEvent { event, .. } => match event { WindowEvent::Resized(physical_size) => { let windowed_context = ct.get_current(windowed_id).unwrap(); @@ -113,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 _); @@ -123,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 8afc689d10..4e283255bd 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")); } @@ -94,7 +102,7 @@ static VERTEX_DATA: [f32; 15] = [ 0.5, -0.5, 0.0, 0.0, 1.0, ]; -const VS_SRC: &'static [u8] = b" +const VS_SRC: &[u8] = b" #version 100 precision mediump float; @@ -109,7 +117,7 @@ void main() { } \0"; -const FS_SRC: &'static [u8] = b" +const FS_SRC: &[u8] = b" #version 100 precision mediump float; diff --git a/glutin_examples/examples/transparent.rs b/glutin_examples/examples/transparent.rs index 4c15b28181..df8d26c29a 100644 --- a/glutin_examples/examples/transparent.rs +++ b/glutin_examples/examples/transparent.rs @@ -18,14 +18,14 @@ fn main() { println!("Pixel format of the window's GL context: {:?}", windowed_context.get_pixel_format()); - let gl = support::load(&windowed_context.context()); + let gl = support::load(windowed_context.context()); el.run(move |event, _, control_flow| { println!("{:?}", event); *control_flow = ControlFlow::Wait; match event { - Event::LoopDestroyed => return, + Event::LoopDestroyed => (), Event::WindowEvent { event, .. } => match event { WindowEvent::Resized(physical_size) => windowed_context.resize(physical_size), WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit, diff --git a/glutin_examples/examples/window.rs b/glutin_examples/examples/window.rs index 44c92852fa..4af3d1543a 100644 --- a/glutin_examples/examples/window.rs +++ b/glutin_examples/examples/window.rs @@ -15,14 +15,14 @@ fn main() { println!("Pixel format of the window's GL context: {:?}", windowed_context.get_pixel_format()); - let gl = support::load(&windowed_context.context()); + let gl = support::load(windowed_context.context()); el.run(move |event, _, control_flow| { println!("{:?}", event); *control_flow = ControlFlow::Wait; match event { - Event::LoopDestroyed => return, + Event::LoopDestroyed => (), Event::WindowEvent { event, .. } => match event { WindowEvent::Resized(physical_size) => windowed_context.resize(physical_size), WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit, diff --git a/glutin_examples/ios-example/rust/src/lib.rs b/glutin_examples/ios-example/rust/src/lib.rs index b273971e27..654d25f74e 100644 --- a/glutin_examples/ios-example/rust/src/lib.rs +++ b/glutin_examples/ios-example/rust/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg_attr(feature = "cargo-clippy", deny(warnings))] + use glutin::event::{Event, WindowEvent}; use glutin::event_loop::{ControlFlow, EventLoop}; use glutin::window::WindowBuilder; @@ -17,7 +19,7 @@ fn main() { let windowed_context = unsafe { windowed_context.make_current().unwrap() }; println!("Pixel format of the window's GL context: {:?}", windowed_context.get_pixel_format()); - let gl = support::load(&windowed_context.context()); + let gl = support::load(windowed_context.context()); let mut inc: f32 = 0.0; el.run(move |event, _, control_flow| { @@ -25,7 +27,7 @@ fn main() { *control_flow = ControlFlow::Wait; match event { - Event::LoopDestroyed => return, + Event::LoopDestroyed => (), Event::WindowEvent { event, .. } => match event { WindowEvent::Resized(physical_size) => windowed_context.resize(physical_size), WindowEvent::Touch(_touch) => { diff --git a/glutin_gles2_sys/src/lib.rs b/glutin_gles2_sys/src/lib.rs index 4a13fa6597..118ff58fb1 100644 --- a/glutin_gles2_sys/src/lib.rs +++ b/glutin_gles2_sys/src/lib.rs @@ -1,5 +1,13 @@ #![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 +)] +#![cfg_attr(feature = "cargo-clippy", deny(warnings))] 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 fadb62a0fa..1ecc40a14c 100644 --- a/glutin_glx_sys/src/lib.rs +++ b/glutin_glx_sys/src/lib.rs @@ -5,6 +5,13 @@ target_os = "netbsd", target_os = "openbsd" ))] +#![allow( + clippy::manual_non_exhaustive, + clippy::missing_safety_doc, + clippy::redundant_static_lifetimes, + clippy::unused_unit +)] +#![cfg_attr(feature = "cargo-clippy", deny(warnings))] 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 42cdd5688d..751b5cf5ba 100644 --- a/glutin_wgl_sys/src/lib.rs +++ b/glutin_wgl_sys/src/lib.rs @@ -1,4 +1,6 @@ #![cfg(any(target_os = "windows"))] +#![allow(clippy::manual_non_exhaustive, clippy::missing_safety_doc, clippy::too_many_arguments)] +#![cfg_attr(feature = "cargo-clippy", deny(warnings))] /// WGL bindings pub mod wgl {