resolve errors from latest clippy version

This commit is contained in:
Carter Anderson 2020-09-07 15:00:03 -07:00
parent d86fae8147
commit 413caae7bb
5 changed files with 18 additions and 28 deletions

View File

@ -67,9 +67,7 @@ impl Entities {
/// Access the location storage of an entity /// Access the location storage of an entity
pub fn get_mut(&mut self, entity: Entity) -> Result<&mut Location, NoSuchEntity> { pub fn get_mut(&mut self, entity: Entity) -> Result<&mut Location, NoSuchEntity> {
self.entity_locations self.entity_locations.get_mut(&entity).ok_or(NoSuchEntity)
.get_mut(&entity)
.ok_or_else(|| NoSuchEntity)
} }
/// Access the location storage of an entity /// Access the location storage of an entity
@ -81,7 +79,7 @@ impl Entities {
self.entity_locations self.entity_locations
.get(&entity) .get(&entity)
.cloned() .cloned()
.ok_or_else(|| NoSuchEntity) .ok_or(NoSuchEntity)
} }
} }

View File

@ -111,9 +111,7 @@ impl<'a> MapSerializer<'a> {
} }
fn format_type_name<'a>(registry: &'a PropertyTypeRegistry, type_name: &'a str) -> &'a str { fn format_type_name<'a>(registry: &'a PropertyTypeRegistry, type_name: &'a str) -> &'a str {
registry registry.format_type_name(type_name).unwrap_or(type_name)
.format_type_name(type_name)
.unwrap_or_else(|| type_name)
} }
impl<'a> Serialize for MapSerializer<'a> { impl<'a> Serialize for MapSerializer<'a> {

View File

@ -230,7 +230,7 @@ impl<'a> DrawContext<'a> {
) -> Result<RenderResourceBinding, DrawError> { ) -> Result<RenderResourceBinding, DrawError> {
self.shared_buffers self.shared_buffers
.get_buffer(render_resource, buffer_usage) .get_buffer(render_resource, buffer_usage)
.ok_or_else(|| DrawError::BufferAllocationFailure) .ok_or(DrawError::BufferAllocationFailure)
} }
pub fn set_pipeline( pub fn set_pipeline(
@ -263,14 +263,14 @@ impl<'a> DrawContext<'a> {
pub fn get_pipeline_descriptor(&self) -> Result<&PipelineDescriptor, DrawError> { pub fn get_pipeline_descriptor(&self) -> Result<&PipelineDescriptor, DrawError> {
self.current_pipeline self.current_pipeline
.and_then(|handle| self.pipelines.get(&handle)) .and_then(|handle| self.pipelines.get(&handle))
.ok_or_else(|| DrawError::NoPipelineSet) .ok_or(DrawError::NoPipelineSet)
} }
pub fn get_pipeline_layout(&self) -> Result<&PipelineLayout, DrawError> { pub fn get_pipeline_layout(&self) -> Result<&PipelineLayout, DrawError> {
self.get_pipeline_descriptor().and_then(|descriptor| { self.get_pipeline_descriptor().and_then(|descriptor| {
descriptor descriptor
.get_layout() .get_layout()
.ok_or_else(|| DrawError::PipelineHasNoLayout) .ok_or(DrawError::PipelineHasNoLayout)
}) })
} }
@ -279,16 +279,14 @@ impl<'a> DrawContext<'a> {
draw: &mut Draw, draw: &mut Draw,
render_resource_bindings: &mut [&mut RenderResourceBindings], render_resource_bindings: &mut [&mut RenderResourceBindings],
) -> Result<(), DrawError> { ) -> Result<(), DrawError> {
let pipeline = self let pipeline = self.current_pipeline.ok_or(DrawError::NoPipelineSet)?;
.current_pipeline
.ok_or_else(|| DrawError::NoPipelineSet)?;
let pipeline_descriptor = self let pipeline_descriptor = self
.pipelines .pipelines
.get(&pipeline) .get(&pipeline)
.ok_or_else(|| DrawError::NonExistentPipeline)?; .ok_or(DrawError::NonExistentPipeline)?;
let layout = pipeline_descriptor let layout = pipeline_descriptor
.get_layout() .get_layout()
.ok_or_else(|| DrawError::PipelineHasNoLayout)?; .ok_or(DrawError::PipelineHasNoLayout)?;
for bindings in render_resource_bindings.iter_mut() { for bindings in render_resource_bindings.iter_mut() {
bindings.update_bind_groups(pipeline_descriptor, &**self.render_resource_context); bindings.update_bind_groups(pipeline_descriptor, &**self.render_resource_context);
} }
@ -311,16 +309,14 @@ impl<'a> DrawContext<'a> {
index: u32, index: u32,
bind_group: &BindGroup, bind_group: &BindGroup,
) -> Result<(), DrawError> { ) -> Result<(), DrawError> {
let pipeline = self let pipeline = self.current_pipeline.ok_or(DrawError::NoPipelineSet)?;
.current_pipeline
.ok_or_else(|| DrawError::NoPipelineSet)?;
let pipeline_descriptor = self let pipeline_descriptor = self
.pipelines .pipelines
.get(&pipeline) .get(&pipeline)
.ok_or_else(|| DrawError::NonExistentPipeline)?; .ok_or(DrawError::NonExistentPipeline)?;
let layout = pipeline_descriptor let layout = pipeline_descriptor
.get_layout() .get_layout()
.ok_or_else(|| DrawError::PipelineHasNoLayout)?; .ok_or(DrawError::PipelineHasNoLayout)?;
let bind_group_descriptor = &layout.bind_groups[index as usize]; let bind_group_descriptor = &layout.bind_groups[index as usize];
self.render_resource_context self.render_resource_context
.create_bind_group(bind_group_descriptor.id, bind_group); .create_bind_group(bind_group_descriptor.id, bind_group);
@ -333,16 +329,14 @@ impl<'a> DrawContext<'a> {
render_resource_bindings: &[&RenderResourceBindings], render_resource_bindings: &[&RenderResourceBindings],
) -> Result<Option<Range<u32>>, DrawError> { ) -> Result<Option<Range<u32>>, DrawError> {
let mut indices = None; let mut indices = None;
let pipeline = self let pipeline = self.current_pipeline.ok_or(DrawError::NoPipelineSet)?;
.current_pipeline
.ok_or_else(|| DrawError::NoPipelineSet)?;
let pipeline_descriptor = self let pipeline_descriptor = self
.pipelines .pipelines
.get(&pipeline) .get(&pipeline)
.ok_or_else(|| DrawError::NonExistentPipeline)?; .ok_or(DrawError::NonExistentPipeline)?;
let layout = pipeline_descriptor let layout = pipeline_descriptor
.get_layout() .get_layout()
.ok_or_else(|| DrawError::PipelineHasNoLayout)?; .ok_or(DrawError::PipelineHasNoLayout)?;
for (slot, vertex_buffer_descriptor) in layout.vertex_buffer_descriptors.iter().enumerate() for (slot, vertex_buffer_descriptor) in layout.vertex_buffer_descriptors.iter().enumerate()
{ {
for bindings in render_resource_bindings.iter() { for bindings in render_resource_bindings.iter() {

View File

@ -144,7 +144,7 @@ impl NodeState {
{ {
self.node self.node
.downcast_ref::<T>() .downcast_ref::<T>()
.ok_or_else(|| RenderGraphError::WrongNodeType) .ok_or(RenderGraphError::WrongNodeType)
} }
pub fn node_mut<T>(&mut self) -> Result<&mut T, RenderGraphError> pub fn node_mut<T>(&mut self) -> Result<&mut T, RenderGraphError>
@ -153,7 +153,7 @@ impl NodeState {
{ {
self.node self.node
.downcast_mut::<T>() .downcast_mut::<T>()
.ok_or_else(|| RenderGraphError::WrongNodeType) .ok_or(RenderGraphError::WrongNodeType)
} }
pub fn validate_output_slots(&self) -> Result<(), RenderGraphError> { pub fn validate_output_slots(&self) -> Result<(), RenderGraphError> {

View File

@ -110,7 +110,7 @@ impl TextureAtlasBuilder {
} }
} }
let rect_placements = rect_placements.ok_or_else(|| RectanglePackError::NotEnoughSpace)?; let rect_placements = rect_placements.ok_or(RectanglePackError::NotEnoughSpace)?;
let mut texture_rects = Vec::with_capacity(rect_placements.packed_locations().len()); let mut texture_rects = Vec::with_capacity(rect_placements.packed_locations().len());
let mut texture_handles = HashMap::default(); let mut texture_handles = HashMap::default();