Skip to content

Commit

Permalink
Fix some simple clippy lints (#284)
Browse files Browse the repository at this point in the history
* Exclude generated code from clippy

* Fix clippy::needless_borrows_for_generic_args

* Fix clippy::redundant_static_lifetimes

* Fix clippy::needless_borrowed_reference

* Fix: clippy::filter_next

* Fix clippy::needless_borrow

* Fix clippy::needless_borrow in tests

* Fix `dropping_copy_types` lint

`GlApi` is Copy and a simple enum on all platforms, so point in dropping it explicitly.

* Fix clippy::clippy::needless_return

* cargo fmt
  • Loading branch information
jschwe committed Apr 21, 2024
1 parent 3722893 commit 0a55a6a
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 84 deletions.
6 changes: 3 additions & 3 deletions surfman/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ fn main() {
|| (target_os == "windows" && cfg!(feature = "sm-angle"))
|| target_family.as_ref().map_or(false, |f| f == "unix")
{
let mut file = File::create(&dest.join("egl_bindings.rs")).unwrap();
let mut file = File::create(dest.join("egl_bindings.rs")).unwrap();
let registry = Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, []);
registry.write_bindings(StructGenerator, &mut file).unwrap();
}

// Generate GL bindings.
if target_os == "android" {
let mut file = File::create(&dest.join("gl_bindings.rs")).unwrap();
let mut file = File::create(dest.join("gl_bindings.rs")).unwrap();
let registry = Registry::new(Api::Gles2, (3, 0), Profile::Core, Fallbacks::All, []);
registry.write_bindings(StructGenerator, &mut file).unwrap();
} else {
let mut file = File::create(&dest.join("gl_bindings.rs")).unwrap();
let mut file = File::create(dest.join("gl_bindings.rs")).unwrap();
let registry = Registry::new(Api::Gl, (3, 3), Profile::Core, Fallbacks::All, []);
registry.write_bindings(StructGenerator, &mut file).unwrap();
}
Expand Down
2 changes: 2 additions & 0 deletions surfman/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub(crate) use crate::gl::Gles2 as Gl;
mod gl_utils;
mod renderbuffers;

#[allow(clippy::all)]
mod gl {
include!(concat!(env!("OUT_DIR"), "/gl_bindings.rs"));
}
Expand All @@ -73,6 +74,7 @@ mod gl {
unix
))]
#[allow(non_camel_case_types)]
#[allow(clippy::all)]
mod egl {
use std::os::raw::{c_long, c_void};
pub type khronos_utime_nanoseconds_t = khronos_uint64_t;
Expand Down
8 changes: 4 additions & 4 deletions surfman/src/platform/generic/multi/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ where
/// Device handles are local to a single thread.
pub fn create_device(&self, adapter: &Adapter<Def, Alt>) -> Result<Device<Def, Alt>, Error> {
match (self, adapter) {
(&Connection::Default(ref connection), &Adapter::Default(ref adapter)) => {
(Connection::Default(connection), Adapter::Default(adapter)) => {
connection.create_device(adapter).map(Device::Default)
}
(&Connection::Alternate(ref connection), &Adapter::Alternate(ref adapter)) => {
(Connection::Alternate(connection), Adapter::Alternate(adapter)) => {
connection.create_device(adapter).map(Device::Alternate)
}
_ => Err(Error::IncompatibleAdapter),
Expand All @@ -164,13 +164,13 @@ where
native_device: NativeDevice<Def, Alt>,
) -> Result<Device<Def, Alt>, Error> {
match self {
&Connection::Default(ref connection) => match native_device {
Connection::Default(connection) => match native_device {
NativeDevice::Default(native_device) => connection
.create_device_from_native_device(native_device)
.map(Device::Default),
_ => Err(Error::IncompatibleNativeDevice),
},
&Connection::Alternate(ref connection) => match native_device {
Connection::Alternate(connection) => match native_device {
NativeDevice::Alternate(native_device) => connection
.create_device_from_native_device(native_device)
.map(Device::Alternate),
Expand Down
69 changes: 30 additions & 39 deletions surfman/src/platform/generic/multi/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ where
share_with: Option<&Context<Def, Alt>>,
) -> Result<Context<Def, Alt>, Error> {
match (&mut *self, descriptor) {
(&mut Device::Default(ref mut device), &ContextDescriptor::Default(ref descriptor)) => {
(&mut Device::Default(ref mut device), ContextDescriptor::Default(descriptor)) => {
let shared = match share_with {
Some(&Context::Default(ref other)) => Some(other),
Some(Context::Default(other)) => Some(other),
Some(_) => {
return Err(Error::IncompatibleSharedContext);
}
Expand All @@ -107,12 +107,9 @@ where
.create_context(descriptor, shared)
.map(Context::Default)
}
(
&mut Device::Alternate(ref mut device),
&ContextDescriptor::Alternate(ref descriptor),
) => {
(&mut Device::Alternate(ref mut device), ContextDescriptor::Alternate(descriptor)) => {
let shared = match share_with {
Some(&Context::Alternate(ref other)) => Some(other),
Some(Context::Alternate(other)) => Some(other),
Some(_) => {
return Err(Error::IncompatibleSharedContext);
}
Expand All @@ -132,13 +129,13 @@ where
native_context: NativeContext<Def, Alt>,
) -> Result<Context<Def, Alt>, Error> {
match self {
&Device::Default(ref device) => match native_context {
Device::Default(device) => match native_context {
NativeContext::Default(native_context) => device
.create_context_from_native_context(native_context)
.map(Context::Default),
_ => Err(Error::IncompatibleNativeContext),
},
&Device::Alternate(ref device) => match native_context {
Device::Alternate(device) => match native_context {
NativeContext::Alternate(native_context) => device
.create_context_from_native_context(native_context)
.map(Context::Alternate),
Expand All @@ -152,10 +149,10 @@ where
/// The context must have been created on this device.
pub fn destroy_context(&self, context: &mut Context<Def, Alt>) -> Result<(), Error> {
match (self, &mut *context) {
(&Device::Default(ref device), &mut Context::Default(ref mut context)) => {
(Device::Default(device), &mut Context::Default(ref mut context)) => {
device.destroy_context(context)
}
(&Device::Alternate(ref device), &mut Context::Alternate(ref mut context)) => {
(Device::Alternate(device), &mut Context::Alternate(ref mut context)) => {
device.destroy_context(context)
}
_ => Err(Error::IncompatibleContext),
Expand All @@ -165,10 +162,10 @@ where
/// Returns the native context underlying this context.
pub fn native_context(&self, context: &Context<Def, Alt>) -> NativeContext<Def, Alt> {
match (self, context) {
(&Device::Default(ref device), &Context::Default(ref context)) => {
(Device::Default(device), Context::Default(context)) => {
NativeContext::Default(device.native_context(context))
}
(&Device::Alternate(ref device), &Context::Alternate(ref context)) => {
(Device::Alternate(device), Context::Alternate(context)) => {
NativeContext::Alternate(device.native_context(context))
}
_ => panic!("Incompatible context!"),
Expand All @@ -178,10 +175,10 @@ where
/// Returns the descriptor that this context was created with.
pub fn context_descriptor(&self, context: &Context<Def, Alt>) -> ContextDescriptor<Def, Alt> {
match (self, context) {
(&Device::Default(ref device), &Context::Default(ref context)) => {
(Device::Default(device), Context::Default(context)) => {
ContextDescriptor::Default(device.context_descriptor(context))
}
(&Device::Alternate(ref device), &Context::Alternate(ref context)) => {
(Device::Alternate(device), Context::Alternate(context)) => {
ContextDescriptor::Alternate(device.context_descriptor(context))
}
_ => panic!("Incompatible context!"),
Expand All @@ -193,10 +190,10 @@ where
/// After calling this function, it is valid to use OpenGL rendering commands.
pub fn make_context_current(&self, context: &Context<Def, Alt>) -> Result<(), Error> {
match (self, context) {
(&Device::Default(ref device), &Context::Default(ref context)) => {
(Device::Default(device), Context::Default(context)) => {
device.make_context_current(context)
}
(&Device::Alternate(ref device), &Context::Alternate(ref context)) => {
(Device::Alternate(device), Context::Alternate(context)) => {
device.make_context_current(context)
}
_ => Err(Error::IncompatibleContext),
Expand All @@ -209,8 +206,8 @@ where
/// made current.
pub fn make_no_context_current(&self) -> Result<(), Error> {
match self {
&Device::Default(ref device) => device.make_no_context_current(),
&Device::Alternate(ref device) => device.make_no_context_current(),
Device::Default(device) => device.make_no_context_current(),
Device::Alternate(device) => device.make_no_context_current(),
}
}

Expand All @@ -230,14 +227,13 @@ where
surface: Surface<Def, Alt>,
) -> Result<(), (Error, Surface<Def, Alt>)> {
match (self, &mut *context) {
(&Device::Default(ref device), &mut Context::Default(ref mut context)) => match surface
{
(Device::Default(device), &mut Context::Default(ref mut context)) => match surface {
Surface::Default(surface) => device
.bind_surface_to_context(context, surface)
.map_err(|(err, surface)| (err, Surface::Default(surface))),
_ => Err((Error::IncompatibleSurface, surface)),
},
(&Device::Alternate(ref device), &mut Context::Alternate(ref mut context)) => {
(Device::Alternate(device), &mut Context::Alternate(ref mut context)) => {
match surface {
Surface::Alternate(surface) => device
.bind_surface_to_context(context, surface)
Expand All @@ -258,10 +254,10 @@ where
context: &mut Context<Def, Alt>,
) -> Result<Option<Surface<Def, Alt>>, Error> {
match (self, &mut *context) {
(&Device::Default(ref device), &mut Context::Default(ref mut context)) => device
(Device::Default(device), &mut Context::Default(ref mut context)) => device
.unbind_surface_from_context(context)
.map(|surface| surface.map(Surface::Default)),
(&Device::Alternate(ref device), &mut Context::Alternate(ref mut context)) => device
(Device::Alternate(device), &mut Context::Alternate(ref mut context)) => device
.unbind_surface_from_context(context)
.map(|surface| surface.map(Surface::Alternate)),
_ => Err(Error::IncompatibleContext),
Expand All @@ -274,13 +270,12 @@ where
context_descriptor: &ContextDescriptor<Def, Alt>,
) -> ContextAttributes {
match (self, context_descriptor) {
(&Device::Default(ref device), &ContextDescriptor::Default(ref context_descriptor)) => {
(Device::Default(device), ContextDescriptor::Default(context_descriptor)) => {
device.context_descriptor_attributes(context_descriptor)
}
(Device::Alternate(device), ContextDescriptor::Alternate(context_descriptor)) => {
device.context_descriptor_attributes(context_descriptor)
}
(
&Device::Alternate(ref device),
&ContextDescriptor::Alternate(ref context_descriptor),
) => device.context_descriptor_attributes(context_descriptor),
_ => panic!("Incompatible context!"),
}
}
Expand All @@ -298,10 +293,10 @@ where
symbol_name: &str,
) -> *const c_void {
match (self, context) {
(&Device::Default(ref device), &Context::Default(ref context)) => {
(Device::Default(device), Context::Default(context)) => {
device.get_proc_address(context, symbol_name)
}
(&Device::Alternate(ref device), &Context::Alternate(ref context)) => {
(Device::Alternate(device), Context::Alternate(context)) => {
device.get_proc_address(context, symbol_name)
}
_ => panic!("Incompatible context!"),
Expand All @@ -314,12 +309,8 @@ where
/// a new one, the new context might have the same ID as the destroyed one.
pub fn context_id(&self, context: &Context<Def, Alt>) -> ContextID {
match (self, context) {
(&Device::Default(ref device), &Context::Default(ref context)) => {
device.context_id(context)
}
(&Device::Alternate(ref device), &Context::Alternate(ref context)) => {
device.context_id(context)
}
(Device::Default(device), Context::Default(context)) => device.context_id(context),
(Device::Alternate(device), Context::Alternate(context)) => device.context_id(context),
_ => panic!("Incompatible context!"),
}
}
Expand All @@ -332,10 +323,10 @@ where
context: &Context<Def, Alt>,
) -> Result<Option<SurfaceInfo>, Error> {
match (self, context) {
(&Device::Default(ref device), &Context::Default(ref context)) => {
(Device::Default(device), Context::Default(context)) => {
device.context_surface_info(context)
}
(&Device::Alternate(ref device), &Context::Alternate(ref context)) => {
(Device::Alternate(device), Context::Alternate(context)) => {
device.context_surface_info(context)
}
_ => Err(Error::IncompatibleContext),
Expand Down

0 comments on commit 0a55a6a

Please sign in to comment.