Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some clippy::pedantic lints #2096

Merged
merged 11 commits into from
Sep 20, 2023
Merged
47 changes: 47 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[alias]
lint = """
clippy --workspace --no-deps -- \
-D warnings \
-D clippy::semicolon_if_nothing_returned \
-D clippy::trivially-copy-pass-by-ref \
-D clippy::default_trait_access \
-D clippy::match-wildcard-for-single-variants \
-D clippy::redundant-closure-for-method-calls \
-D clippy::filter_map_next \
-D clippy::manual_let_else \
-D clippy::unused_async
"""

nitpick = """
clippy --workspace --no-deps -- \
-D warnings \
-D clippy::pedantic \
-A clippy::must_use_candidate \
-A clippy::return_self_not_must_use \
-A clippy::needless_pass_by_value \
-A clippy::cast_precision_loss \
-A clippy::cast_sign_loss \
-A clippy::cast_possible_truncation \
-A clippy::match_same_arms \
-A clippy::missing-errors-doc \
-A clippy::missing-panics-doc \
-A clippy::cast_lossless \
-A clippy::doc_markdown \
-A clippy::items_after_statements \
-A clippy::too_many_lines \
-A clippy::module_name_repetitions \
-A clippy::if_not_else \
-A clippy::redundant_else \
-A clippy::used_underscore_binding \
-A clippy::cast_possible_wrap \
-A clippy::unnecessary_wraps \
-A clippy::struct-excessive-bools \
-A clippy::float-cmp \
-A clippy::single_match_else \
-A clippy::unreadable_literal \
-A clippy::explicit_deref_methods \
-A clippy::map_unwrap_or \
-A clippy::unnested_or_patterns \
-A clippy::similar_names \
-A clippy::unused_self
"""
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ jobs:
components: clippy
- uses: actions/checkout@master
- name: Check lints
run: cargo clippy --workspace --all-features --all-targets --no-deps -- -D warnings
run: cargo lint
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ target/
pkg/
**/*.rs.bk
Cargo.lock
.cargo/
dist/
traces/
6 changes: 3 additions & 3 deletions core/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ where
}

fn diff(&self, tree: &mut Tree) {
self.widget.diff(tree)
self.widget.diff(tree);
}

fn width(&self) -> Length {
Expand Down Expand Up @@ -418,7 +418,7 @@ where
viewport: &Rectangle,
) {
self.widget
.draw(tree, renderer, theme, style, layout, cursor, viewport)
.draw(tree, renderer, theme, style, layout, cursor, viewport);
}

fn mouse_interaction(
Expand Down Expand Up @@ -508,7 +508,7 @@ where
) {
self.element
.widget
.operate(state, layout, renderer, operation)
.operate(state, layout, renderer, operation);
}

fn on_event(
Expand Down
2 changes: 1 addition & 1 deletion core/src/gradient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl Linear {
stops: impl IntoIterator<Item = ColorStop>,
) -> Self {
for stop in stops {
self = self.add_stop(stop.offset, stop.color)
self = self.add_stop(stop.offset, stop.color);
}

self
Expand Down
2 changes: 1 addition & 1 deletion core/src/hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub struct Hasher(twox_hash::XxHash64);

impl core::hash::Hasher for Hasher {
fn write(&mut self, bytes: &[u8]) {
self.0.write(bytes)
self.0.write(bytes);
}

fn finish(&self) -> u64 {
Expand Down
2 changes: 1 addition & 1 deletion core/src/mouse/click.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub enum Kind {
}

impl Kind {
fn next(&self) -> Kind {
fn next(self) -> Kind {
match self {
Kind::Single => Kind::Double,
Kind::Double => Kind::Triple,
Expand Down
6 changes: 3 additions & 3 deletions core/src/overlay/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ where
layout: Layout<'_>,
cursor: mouse::Cursor,
) {
self.overlay.draw(renderer, theme, style, layout, cursor)
self.overlay.draw(renderer, theme, style, layout, cursor);
}

/// Applies a [`widget::Operation`] to the [`Element`].
Expand Down Expand Up @@ -205,7 +205,7 @@ where
state: &mut dyn widget::operation::TextInput,
id: Option<&widget::Id>,
) {
self.operation.text_input(state, id)
self.operation.text_input(state, id);
}

fn custom(&mut self, state: &mut dyn Any, id: Option<&widget::Id>) {
Expand Down Expand Up @@ -262,7 +262,7 @@ where
layout: Layout<'_>,
cursor: mouse::Cursor,
) {
self.content.draw(renderer, theme, style, layout, cursor)
self.content.draw(renderer, theme, style, layout, cursor);
}

fn is_over(
Expand Down
2 changes: 1 addition & 1 deletion core/src/overlay/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ where
|(child, layout)| {
child.operate(layout, renderer, operation);
},
)
);
});
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl<'a, Message> Shell<'a, Message> {
if self.is_layout_invalid {
self.is_layout_invalid = false;

f()
f();
}
}

Expand Down
10 changes: 5 additions & 5 deletions core/src/widget/operation/focusable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn focus<T>(target: Id) -> impl Operation<T> {
_bounds: Rectangle,
operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
) {
operate_on_children(self)
operate_on_children(self);
}
}

Expand Down Expand Up @@ -85,7 +85,7 @@ where
_bounds: Rectangle,
operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
) {
operate_on_children(self)
operate_on_children(self);
}

fn finish(&self) -> Outcome<T> {
Expand Down Expand Up @@ -132,7 +132,7 @@ pub fn focus_previous<T>() -> impl Operation<T> {
_bounds: Rectangle,
operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
) {
operate_on_children(self)
operate_on_children(self);
}
}

Expand Down Expand Up @@ -166,7 +166,7 @@ pub fn focus_next<T>() -> impl Operation<T> {
_bounds: Rectangle,
operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
) {
operate_on_children(self)
operate_on_children(self);
}
}

Expand All @@ -193,7 +193,7 @@ pub fn find_focused() -> impl Operation<Id> {
_bounds: Rectangle,
operate_on_children: &mut dyn FnMut(&mut dyn Operation<Id>),
) {
operate_on_children(self)
operate_on_children(self);
}

fn finish(&self) -> Outcome<Id> {
Expand Down
4 changes: 2 additions & 2 deletions core/src/widget/operation/scrollable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn snap_to<T>(target: Id, offset: RelativeOffset) -> impl Operation<T> {
_bounds: Rectangle,
operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
) {
operate_on_children(self)
operate_on_children(self);
}

fn scrollable(
Expand Down Expand Up @@ -60,7 +60,7 @@ pub fn scroll_to<T>(target: Id, offset: AbsoluteOffset) -> impl Operation<T> {
_bounds: Rectangle,
operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
) {
operate_on_children(self)
operate_on_children(self);
}

fn scrollable(
Expand Down
8 changes: 4 additions & 4 deletions core/src/widget/operation/text_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn move_cursor_to_front<T>(target: Id) -> impl Operation<T> {
_bounds: Rectangle,
operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
) {
operate_on_children(self)
operate_on_children(self);
}
}

Expand Down Expand Up @@ -68,7 +68,7 @@ pub fn move_cursor_to_end<T>(target: Id) -> impl Operation<T> {
_bounds: Rectangle,
operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
) {
operate_on_children(self)
operate_on_children(self);
}
}

Expand Down Expand Up @@ -99,7 +99,7 @@ pub fn move_cursor_to<T>(target: Id, position: usize) -> impl Operation<T> {
_bounds: Rectangle,
operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
) {
operate_on_children(self)
operate_on_children(self);
}
}

Expand Down Expand Up @@ -128,7 +128,7 @@ pub fn select_all<T>(target: Id) -> impl Operation<T> {
_bounds: Rectangle,
operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
) {
operate_on_children(self)
operate_on_children(self);
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/widget/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Tree {
Renderer: crate::Renderer,
{
if self.tag == new.borrow().tag() {
new.borrow().diff(self)
new.borrow().diff(self);
} else {
*self = Self::new(new);
}
Expand All @@ -78,7 +78,7 @@ impl Tree {
new_children,
|tree, widget| tree.diff(widget.borrow()),
|widget| Self::new(widget.borrow()),
)
);
}

/// Reconciliates the children of the tree with the provided list of widgets using custom
Expand Down
2 changes: 1 addition & 1 deletion examples/arc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Application for Arc {
(
Arc {
start: Instant::now(),
cache: Default::default(),
cache: Cache::default(),
},
Command::none(),
)
Expand Down
11 changes: 4 additions & 7 deletions examples/bezier_tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ mod bezier {
}

pub fn request_redraw(&mut self) {
self.cache.clear()
self.cache.clear();
}
}

Expand All @@ -100,12 +100,9 @@ mod bezier {
bounds: Rectangle,
cursor: mouse::Cursor,
) -> (event::Status, Option<Curve>) {
let cursor_position =
if let Some(position) = cursor.position_in(bounds) {
position
} else {
return (event::Status::Ignored, None);
};
let Some(cursor_position) = cursor.position_in(bounds) else {
return (event::Status::Ignored, None);
};

match event {
Event::Mouse(mouse_event) => {
Expand Down
4 changes: 2 additions & 2 deletions examples/clock/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Application for Clock {
Clock {
now: time::OffsetDateTime::now_local()
.unwrap_or_else(|_| time::OffsetDateTime::now_utc()),
clock: Default::default(),
clock: Cache::default(),
},
Command::none(),
)
Expand Down Expand Up @@ -141,7 +141,7 @@ impl<Message> canvas::Program<Message, Renderer> for Clock {
frame.with_save(|frame| {
frame.rotate(hand_rotation(self.now.second(), 60));
frame.stroke(&long_hand, thin_stroke());
})
});
});

vec![clock]
Expand Down
2 changes: 1 addition & 1 deletion examples/download_progress/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl Download {
| State::Errored { .. } => {
self.state = State::Downloading { progress: 0.0 };
}
_ => {}
State::Downloading { .. } => {}
}
}

Expand Down
13 changes: 5 additions & 8 deletions examples/game_of_life/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,12 +406,9 @@ mod grid {
*interaction = Interaction::None;
}

let cursor_position =
if let Some(position) = cursor.position_in(bounds) {
position
} else {
return (event::Status::Ignored, None);
};
let Some(cursor_position) = cursor.position_in(bounds) else {
return (event::Status::Ignored, None);
};

let cell = Cell::at(self.project(cursor_position, bounds.size()));
let is_populated = self.state.contains(&cell);
Expand Down Expand Up @@ -472,7 +469,7 @@ mod grid {
* (1.0 / self.scaling),
))
}
_ => None,
Interaction::None => None,
};

let event_status = match interaction {
Expand Down Expand Up @@ -676,7 +673,7 @@ mod grid {
Interaction::None if cursor.is_over(bounds) => {
mouse::Interaction::Crosshair
}
_ => mouse::Interaction::default(),
Interaction::None => mouse::Interaction::default(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/integration/src/controls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl Controls {
pub fn new() -> Controls {
Controls {
background_color: Color::BLACK,
text: Default::default(),
text: String::default(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/integration/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {

{
// We clear the frame
let mut render_pass = scene.clear(
let mut render_pass = Scene::clear(
&view,
&mut encoder,
program.background_color(),
Expand Down
1 change: 0 additions & 1 deletion examples/integration/src/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ impl Scene {
}

pub fn clear<'a>(
&self,
target: &'a wgpu::TextureView,
encoder: &'a mut wgpu::CommandEncoder,
background_color: Color,
Expand Down
Loading