Skip to content

Commit

Permalink
Address Clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyMeilex authored and hecrj committed Jul 9, 2022
1 parent e053e25 commit 15f794b
Show file tree
Hide file tree
Showing 43 changed files with 148 additions and 173 deletions.
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
too-many-arguments-threshold = 20
6 changes: 1 addition & 5 deletions futures/src/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
2 changes: 1 addition & 1 deletion futures/src/subscription/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion glow/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 4 additions & 6 deletions glow/src/quad/compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion glow/src/quad/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions glow/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -180,7 +180,8 @@ impl Pipeline {
}
b_count += utf8_len;
}
return byte_index;

byte_index
};

if !nearest_only {
Expand Down
4 changes: 2 additions & 2 deletions graphics/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,15 @@ impl<'a> Layer<'a> {
Self::process_primitive(
layers,
translation + *new_translation,
&content,
content,
current_layer,
);
}
Primitive::Cached { cache } => {
Self::process_primitive(
layers,
translation,
&cache,
cache,
current_layer,
);
}
Expand Down
5 changes: 2 additions & 3 deletions graphics/src/widget/canvas/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
},
);
Expand Down
2 changes: 1 addition & 1 deletion graphics/src/widget/canvas/path/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
5 changes: 1 addition & 4 deletions graphics/src/widget/qr_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 1 addition & 7 deletions native/src/hasher.rs
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
22 changes: 13 additions & 9 deletions native/src/overlay/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ where

Self {
container,
width: width,
width,
target_height,
style: style,
style,
}
}
}
Expand Down Expand Up @@ -230,7 +230,7 @@ where
shell: &mut Shell<'_, Message>,
) -> event::Status {
self.container.on_event(
event.clone(),
event,
layout,
cursor_position,
renderer,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion native/src/program/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion native/src/user_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion native/src/widget/checkbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions native/src/widget/pane_grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
20 changes: 7 additions & 13 deletions native/src/widget/pane_grid/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions native/src/widget/pane_grid/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 6 additions & 7 deletions native/src/widget/pick_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
)
}
Expand Down Expand Up @@ -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,
)
Expand Down
8 changes: 3 additions & 5 deletions native/src/widget/radio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion native/src/widget/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions native/src/widget/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
}
}

Expand Down
Loading

0 comments on commit 15f794b

Please sign in to comment.