Address Clippy lints

This commit is contained in:
Poly 2022-07-04 01:17:29 +02:00 committed by Héctor Ramón Jiménez
parent e053e25d2c
commit 15f794b7a8
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
43 changed files with 147 additions and 172 deletions

1
clippy.toml Normal file
View file

@ -0,0 +1 @@
too-many-arguments-threshold = 20

View file

@ -183,11 +183,7 @@ where
let mapper = self.mapper;
Box::pin(
self.recipe
.stream(input)
.map(move |element| mapper(element)),
)
Box::pin(self.recipe.stream(input).map(mapper))
}
}

View file

@ -127,7 +127,7 @@ where
futures.push(Box::pin(future));
}
self.subscriptions.retain(|id, _| alive.contains(&id));
self.subscriptions.retain(|id, _| alive.contains(id));
futures
}

View file

@ -70,7 +70,7 @@ impl Shader {
unsafe {
let shader = gl.create_shader(stage).expect("Cannot create shader");
gl.shader_source(shader, &content);
gl.shader_source(shader, content);
gl.compile_shader(shader);
if !gl.get_shader_compile_status(shader) {

View file

@ -110,10 +110,8 @@ impl Pipeline {
bounds: Rectangle<u32>,
) {
// TODO: Remove this allocation (probably by changing the shader and removing the need of two `position`)
let vertices: Vec<Vertex> = instances
.iter()
.flat_map(|quad| Vertex::from_quad(quad))
.collect();
let vertices: Vec<Vertex> =
instances.iter().flat_map(Vertex::from_quad).collect();
// TODO: Remove this allocation (or allocate only when needed)
let indices: Vec<i32> = (0..instances.len().min(MAX_QUADS) as i32)
@ -187,13 +185,13 @@ impl Pipeline {
gl.buffer_sub_data_u8_slice(
glow::ARRAY_BUFFER,
0,
bytemuck::cast_slice(&vertices),
bytemuck::cast_slice(vertices),
);
gl.buffer_sub_data_u8_slice(
glow::ELEMENT_ARRAY_BUFFER,
0,
bytemuck::cast_slice(&indices),
bytemuck::cast_slice(indices),
);
gl.draw_elements(

View file

@ -154,7 +154,7 @@ impl Pipeline {
gl.buffer_sub_data_u8_slice(
glow::ARRAY_BUFFER,
0,
bytemuck::cast_slice(&instances),
bytemuck::cast_slice(instances),
);
gl.draw_arrays_instanced(

View file

@ -54,7 +54,7 @@ impl Pipeline {
#[cfg(target_arch = "wasm32")]
let draw_brush_builder = draw_brush_builder.draw_cache_align_4x4(true);
let draw_brush = draw_brush_builder.build(&gl);
let draw_brush = draw_brush_builder.build(gl);
let measure_brush =
glyph_brush::GlyphBrushBuilder::using_font(font).build();
@ -180,7 +180,8 @@ impl Pipeline {
}
b_count += utf8_len;
}
return byte_index;
byte_index
};
if !nearest_only {

View file

@ -202,7 +202,7 @@ impl<'a> Layer<'a> {
Self::process_primitive(
layers,
translation + *new_translation,
&content,
content,
current_layer,
);
}
@ -210,7 +210,7 @@ impl<'a> Layer<'a> {
Self::process_primitive(
layers,
translation,
&cache,
cache,
current_layer,
);
}

View file

@ -74,7 +74,7 @@ impl Path {
pub(super) fn dashed(path: &Path, line_dash: LineDash<'_>) -> Path {
Path::new(|builder| {
let segments_odd = (line_dash.segments.len() % 2 == 1).then(|| {
[&line_dash.segments[..], &line_dash.segments[..]].concat()
[line_dash.segments, line_dash.segments].concat()
});
let mut draw_line = false;
@ -103,8 +103,7 @@ pub(super) fn dashed(path: &Path, line_dash: LineDash<'_>) -> Path {
},
index: line_dash.offset,
intervals: segments_odd
.as_ref()
.map(Vec::as_slice)
.as_deref()
.unwrap_or(line_dash.segments),
},
);

View file

@ -53,7 +53,7 @@ impl Builder {
let _ = self.raw.line_to(a);
}
let _ = self.raw.arc_to(
self.raw.arc_to(
math::Vector::new(radius, radius),
math::Angle::radians(0.0),
path::ArcFlags::default(),

View file

@ -67,10 +67,7 @@ where
let side_length = (self.state.width + 2 * QUIET_ZONE) as f32
* f32::from(self.cell_size);
layout::Node::new(Size::new(
f32::from(side_length),
f32::from(side_length),
))
layout::Node::new(Size::new(side_length, side_length))
}
fn draw(

View file

@ -1,13 +1,7 @@
/// The hasher used to compare layouts.
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct Hasher(twox_hash::XxHash64);
impl Default for Hasher {
fn default() -> Self {
Hasher(twox_hash::XxHash64::default())
}
}
impl core::hash::Hasher for Hasher {
fn write(&mut self, bytes: &[u8]) {
self.0.write(bytes)

View file

@ -174,9 +174,9 @@ where
Self {
container,
width: width,
width,
target_height,
style: style,
style,
}
}
}
@ -230,7 +230,7 @@ where
shell: &mut Shell<'_, Message>,
) -> event::Status {
self.container.on_event(
event.clone(),
event,
layout,
cursor_position,
renderer,
@ -326,7 +326,8 @@ where
use std::f32;
let limits = limits.width(Length::Fill).height(Length::Shrink);
let text_size = self.text_size.unwrap_or(renderer.default_size());
let text_size =
self.text_size.unwrap_or_else(|| renderer.default_size());
let size = {
let intrinsic = Size::new(
@ -366,8 +367,9 @@ where
let bounds = layout.bounds();
if bounds.contains(cursor_position) {
let text_size =
self.text_size.unwrap_or(renderer.default_size());
let text_size = self
.text_size
.unwrap_or_else(|| renderer.default_size());
*self.hovered_option = Some(
((cursor_position.y - bounds.y)
@ -380,8 +382,9 @@ where
let bounds = layout.bounds();
if bounds.contains(cursor_position) {
let text_size =
self.text_size.unwrap_or(renderer.default_size());
let text_size = self
.text_size
.unwrap_or_else(|| renderer.default_size());
*self.hovered_option = Some(
((cursor_position.y - bounds.y)
@ -430,7 +433,8 @@ where
let appearance = theme.appearance(self.style);
let bounds = layout.bounds();
let text_size = self.text_size.unwrap_or(renderer.default_size());
let text_size =
self.text_size.unwrap_or_else(|| renderer.default_size());
let option_height = (text_size + self.padding.vertical()) as usize;
let offset = viewport.y - bounds.y;

View file

@ -113,7 +113,7 @@ where
&mut messages,
);
messages.extend(self.queued_messages.drain(..));
messages.append(&mut self.queued_messages);
self.queued_events.clear();
debug.event_processing_finished();

View file

@ -430,7 +430,7 @@ where
overlay
.as_ref()
.and_then(|layout| {
root.overlay(Layout::new(&base), renderer).map(|overlay| {
root.overlay(Layout::new(base), renderer).map(|overlay| {
let overlay_interaction = overlay.mouse_interaction(
Layout::new(layout),
cursor_position,

View file

@ -158,7 +158,10 @@ where
Text::new(&self.label)
.font(self.font.clone())
.width(self.width)
.size(self.text_size.unwrap_or(renderer.default_size())),
.size(
self.text_size
.unwrap_or_else(|| renderer.default_size()),
),
)
.layout(renderer, limits)
}

View file

@ -835,8 +835,7 @@ fn hovered_split<'a>(
) -> Option<(Split, Axis, Rectangle)> {
splits
.filter_map(|(split, (axis, region, ratio))| {
let bounds =
axis.split_line_bounds(*region, *ratio, f32::from(spacing));
let bounds = axis.split_line_bounds(*region, *ratio, spacing);
if bounds.contains(cursor_position) {
Some((*split, *axis, bounds))

View file

@ -36,14 +36,11 @@ impl Node {
std::iter::from_fn(move || {
while let Some(node) = unvisited_nodes.pop() {
match node {
Node::Split { id, a, b, .. } => {
unvisited_nodes.push(a);
unvisited_nodes.push(b);
if let Node::Split { id, a, b, .. } = node {
unvisited_nodes.push(a);
unvisited_nodes.push(b);
return Some(id);
}
_ => {}
return Some(id);
}
}
@ -124,12 +121,9 @@ impl Node {
}
pub(crate) fn update(&mut self, f: &impl Fn(&mut Node)) {
match self {
Node::Split { a, b, .. } => {
a.update(f);
b.update(f);
}
_ => {}
if let Node::Split { a, b, .. } = self {
a.update(f);
b.update(f);
}
f(self);

View file

@ -66,6 +66,11 @@ impl<T> State<T> {
self.panes.len()
}
/// Returns `true` if the amount of panes in the [`State`] is 0.
pub fn is_empty(&self) -> bool {
self.len() == 0
}
/// Returns the internal state of the given [`Pane`], if it exists.
pub fn get(&self, pane: &Pane) -> Option<&T> {
self.panes.get(pane)

View file

@ -160,7 +160,7 @@ where
let limits = limits.width(width).height(Length::Shrink).pad(padding);
let text_size = text_size.unwrap_or(renderer.default_size());
let text_size = text_size.unwrap_or_else(|| renderer.default_size());
let max_width = match width {
Length::Shrink => {
@ -407,10 +407,9 @@ pub fn draw<T, Renderer>(
let label = selected.map(ToString::to_string);
if let Some(label) =
label.as_ref().map(String::as_str).or_else(|| placeholder)
{
let text_size = f32::from(text_size.unwrap_or(renderer.default_size()));
if let Some(label) = label.as_deref().or(placeholder) {
let text_size =
f32::from(text_size.unwrap_or_else(|| renderer.default_size()));
renderer.fill_text(Text {
content: label,
@ -460,7 +459,7 @@ where
self.padding,
self.text_size,
&self.font,
self.placeholder.as_ref().map(String::as_str),
self.placeholder.as_deref(),
&self.options,
)
}
@ -513,7 +512,7 @@ where
self.padding,
self.text_size,
&self.font,
self.placeholder.as_ref().map(String::as_str),
self.placeholder.as_deref(),
self.selected.as_ref(),
self.style,
)

View file

@ -168,11 +168,9 @@ where
.width(Length::Units(self.size))
.height(Length::Units(self.size)),
)
.push(
Text::new(&self.label)
.width(self.width)
.size(self.text_size.unwrap_or(renderer.default_size())),
)
.push(Text::new(&self.label).width(self.width).size(
self.text_size.unwrap_or_else(|| renderer.default_size()),
))
.layout(renderer, limits)
}

View file

@ -36,7 +36,7 @@ where
/// Creates a vertical [`Rule`] with the given width.
pub fn vertical(width: u16) -> Self {
Rule {
width: Length::from(Length::Units(width)),
width: Length::Units(width),
height: Length::Fill,
is_horizontal: false,
style: Default::default(),

View file

@ -303,7 +303,7 @@ pub fn draw<T, R>(
HandleShape::Rectangle {
width,
border_radius,
} => (f32::from(width), f32::from(bounds.height), border_radius),
} => (f32::from(width), bounds.height, border_radius),
};
let value = value.into() as f32;
@ -447,7 +447,7 @@ where
_viewport: &Rectangle,
_renderer: &Renderer,
) -> mouse::Interaction {
mouse_interaction(layout, cursor_position, &self.state)
mouse_interaction(layout, cursor_position, self.state)
}
}

View file

@ -131,7 +131,7 @@ where
) -> layout::Node {
let limits = limits.width(self.width).height(self.height);
let size = self.size.unwrap_or(renderer.default_size());
let size = self.size.unwrap_or_else(|| renderer.default_size());
let bounds = limits.max();
@ -205,7 +205,7 @@ pub fn draw<Renderer>(
renderer.fill_text(crate::text::Text {
content,
size: f32::from(size.unwrap_or(renderer.default_size())),
size: f32::from(size.unwrap_or_else(|| renderer.default_size())),
bounds: Rectangle { x, y, ..bounds },
color: appearance.color.unwrap_or(style.text_color),
font,

View file

@ -198,7 +198,7 @@ pub fn layout<Renderer>(
where
Renderer: text::Renderer,
{
let text_size = size.unwrap_or(renderer.default_size());
let text_size = size.unwrap_or_else(|| renderer.default_size());
let limits = limits
.pad(padding)
@ -498,7 +498,7 @@ where
None => {
let content: String = clipboard
.read()
.unwrap_or(String::new())
.unwrap_or_default()
.chars()
.filter(|c| !c.is_control())
.collect();
@ -597,7 +597,7 @@ pub fn draw<Renderer>(
Renderer::Theme: StyleSheet,
{
let secure_value = is_secure.then(|| value.secure());
let value = secure_value.as_ref().unwrap_or(&value);
let value = secure_value.as_ref().unwrap_or(value);
let bounds = layout.bounds();
let text_bounds = layout.children().next().unwrap().bounds();
@ -623,16 +623,16 @@ pub fn draw<Renderer>(
);
let text = value.to_string();
let size = size.unwrap_or(renderer.default_size());
let size = size.unwrap_or_else(|| renderer.default_size());
let (cursor, offset) = if state.is_focused() {
match state.cursor.state(&value) {
match state.cursor.state(value) {
cursor::State::Index(position) => {
let (text_value_width, offset) =
measure_cursor_and_scroll_offset(
renderer,
text_bounds,
&value,
value,
size,
position,
font.clone(),
@ -664,7 +664,7 @@ pub fn draw<Renderer>(
measure_cursor_and_scroll_offset(
renderer,
text_bounds,
&value,
value,
size,
left,
font.clone(),
@ -674,7 +674,7 @@ pub fn draw<Renderer>(
measure_cursor_and_scroll_offset(
renderer,
text_bounds,
&value,
value,
size,
right,
font.clone(),
@ -998,16 +998,16 @@ fn find_cursor_position<Renderer>(
where
Renderer: text::Renderer,
{
let size = size.unwrap_or(renderer.default_size());
let size = size.unwrap_or_else(|| renderer.default_size());
let offset =
offset(renderer, text_bounds, font.clone(), size, &value, &state);
offset(renderer, text_bounds, font.clone(), size, value, state);
renderer
.hit_test(
&value.to_string(),
size.into(),
font.clone(),
font,
Size::INFINITY,
Point::new(x + offset, text_bounds.height / 2.0),
true,

View file

@ -15,12 +15,9 @@ impl<'a> Editor<'a> {
}
pub fn insert(&mut self, character: char) {
match self.cursor.selection(self.value) {
Some((left, right)) => {
self.cursor.move_left(self.value);
self.value.remove_many(left, right);
}
_ => {}
if let Some((left, right)) = self.cursor.selection(self.value) {
self.cursor.move_left(self.value);
self.value.remove_many(left, right);
}
self.value.insert(self.cursor.end(self.value), character);
@ -29,13 +26,9 @@ impl<'a> Editor<'a> {
pub fn paste(&mut self, content: Value) {
let length = content.len();
match self.cursor.selection(self.value) {
Some((left, right)) => {
self.cursor.move_left(self.value);
self.value.remove_many(left, right);
}
_ => {}
if let Some((left, right)) = self.cursor.selection(self.value) {
self.cursor.move_left(self.value);
self.value.remove_many(left, right);
}
self.value.insert_many(self.cursor.end(self.value), content);

View file

@ -37,7 +37,7 @@ impl Value {
let previous_string =
&self.graphemes[..index.min(self.graphemes.len())].concat();
UnicodeSegmentation::split_word_bound_indices(&previous_string as &str)
UnicodeSegmentation::split_word_bound_indices(previous_string as &str)
.filter(|(_, word)| !word.trim_start().is_empty())
.next_back()
.map(|(i, previous_word)| {
@ -58,9 +58,8 @@ impl Value {
pub fn next_end_of_word(&self, index: usize) -> usize {
let next_string = &self.graphemes[index..].concat();
UnicodeSegmentation::split_word_bound_indices(&next_string as &str)
.filter(|(_, word)| !word.trim_start().is_empty())
.next()
UnicodeSegmentation::split_word_bound_indices(next_string as &str)
.find(|(_, word)| !word.trim_start().is_empty())
.map(|(i, next_word)| {
index
+ UnicodeSegmentation::graphemes(next_word, true).count()

View file

@ -162,7 +162,10 @@ where
.horizontal_alignment(self.text_alignment)
.font(self.font.clone())
.width(self.width)
.size(self.text_size.unwrap_or(renderer.default_size())),
.size(
self.text_size
.unwrap_or_else(|| renderer.default_size()),
),
);
}
@ -239,7 +242,7 @@ where
renderer,
style,
label_layout,
&label,
label,
self.text_size,
self.font.clone(),
Default::default(),

View file

@ -146,7 +146,7 @@ where
content: impl Into<Element<'a, Message, Renderer>>,
) -> Self {
let element = content.into();
let _ = state.diff(&element);
state.diff(&element);
Self { state, element }
}

View file

@ -143,7 +143,7 @@ where
self.padding,
self.text_size,
&self.font,
self.placeholder.as_ref().map(String::as_str),
self.placeholder.as_deref(),
&self.options,
)
}
@ -199,7 +199,7 @@ where
self.padding,
self.text_size,
&self.font,
self.placeholder.as_ref().map(String::as_str),
self.placeholder.as_deref(),
self.selected.as_ref(),
self.style,
)

View file

@ -93,7 +93,7 @@ impl Backend {
&layer,
staging_belt,
encoder,
&frame,
frame,
target_size.width,
target_size.height,
);

View file

@ -236,7 +236,7 @@ impl Pipeline {
entries: &[wgpu::BindGroupEntry {
binding: 0,
resource: wgpu::BindingResource::TextureView(
&texture_atlas.view(),
texture_atlas.view(),
),
}],
});
@ -264,7 +264,7 @@ impl Pipeline {
#[cfg(feature = "image_rs")]
pub fn dimensions(&self, handle: &image::Handle) -> (u32, u32) {
let mut cache = self.raster_cache.borrow_mut();
let memory = cache.load(&handle);
let memory = cache.load(handle);
memory.dimensions()
}
@ -272,7 +272,7 @@ impl Pipeline {
#[cfg(feature = "svg")]
pub fn viewport_dimensions(&self, handle: &svg::Handle) -> (u32, u32) {
let mut cache = self.vector_cache.borrow_mut();
let svg = cache.load(&handle);
let svg = cache.load(handle);
svg.viewport_dimensions()
}
@ -358,7 +358,7 @@ impl Pipeline {
entries: &[wgpu::BindGroupEntry {
binding: 0,
resource: wgpu::BindingResource::TextureView(
&self.texture_atlas.view(),
self.texture_atlas.view(),
),
}],
});

View file

@ -118,7 +118,7 @@ impl Atlas {
height,
padding,
0,
&allocation,
allocation,
encoder,
);
}

View file

@ -9,9 +9,6 @@ pub enum Layer {
impl Layer {
pub fn is_empty(&self) -> bool {
match self {
Layer::Empty => true,
_ => false,
}
matches!(self, Layer::Empty)
}
}

View file

@ -59,7 +59,7 @@ impl Cache {
}
}
image::Data::Bytes(bytes) => {
if let Ok(image) = image_rs::load_from_memory(&bytes) {
if let Ok(image) = image_rs::load_from_memory(bytes) {
let operation =
Operation::from_exif(&mut std::io::Cursor::new(bytes))
.ok()

View file

@ -60,7 +60,7 @@ impl Cache {
}
svg::Data::Bytes(bytes) => {
match usvg::Tree::from_data(
&bytes,
bytes,
&usvg::Options::default().to_ref(),
) {
Ok(tree) => Svg::Loaded(tree),
@ -112,7 +112,7 @@ impl Cache {
// It would be cool to be able to smooth resize the `svg` example.
let mut img = tiny_skia::Pixmap::new(width, height)?;
let _ = resvg::render(
resvg::render(
tree,
if width > height {
usvg::FitTo::Width(width)

View file

@ -188,7 +188,8 @@ impl Pipeline {
}
b_count += utf8_len;
}
return byte_index;
byte_index
};
if !nearest_only {

View file

@ -173,9 +173,7 @@ impl Pipeline {
},
depth_stencil: None,
multisample: wgpu::MultisampleState {
count: u32::from(
antialiasing.map(|a| a.sample_count()).unwrap_or(1),
),
count: antialiasing.map(|a| a.sample_count()).unwrap_or(1),
mask: !0,
alpha_to_coverage_enabled: false,
},
@ -272,47 +270,43 @@ impl Pipeline {
let vertices = bytemuck::cast_slice(&mesh.buffers.vertices);
let indices = bytemuck::cast_slice(&mesh.buffers.indices);
match (
if let (Some(vertices_size), Some(indices_size)) = (
wgpu::BufferSize::new(vertices.len() as u64),
wgpu::BufferSize::new(indices.len() as u64),
) {
(Some(vertices_size), Some(indices_size)) => {
{
let mut vertex_buffer = staging_belt.write_buffer(
encoder,
&self.vertex_buffer.raw,
(std::mem::size_of::<Vertex2D>() * last_vertex)
as u64,
vertices_size,
device,
);
{
let mut vertex_buffer = staging_belt.write_buffer(
encoder,
&self.vertex_buffer.raw,
(std::mem::size_of::<Vertex2D>() * last_vertex) as u64,
vertices_size,
device,
);
vertex_buffer.copy_from_slice(vertices);
}
{
let mut index_buffer = staging_belt.write_buffer(
encoder,
&self.index_buffer.raw,
(std::mem::size_of::<u32>() * last_index) as u64,
indices_size,
device,
);
index_buffer.copy_from_slice(indices);
}
uniforms.push(transform);
offsets.push((
last_vertex as u64,
last_index as u64,
mesh.buffers.indices.len(),
));
last_vertex += mesh.buffers.vertices.len();
last_index += mesh.buffers.indices.len();
vertex_buffer.copy_from_slice(vertices);
}
_ => {}
{
let mut index_buffer = staging_belt.write_buffer(
encoder,
&self.index_buffer.raw,
(std::mem::size_of::<u32>() * last_index) as u64,
indices_size,
device,
);
index_buffer.copy_from_slice(indices);
}
uniforms.push(transform);
offsets.push((
last_vertex as u64,
last_index as u64,
mesh.buffers.indices.len(),
));
last_vertex += mesh.buffers.vertices.len();
last_index += mesh.buffers.indices.len();
}
}

View file

@ -134,7 +134,7 @@ impl Blit {
match &mut self.targets {
None => {
self.targets = Some(Targets::new(
&device,
device,
self.format,
&self.texture_layout,
self.sample_count,
@ -145,7 +145,7 @@ impl Blit {
Some(targets) => {
if targets.width != width || targets.height != height {
self.targets = Some(Targets::new(
&device,
device,
self.format,
&self.texture_layout,
self.sample_count,

View file

@ -225,7 +225,7 @@ impl<Theme> iced_graphics::window::Compositor for Compositor<Theme> {
renderer.with_primitives(|backend, primitives| {
backend.present(
&mut self.device,
&self.device,
&mut self.staging_belt,
&mut encoder,
view,

View file

@ -647,7 +647,7 @@ mod platform {
{
use winit::platform::run_return::EventLoopExtRunReturn;
let _ = event_loop.run_return(event_handler);
event_loop.run_return(event_handler);
Ok(())
}

View file

@ -485,10 +485,10 @@ pub fn key_code(
// As defined in: http://www.unicode.org/faq/private_use.html
pub(crate) fn is_private_use_character(c: char) -> bool {
match c {
matches!(
c,
'\u{E000}'..='\u{F8FF}'
| '\u{F0000}'..='\u{FFFFD}'
| '\u{100000}'..='\u{10FFFD}' => true,
_ => false,
}
| '\u{100000}'..='\u{10FFFD}'
)
}

View file

@ -24,7 +24,7 @@ pub(crate) fn information(
let memory_used = sysinfo::get_current_pid()
.and_then(|pid| system.process(pid).ok_or("Process not found"))
.and_then(|process| Ok(process.memory()))
.map(|process| process.memory())
.ok();
Information {