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

Address Clippy lints #1379

Merged
merged 6 commits into from
Jul 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Lint
on: [push, pull_request]
jobs:
all:
runs-on: ubuntu-latest
steps:
- uses: hecrj/setup-rust-action@v1
with:
components: clippy
- uses: actions/checkout@master
- name: Check lints
run: cargo clippy --all --all-features --no-deps
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
2 changes: 1 addition & 1 deletion core/src/keyboard/modifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ bitflags! {
#[derive(Default)]
pub struct Modifiers: u32{
/// The "shift" key.
const SHIFT = 0b100 << 0;
const SHIFT = 0b100;
// const LSHIFT = 0b010 << 0;
// const RSHIFT = 0b001 << 0;
//
Expand Down
17 changes: 12 additions & 5 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@
#![doc(
html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
)]
#![deny(missing_docs)]
#![deny(missing_debug_implementations)]
#![deny(unused_results)]
#![forbid(unsafe_code)]
#![forbid(rust_2018_idioms)]
#![deny(
missing_debug_implementations,
missing_docs,
unused_results,
clippy::extra_unused_lifetimes,
clippy::from_over_into,
clippy::needless_borrow,
clippy::new_without_default,
clippy::useless_conversion
)]
#![forbid(unsafe_code, rust_2018_idioms)]
#![allow(clippy::inherent_to_string, clippy::type_complexity)]
pub mod alignment;
pub mod keyboard;
pub mod mouse;
Expand Down
2 changes: 1 addition & 1 deletion examples/color_palette/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Sandbox for ColorPalette {
}

#[derive(Debug)]
pub struct Theme {
struct Theme {
lower: Vec<Color>,
base: Color,
higher: Vec<Color>,
Expand Down
3 changes: 1 addition & 2 deletions examples/component/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ mod numeric_input {
self.value
.as_ref()
.map(u32::to_string)
.as_ref()
.map(String::as_str)
.as_deref()
.unwrap_or(""),
Event::InputChanged,
)
Expand Down
6 changes: 3 additions & 3 deletions examples/custom_widget/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ mod circle {
}
}

impl<'a, Message, Renderer> Into<Element<'a, Message, Renderer>> for Circle
impl<'a, Message, Renderer> From<Circle> for Element<'a, Message, Renderer>
where
Renderer: renderer::Renderer,
{
fn into(self) -> Element<'a, Message, Renderer> {
Element::new(self)
fn from(circle: Circle) -> Self {
Self::new(circle)
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions examples/download_progress/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Application for Example {
fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::Add => {
self.last_id = self.last_id + 1;
self.last_id += 1;

self.downloads.push(Download::new(self.last_id));
}
Expand Down Expand Up @@ -134,8 +134,8 @@ impl Download {
}

pub fn progress(&mut self, new_progress: download::Progress) {
match &mut self.state {
State::Downloading { progress } => match new_progress {
if let State::Downloading { progress } = &mut self.state {
match new_progress {
download::Progress::Started => {
*progress = 0.0;
}
Expand All @@ -152,8 +152,7 @@ impl Download {
button: button::State::new(),
};
}
},
_ => {}
}
}
}

Expand Down
10 changes: 5 additions & 5 deletions examples/game_of_life/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ mod grid {
}
}

pub fn view<'a>(&'a mut self) -> Element<'a, Message> {
pub fn view(&mut self) -> Element<Message> {
Canvas::new(self)
.width(Length::Fill)
.height(Length::Fill)
Expand Down Expand Up @@ -328,7 +328,7 @@ mod grid {
}
}

impl<'a> canvas::Program<Message> for Grid {
impl canvas::Program<Message> for Grid {
fn update(
&mut self,
event: Event,
Expand Down Expand Up @@ -826,13 +826,13 @@ struct Controls {
}

impl Controls {
fn view<'a>(
&'a mut self,
fn view(
&mut self,
is_playing: bool,
is_grid_enabled: bool,
speed: usize,
preset: Preset,
) -> Element<'a, Message> {
) -> Element<Message> {
let playback_controls = Row::new()
.spacing(10)
.push(
Expand Down
10 changes: 5 additions & 5 deletions examples/game_of_life/src/preset.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Preset {
Custom,
XKCD,
Xkcd,
Glider,
SmallExploder,
Exploder,
Expand All @@ -14,7 +14,7 @@ pub enum Preset {

pub static ALL: &[Preset] = &[
Preset::Custom,
Preset::XKCD,
Preset::Xkcd,
Preset::Glider,
Preset::SmallExploder,
Preset::Exploder,
Expand All @@ -30,7 +30,7 @@ impl Preset {
#[rustfmt::skip]
let cells = match self {
Preset::Custom => vec![],
Preset::XKCD => vec![
Preset::Xkcd => vec![
" xxx ",
" x x ",
" x x ",
Expand Down Expand Up @@ -116,7 +116,7 @@ impl Preset {

impl Default for Preset {
fn default() -> Preset {
Preset::XKCD
Preset::Xkcd
}
}

Expand All @@ -127,7 +127,7 @@ impl std::fmt::Display for Preset {
"{}",
match self {
Preset::Custom => "Custom",
Preset::XKCD => "xkcd #2293",
Preset::Xkcd => "xkcd #2293",
Preset::Glider => "Glider",
Preset::SmallExploder => "Small Exploder",
Preset::Exploder => "Exploder",
Expand Down
7 changes: 4 additions & 3 deletions examples/geometry/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod rainbow {
layout, Element, Layout, Length, Point, Rectangle, Size, Vector, Widget,
};

#[derive(Default)]
pub struct Rainbow;

impl Rainbow {
Expand Down Expand Up @@ -148,12 +149,12 @@ mod rainbow {
}
}

impl<'a, Message, B, T> Into<Element<'a, Message, Renderer<B, T>>> for Rainbow
impl<'a, Message, B, T> From<Rainbow> for Element<'a, Message, Renderer<B, T>>
where
B: Backend,
{
fn into(self) -> Element<'a, Message, Renderer<B, T>> {
Element::new(self)
fn from(rainbow: Rainbow) -> Self {
Self::new(rainbow)
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions examples/integration_opengl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn main() {

let mut cursor_position = PhysicalPosition::new(-1.0, -1.0);
let mut modifiers = ModifiersState::default();
let mut clipboard = Clipboard::connect(&windowed_context.window());
let mut clipboard = Clipboard::connect(windowed_context.window());

let mut renderer = Renderer::new(Backend::new(&gl, Settings::default()));

Expand All @@ -73,13 +73,12 @@ pub fn main() {
);
let mut resized = false;

let scene = Scene::new(&gl, &shader_version);
let scene = Scene::new(&gl, shader_version);

event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;

match event {
Event::LoopDestroyed => return,
Event::WindowEvent { event, .. } => {
match event {
WindowEvent::CursorMoved { position, .. } => {
Expand Down
2 changes: 1 addition & 1 deletion examples/integration_wgpu/src/controls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl Program for Controls {
t,
"Placeholder",
text,
move |text| Message::TextChanged(text),
Message::TextChanged,
)),
),
)
Expand Down
10 changes: 5 additions & 5 deletions examples/integration_wgpu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn main() {
let instance = wgpu::Instance::new(backend);
let surface = unsafe { instance.create_surface(&window) };

let (format, (mut device, queue)) = futures::executor::block_on(async {
let (format, (device, queue)) = futures::executor::block_on(async {
let adapter = wgpu::util::initialize_adapter_from_env_or_default(
&instance,
backend,
Expand Down Expand Up @@ -128,13 +128,13 @@ pub fn main() {
let mut staging_belt = wgpu::util::StagingBelt::new(5 * 1024);

// Initialize scene and GUI controls
let scene = Scene::new(&mut device, format);
let scene = Scene::new(&device, format);
let controls = Controls::new();

// Initialize iced
let mut debug = Debug::new();
let mut renderer =
Renderer::new(Backend::new(&mut device, Settings::default(), format));
Renderer::new(Backend::new(&device, Settings::default(), format));

let mut state = program::State::new(
controls,
Expand Down Expand Up @@ -208,8 +208,8 @@ pub fn main() {
surface.configure(
&device,
&wgpu::SurfaceConfiguration {
format,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: format,
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::AutoVsync,
Expand Down Expand Up @@ -244,7 +244,7 @@ pub fn main() {
// And then iced on top
renderer.with_primitives(|backend, primitive| {
backend.present(
&mut device,
&device,
&mut staging_belt,
&mut encoder,
&view,
Expand Down
69 changes: 33 additions & 36 deletions examples/integration_wgpu/src/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,40 +66,37 @@ fn build_pipeline(
bind_group_layouts: &[],
});

let pipeline =
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: None,
layout: Some(&pipeline_layout),
vertex: wgpu::VertexState {
module: &vs_module,
entry_point: "main",
buffers: &[],
},
fragment: Some(wgpu::FragmentState {
module: &fs_module,
entry_point: "main",
targets: &[Some(wgpu::ColorTargetState {
format: texture_format,
blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent::REPLACE,
alpha: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
front_face: wgpu::FrontFace::Ccw,
..Default::default()
},
depth_stencil: None,
multisample: wgpu::MultisampleState {
count: 1,
mask: !0,
alpha_to_coverage_enabled: false,
},
multiview: None,
});

pipeline
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: None,
layout: Some(&pipeline_layout),
vertex: wgpu::VertexState {
module: &vs_module,
entry_point: "main",
buffers: &[],
},
fragment: Some(wgpu::FragmentState {
module: &fs_module,
entry_point: "main",
targets: &[Some(wgpu::ColorTargetState {
format: texture_format,
blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent::REPLACE,
alpha: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
front_face: wgpu::FrontFace::Ccw,
..Default::default()
},
depth_stencil: None,
multisample: wgpu::MultisampleState {
count: 1,
mask: !0,
alpha_to_coverage_enabled: false,
},
multiview: None,
})
}
3 changes: 1 addition & 2 deletions examples/pokedex/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ impl Pokemon {
let description = entry
.flavor_text_entries
.iter()
.filter(|text| text.language.name == "en")
.next()
.find(|text| text.language.name == "en")
.ok_or(Error::LanguageError)?;

Ok(Pokemon {
Expand Down
3 changes: 1 addition & 2 deletions examples/pure/component/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ mod numeric_input {
self.value
.as_ref()
.map(u32::to_string)
.as_ref()
.map(String::as_str)
.as_deref()
.unwrap_or(""),
Event::InputChanged,
)
Expand Down
2 changes: 1 addition & 1 deletion examples/pure/game_of_life/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ mod grid {
}
}

pub fn view<'a>(&'a self) -> Element<'a, Message> {
pub fn view(&self) -> Element<Message> {
Canvas::new(self)
.width(Length::Fill)
.height(Length::Fill)
Expand Down
Loading