diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000000..688c208761 --- /dev/null +++ b/.github/workflows/lint.yml @@ -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 diff --git a/clippy.toml b/clippy.toml new file mode 100644 index 0000000000..0d4e02f0b0 --- /dev/null +++ b/clippy.toml @@ -0,0 +1 @@ +too-many-arguments-threshold = 20 diff --git a/core/src/keyboard/modifiers.rs b/core/src/keyboard/modifiers.rs index ff5b08f251..bbdd827270 100644 --- a/core/src/keyboard/modifiers.rs +++ b/core/src/keyboard/modifiers.rs @@ -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; // diff --git a/core/src/lib.rs b/core/src/lib.rs index 7b0dc57b5d..03ba8ccada 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -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; diff --git a/examples/color_palette/src/main.rs b/examples/color_palette/src/main.rs index 16c87a75c7..cc1af750a3 100644 --- a/examples/color_palette/src/main.rs +++ b/examples/color_palette/src/main.rs @@ -84,7 +84,7 @@ impl Sandbox for ColorPalette { } #[derive(Debug)] -pub struct Theme { +struct Theme { lower: Vec, base: Color, higher: Vec, diff --git a/examples/component/src/main.rs b/examples/component/src/main.rs index b6ff060076..6a8f53e21a 100644 --- a/examples/component/src/main.rs +++ b/examples/component/src/main.rs @@ -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, ) diff --git a/examples/custom_widget/src/main.rs b/examples/custom_widget/src/main.rs index ce5306ba08..d1a7bb065f 100644 --- a/examples/custom_widget/src/main.rs +++ b/examples/custom_widget/src/main.rs @@ -64,12 +64,12 @@ mod circle { } } - impl<'a, Message, Renderer> Into> for Circle + impl<'a, Message, Renderer> From 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) } } } diff --git a/examples/download_progress/src/main.rs b/examples/download_progress/src/main.rs index 4a801ba4d6..2999bc7e80 100644 --- a/examples/download_progress/src/main.rs +++ b/examples/download_progress/src/main.rs @@ -49,7 +49,7 @@ impl Application for Example { fn update(&mut self, message: Message) -> Command { match message { Message::Add => { - self.last_id = self.last_id + 1; + self.last_id += 1; self.downloads.push(Download::new(self.last_id)); } @@ -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; } @@ -152,8 +152,7 @@ impl Download { button: button::State::new(), }; } - }, - _ => {} + } } } diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs index 353995849d..62ecc2d158 100644 --- a/examples/game_of_life/src/main.rs +++ b/examples/game_of_life/src/main.rs @@ -280,7 +280,7 @@ mod grid { } } - pub fn view<'a>(&'a mut self) -> Element<'a, Message> { + pub fn view(&mut self) -> Element { Canvas::new(self) .width(Length::Fill) .height(Length::Fill) @@ -328,7 +328,7 @@ mod grid { } } - impl<'a> canvas::Program for Grid { + impl canvas::Program for Grid { fn update( &mut self, event: Event, @@ -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 { let playback_controls = Row::new() .spacing(10) .push( diff --git a/examples/game_of_life/src/preset.rs b/examples/game_of_life/src/preset.rs index 05157b6a96..964b912036 100644 --- a/examples/game_of_life/src/preset.rs +++ b/examples/game_of_life/src/preset.rs @@ -1,7 +1,7 @@ #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Preset { Custom, - XKCD, + Xkcd, Glider, SmallExploder, Exploder, @@ -14,7 +14,7 @@ pub enum Preset { pub static ALL: &[Preset] = &[ Preset::Custom, - Preset::XKCD, + Preset::Xkcd, Preset::Glider, Preset::SmallExploder, Preset::Exploder, @@ -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 ", @@ -116,7 +116,7 @@ impl Preset { impl Default for Preset { fn default() -> Preset { - Preset::XKCD + Preset::Xkcd } } @@ -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", diff --git a/examples/geometry/src/main.rs b/examples/geometry/src/main.rs index ba4b808e3d..03eac69ebc 100644 --- a/examples/geometry/src/main.rs +++ b/examples/geometry/src/main.rs @@ -17,6 +17,7 @@ mod rainbow { layout, Element, Layout, Length, Point, Rectangle, Size, Vector, Widget, }; + #[derive(Default)] pub struct Rainbow; impl Rainbow { @@ -148,12 +149,12 @@ mod rainbow { } } - impl<'a, Message, B, T> Into>> for Rainbow + impl<'a, Message, B, T> From for Element<'a, Message, Renderer> where B: Backend, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from(rainbow: Rainbow) -> Self { + Self::new(rainbow) } } } diff --git a/examples/integration_opengl/src/main.rs b/examples/integration_opengl/src/main.rs index 1a78a493fa..f161c8a0e0 100644 --- a/examples/integration_opengl/src/main.rs +++ b/examples/integration_opengl/src/main.rs @@ -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())); @@ -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, .. } => { diff --git a/examples/integration_wgpu/src/controls.rs b/examples/integration_wgpu/src/controls.rs index cb2c423f3c..2f1daa91dd 100644 --- a/examples/integration_wgpu/src/controls.rs +++ b/examples/integration_wgpu/src/controls.rs @@ -112,7 +112,7 @@ impl Program for Controls { t, "Placeholder", text, - move |text| Message::TextChanged(text), + Message::TextChanged, )), ), ) diff --git a/examples/integration_wgpu/src/main.rs b/examples/integration_wgpu/src/main.rs index 3d27a0f03a..86a0d6a481 100644 --- a/examples/integration_wgpu/src/main.rs +++ b/examples/integration_wgpu/src/main.rs @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/examples/integration_wgpu/src/scene.rs b/examples/integration_wgpu/src/scene.rs index af75e67c79..3e41fbda5a 100644 --- a/examples/integration_wgpu/src/scene.rs +++ b/examples/integration_wgpu/src/scene.rs @@ -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, + }) } diff --git a/examples/pokedex/src/main.rs b/examples/pokedex/src/main.rs index 89d865e4dc..a1cf68e82c 100644 --- a/examples/pokedex/src/main.rs +++ b/examples/pokedex/src/main.rs @@ -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 { diff --git a/examples/pure/component/src/main.rs b/examples/pure/component/src/main.rs index 64935afd8e..db22d019fb 100644 --- a/examples/pure/component/src/main.rs +++ b/examples/pure/component/src/main.rs @@ -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, ) diff --git a/examples/pure/game_of_life/src/main.rs b/examples/pure/game_of_life/src/main.rs index 851fbd47c7..cf6560d644 100644 --- a/examples/pure/game_of_life/src/main.rs +++ b/examples/pure/game_of_life/src/main.rs @@ -350,7 +350,7 @@ mod grid { } } - pub fn view<'a>(&'a self) -> Element<'a, Message> { + pub fn view(&self) -> Element { Canvas::new(self) .width(Length::Fill) .height(Length::Fill) diff --git a/examples/pure/game_of_life/src/preset.rs b/examples/pure/game_of_life/src/preset.rs index 05157b6a96..964b912036 100644 --- a/examples/pure/game_of_life/src/preset.rs +++ b/examples/pure/game_of_life/src/preset.rs @@ -1,7 +1,7 @@ #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Preset { Custom, - XKCD, + Xkcd, Glider, SmallExploder, Exploder, @@ -14,7 +14,7 @@ pub enum Preset { pub static ALL: &[Preset] = &[ Preset::Custom, - Preset::XKCD, + Preset::Xkcd, Preset::Glider, Preset::SmallExploder, Preset::Exploder, @@ -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 ", @@ -116,7 +116,7 @@ impl Preset { impl Default for Preset { fn default() -> Preset { - Preset::XKCD + Preset::Xkcd } } @@ -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", diff --git a/examples/pure/todos/src/main.rs b/examples/pure/todos/src/main.rs index 723386ad1b..9a74ea711e 100644 --- a/examples/pure/todos/src/main.rs +++ b/examples/pure/todos/src/main.rs @@ -167,7 +167,7 @@ impl Application for Todos { .size(30) .on_submit(Message::CreateTask); - let controls = view_controls(&tasks, *filter); + let controls = view_controls(tasks, *filter); let filtered_tasks = tasks.iter().filter(|task| filter.matches(task)); @@ -446,15 +446,15 @@ struct SavedState { #[derive(Debug, Clone)] enum LoadError { - FileError, - FormatError, + File, + Format, } #[derive(Debug, Clone)] enum SaveError { - FileError, - WriteError, - FormatError, + File, + Write, + Format, } #[cfg(not(target_arch = "wasm32"))] @@ -465,7 +465,7 @@ impl SavedState { { project_dirs.data_dir().into() } else { - std::env::current_dir().unwrap_or(std::path::PathBuf::new()) + std::env::current_dir().unwrap_or_default() }; path.push("todos.json"); @@ -480,37 +480,37 @@ impl SavedState { let mut file = async_std::fs::File::open(Self::path()) .await - .map_err(|_| LoadError::FileError)?; + .map_err(|_| LoadError::File)?; file.read_to_string(&mut contents) .await - .map_err(|_| LoadError::FileError)?; + .map_err(|_| LoadError::File)?; - serde_json::from_str(&contents).map_err(|_| LoadError::FormatError) + serde_json::from_str(&contents).map_err(|_| LoadError::Format) } async fn save(self) -> Result<(), SaveError> { use async_std::prelude::*; let json = serde_json::to_string_pretty(&self) - .map_err(|_| SaveError::FormatError)?; + .map_err(|_| SaveError::Format)?; let path = Self::path(); if let Some(dir) = path.parent() { async_std::fs::create_dir_all(dir) .await - .map_err(|_| SaveError::FileError)?; + .map_err(|_| SaveError::File)?; } { let mut file = async_std::fs::File::create(path) .await - .map_err(|_| SaveError::FileError)?; + .map_err(|_| SaveError::File)?; file.write_all(json.as_bytes()) .await - .map_err(|_| SaveError::WriteError)?; + .map_err(|_| SaveError::Write)?; } // This is a simple way to save at most once every couple seconds @@ -529,25 +529,25 @@ impl SavedState { } async fn load() -> Result { - let storage = Self::storage().ok_or(LoadError::FileError)?; + let storage = Self::storage().ok_or(LoadError::File)?; let contents = storage .get_item("state") - .map_err(|_| LoadError::FileError)? - .ok_or(LoadError::FileError)?; + .map_err(|_| LoadError::File)? + .ok_or(LoadError::File)?; - serde_json::from_str(&contents).map_err(|_| LoadError::FormatError) + serde_json::from_str(&contents).map_err(|_| LoadError::Format) } async fn save(self) -> Result<(), SaveError> { - let storage = Self::storage().ok_or(SaveError::FileError)?; + let storage = Self::storage().ok_or(SaveError::File)?; let json = serde_json::to_string_pretty(&self) - .map_err(|_| SaveError::FormatError)?; + .map_err(|_| SaveError::Format)?; storage .set_item("state", &json) - .map_err(|_| SaveError::WriteError)?; + .map_err(|_| SaveError::Write)?; let _ = wasm_timer::Delay::new(std::time::Duration::from_secs(2)).await; diff --git a/examples/pure/tour/src/main.rs b/examples/pure/tour/src/main.rs index 477a1ec7d3..05c269c37b 100644 --- a/examples/pure/tour/src/main.rs +++ b/examples/pure/tour/src/main.rs @@ -78,14 +78,6 @@ impl Sandbox for Tour { .push(controls) .into(); - let content = if self.debug { - // TODO - //content.explain(Color::BLACK) - content - } else { - content - }; - let scrollable = scrollable(container(content).width(Length::Fill).center_x()); @@ -494,7 +486,7 @@ impl<'a> Step { .push(ferris(width)) .push(slider(100..=500, width, StepMessage::ImageWidthChanged)) .push( - text(format!("Width: {} px", width.to_string())) + text(format!("Width: {} px", width)) .width(Length::Fill) .horizontal_alignment(alignment::Horizontal::Center), ) diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index cee9a02fda..fc53d8f7c2 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -65,8 +65,7 @@ impl Application for SolarSystem { } fn subscription(&self) -> Subscription { - time::every(std::time::Duration::from_millis(10)) - .map(|instant| Message::Tick(instant)) + time::every(std::time::Duration::from_millis(10)).map(Message::Tick) } fn view(&mut self) -> Element { diff --git a/examples/stopwatch/src/main.rs b/examples/stopwatch/src/main.rs index b83b92ecf9..b7c816ff3e 100644 --- a/examples/stopwatch/src/main.rs +++ b/examples/stopwatch/src/main.rs @@ -67,13 +67,12 @@ impl Application for Stopwatch { self.state = State::Idle; } }, - Message::Tick(now) => match &mut self.state { - State::Ticking { last_tick } => { + Message::Tick(now) => { + if let State::Ticking { last_tick } = &mut self.state { self.duration += now - *last_tick; *last_tick = now; } - _ => {} - }, + } Message::Reset => { self.duration = Duration::default(); } diff --git a/examples/system_information/src/main.rs b/examples/system_information/src/main.rs index 9e6a2f61dc..54fc635fa3 100644 --- a/examples/system_information/src/main.rs +++ b/examples/system_information/src/main.rs @@ -107,11 +107,8 @@ impl Application for Example { ByteSize::kb(information.memory_total).to_string(); let memory_total = Text::new(format!( - "Memory (total): {}", - format!( - "{} kb ({})", - information.memory_total, memory_readable - ) + "Memory (total): {} kb ({})", + information.memory_total, memory_readable )); let memory_text = if let Some(memory_used) = diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs index dc080ef52a..363e3fb802 100644 --- a/examples/todos/src/main.rs +++ b/examples/todos/src/main.rs @@ -168,7 +168,7 @@ impl Application for Todos { .size(30) .on_submit(Message::CreateTask); - let controls = controls.view(&tasks, *filter); + let controls = controls.view(tasks, *filter); let filtered_tasks = tasks.iter().filter(|task| filter.matches(task)); @@ -493,15 +493,15 @@ struct SavedState { #[derive(Debug, Clone)] enum LoadError { - FileError, - FormatError, + File, + Format, } #[derive(Debug, Clone)] enum SaveError { - FileError, - WriteError, - FormatError, + File, + Write, + Format, } #[cfg(not(target_arch = "wasm32"))] @@ -512,7 +512,7 @@ impl SavedState { { project_dirs.data_dir().into() } else { - std::env::current_dir().unwrap_or(std::path::PathBuf::new()) + std::env::current_dir().unwrap_or_default() }; path.push("todos.json"); @@ -527,37 +527,37 @@ impl SavedState { let mut file = async_std::fs::File::open(Self::path()) .await - .map_err(|_| LoadError::FileError)?; + .map_err(|_| LoadError::File)?; file.read_to_string(&mut contents) .await - .map_err(|_| LoadError::FileError)?; + .map_err(|_| LoadError::File)?; - serde_json::from_str(&contents).map_err(|_| LoadError::FormatError) + serde_json::from_str(&contents).map_err(|_| LoadError::Format) } async fn save(self) -> Result<(), SaveError> { use async_std::prelude::*; let json = serde_json::to_string_pretty(&self) - .map_err(|_| SaveError::FormatError)?; + .map_err(|_| SaveError::Format)?; let path = Self::path(); if let Some(dir) = path.parent() { async_std::fs::create_dir_all(dir) .await - .map_err(|_| SaveError::FileError)?; + .map_err(|_| SaveError::File)?; } { let mut file = async_std::fs::File::create(path) .await - .map_err(|_| SaveError::FileError)?; + .map_err(|_| SaveError::File)?; file.write_all(json.as_bytes()) .await - .map_err(|_| SaveError::WriteError)?; + .map_err(|_| SaveError::Write)?; } // This is a simple way to save at most once every couple seconds @@ -576,25 +576,25 @@ impl SavedState { } async fn load() -> Result { - let storage = Self::storage().ok_or(LoadError::FileError)?; + let storage = Self::storage().ok_or(LoadError::File)?; let contents = storage .get_item("state") - .map_err(|_| LoadError::FileError)? - .ok_or(LoadError::FileError)?; + .map_err(|_| LoadError::File)? + .ok_or(LoadError::File)?; - serde_json::from_str(&contents).map_err(|_| LoadError::FormatError) + serde_json::from_str(&contents).map_err(|_| LoadError::Format) } async fn save(self) -> Result<(), SaveError> { - let storage = Self::storage().ok_or(SaveError::FileError)?; + let storage = Self::storage().ok_or(SaveError::File)?; let json = serde_json::to_string_pretty(&self) - .map_err(|_| SaveError::FormatError)?; + .map_err(|_| SaveError::Format)?; storage .set_item("state", &json) - .map_err(|_| SaveError::WriteError)?; + .map_err(|_| SaveError::Write)?; let _ = wasm_timer::Delay::new(std::time::Duration::from_secs(2)).await; diff --git a/examples/tooltip/src/main.rs b/examples/tooltip/src/main.rs index 1bd1133c8c..7c8001128f 100644 --- a/examples/tooltip/src/main.rs +++ b/examples/tooltip/src/main.rs @@ -54,16 +54,11 @@ impl Sandbox for Example { tooltip::Position::Right, ); - let fixed_tooltips = Row::with_children(vec![ - top.into(), - bottom.into(), - left.into(), - right.into(), - ]) - .width(Length::Fill) - .height(Length::Fill) - .align_items(Alignment::Center) - .spacing(50); + let fixed_tooltips = Row::with_children(vec![top, bottom, left, right]) + .width(Length::Fill) + .height(Length::Fill) + .align_items(Alignment::Center) + .spacing(50); let follow_cursor = tooltip( "Tooltip follows cursor", @@ -78,7 +73,7 @@ impl Sandbox for Example { .center_x() .center_y() .into(), - follow_cursor.into(), + follow_cursor, ]) .width(Length::Fill) .height(Length::Fill) diff --git a/examples/url_handler/src/main.rs b/examples/url_handler/src/main.rs index b544c30db4..3695b6b778 100644 --- a/examples/url_handler/src/main.rs +++ b/examples/url_handler/src/main.rs @@ -57,7 +57,7 @@ impl Application for App { fn view(&mut self) -> Element { let content = match &self.url { - Some(url) => Text::new(format!("{}", url)), + Some(url) => Text::new(url), None => Text::new("No URL received yet!"), }; diff --git a/examples/websocket/src/echo.rs b/examples/websocket/src/echo.rs index 13596ddde5..8832188053 100644 --- a/examples/websocket/src/echo.rs +++ b/examples/websocket/src/echo.rs @@ -32,7 +32,7 @@ pub fn connect() -> Subscription { ) } Err(_) => { - let _ = tokio::time::sleep( + tokio::time::sleep( tokio::time::Duration::from_secs(1), ) .await; @@ -79,6 +79,7 @@ pub fn connect() -> Subscription { } #[derive(Debug)] +#[allow(clippy::large_enum_variant)] enum State { Disconnected, Connected( @@ -101,8 +102,7 @@ pub struct Connection(mpsc::Sender); impl Connection { pub fn send(&mut self, message: Message) { - let _ = self - .0 + self.0 .try_send(message) .expect("Send message to echo server"); } diff --git a/examples/websocket/src/echo/server.rs b/examples/websocket/src/echo/server.rs index 7702d41780..fef89a1250 100644 --- a/examples/websocket/src/echo/server.rs +++ b/examples/websocket/src/echo/server.rs @@ -27,9 +27,9 @@ use warp::Filter; // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. pub async fn run() { - let routes = warp::path::end().and(warp::ws()).map(|ws: warp::ws::Ws| { - ws.on_upgrade(move |socket| user_connected(socket)) - }); + let routes = warp::path::end() + .and(warp::ws()) + .map(|ws: warp::ws::Ws| ws.on_upgrade(user_connected)); warp::serve(routes).run(([127, 0, 0, 1], 3030)).await; } @@ -40,7 +40,7 @@ async fn user_connected(ws: WebSocket) { tokio::task::spawn(async move { while let Some(message) = rx.next().await { - let _ = user_ws_tx.send(message).await.unwrap_or_else(|e| { + user_ws_tx.send(message).await.unwrap_or_else(|e| { eprintln!("websocket send error: {}", e); }); } diff --git a/futures/src/lib.rs b/futures/src/lib.rs index b0b2f6ce9c..c0982db7ad 100644 --- a/futures/src/lib.rs +++ b/futures/src/lib.rs @@ -4,13 +4,19 @@ #![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)] #![cfg_attr(docsrs, feature(doc_cfg))] - pub use futures; mod command; diff --git a/futures/src/runtime.rs b/futures/src/runtime.rs index 34f6b6dd69..24f9f24121 100644 --- a/futures/src/runtime.rs +++ b/futures/src/runtime.rs @@ -66,8 +66,6 @@ where let future = future.then(|message| async move { let _ = sender.send(message).await; - - () }); self.executor.spawn(future); diff --git a/futures/src/subscription.rs b/futures/src/subscription.rs index 0085886dd8..0479c63cd8 100644 --- a/futures/src/subscription.rs +++ b/futures/src/subscription.rs @@ -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)) } } diff --git a/futures/src/subscription/tracker.rs b/futures/src/subscription/tracker.rs index 2cf9828460..9fe110b0b5 100644 --- a/futures/src/subscription/tracker.rs +++ b/futures/src/subscription/tracker.rs @@ -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 } @@ -156,3 +156,13 @@ where }); } } + +impl Default for Tracker +where + Hasher: std::hash::Hasher + Default, + Event: 'static + Send + Clone, +{ + fn default() -> Self { + Self::new() + } +} diff --git a/glow/src/backend.rs b/glow/src/backend.rs index f63135a477..78d4229e58 100644 --- a/glow/src/backend.rs +++ b/glow/src/backend.rs @@ -173,7 +173,6 @@ impl Backend { glow_glyph::VerticalAlign::Bottom } }), - ..Default::default() }; self.text_pipeline.queue(text); diff --git a/glow/src/lib.rs b/glow/src/lib.rs index 043c5b1355..de9c000214 100644 --- a/glow/src/lib.rs +++ b/glow/src/lib.rs @@ -7,10 +7,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)] +#![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(rust_2018_idioms)] +#![allow(clippy::inherent_to_string, clippy::type_complexity)] #![cfg_attr(docsrs, feature(doc_cfg))] pub use glow; diff --git a/glow/src/program.rs b/glow/src/program.rs index 9a02d578e0..1eb9c53589 100644 --- a/glow/src/program.rs +++ b/glow/src/program.rs @@ -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) { diff --git a/glow/src/quad/compatibility.rs b/glow/src/quad/compatibility.rs index 76f98ab72a..eb3fb7e0d2 100644 --- a/glow/src/quad/compatibility.rs +++ b/glow/src/quad/compatibility.rs @@ -110,22 +110,13 @@ impl Pipeline { bounds: Rectangle, ) { // TODO: Remove this allocation (probably by changing the shader and removing the need of two `position`) - let vertices: Vec = instances - .iter() - .flat_map(|quad| Vertex::from_quad(quad)) - .collect(); + let vertices: Vec = + instances.iter().flat_map(Vertex::from_quad).collect(); // TODO: Remove this allocation (or allocate only when needed) let indices: Vec = (0..instances.len().min(MAX_QUADS) as i32) .flat_map(|i| { - [ - 0 + i * 4, - 1 + i * 4, - 2 + i * 4, - 2 + i * 4, - 1 + i * 4, - 3 + i * 4, - ] + [i * 4, 1 + i * 4, 2 + i * 4, 2 + i * 4, 1 + i * 4, 3 + i * 4] }) .cycle() .take(instances.len() * 6) @@ -187,13 +178,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( diff --git a/glow/src/quad/core.rs b/glow/src/quad/core.rs index f37300f6c4..3e51b1ca13 100644 --- a/glow/src/quad/core.rs +++ b/glow/src/quad/core.rs @@ -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( diff --git a/glow/src/text.rs b/glow/src/text.rs index 0d45d61b9e..37ccdece0d 100644 --- a/glow/src/text.rs +++ b/glow/src/text.rs @@ -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 { diff --git a/glutin/src/lib.rs b/glutin/src/lib.rs index 146dfc4d7d..33afd66435 100644 --- a/glutin/src/lib.rs +++ b/glutin/src/lib.rs @@ -7,11 +7,20 @@ #![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)] -#![deny(unsafe_code)] +#![deny( + missing_docs, + missing_debug_implementations, + unsafe_code, + unused_results, + clippy::extra_unused_lifetimes, + clippy::from_over_into, + clippy::needless_borrow, + clippy::new_without_default, + clippy::useless_conversion +)] #![forbid(rust_2018_idioms)] +#![allow(clippy::inherent_to_string, clippy::type_complexity)] +#![cfg_attr(docsrs, feature(doc_cfg))] pub use glutin; diff --git a/graphics/src/font/source.rs b/graphics/src/font/source.rs index a2d3f51d34..c0b50e1dda 100644 --- a/graphics/src/font/source.rs +++ b/graphics/src/font/source.rs @@ -37,3 +37,9 @@ impl Source { } } } + +impl Default for Source { + fn default() -> Self { + Self::new() + } +} diff --git a/graphics/src/layer.rs b/graphics/src/layer.rs index 935062586d..af545713b6 100644 --- a/graphics/src/layer.rs +++ b/graphics/src/layer.rs @@ -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, ); } diff --git a/graphics/src/lib.rs b/graphics/src/lib.rs index 370f70d638..a7a1cabba4 100644 --- a/graphics/src/lib.rs +++ b/graphics/src/lib.rs @@ -7,11 +7,19 @@ #![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)] -#![deny(unsafe_code)] +#![deny( + missing_debug_implementations, + missing_docs, + unsafe_code, + unused_results, + clippy::extra_unused_lifetimes, + clippy::from_over_into, + clippy::needless_borrow, + clippy::new_without_default, + clippy::useless_conversion +)] #![forbid(rust_2018_idioms)] +#![allow(clippy::inherent_to_string, clippy::type_complexity)] #![cfg_attr(docsrs, feature(doc_cfg))] mod antialiasing; mod error; diff --git a/graphics/src/widget/canvas/path.rs b/graphics/src/widget/canvas/path.rs index 1728f0607c..f834e28609 100644 --- a/graphics/src/widget/canvas/path.rs +++ b/graphics/src/widget/canvas/path.rs @@ -73,9 +73,8 @@ 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() - }); + let segments_odd = (line_dash.segments.len() % 2 == 1) + .then(|| [line_dash.segments, line_dash.segments].concat()); let mut draw_line = false; @@ -103,8 +102,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), }, ); diff --git a/graphics/src/widget/canvas/path/builder.rs b/graphics/src/widget/canvas/path/builder.rs index d04dbdde8e..05316d8a68 100644 --- a/graphics/src/widget/canvas/path/builder.rs +++ b/graphics/src/widget/canvas/path/builder.rs @@ -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(), @@ -151,3 +151,9 @@ impl Builder { } } } + +impl Default for Builder { + fn default() -> Self { + Self::new() + } +} diff --git a/graphics/src/widget/pure/qr_code.rs b/graphics/src/widget/pure/qr_code.rs index 23a8ceb631..bff391feb9 100644 --- a/graphics/src/widget/pure/qr_code.rs +++ b/graphics/src/widget/pure/qr_code.rs @@ -53,12 +53,12 @@ where } } -impl<'a, Message, B, T> Into>> - for QRCode<'a> +impl<'a, Message, B, T> From> + for Element<'a, Message, Renderer> where B: Backend, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from(qr_code: QRCode<'a>) -> Self { + Self::new(qr_code) } } diff --git a/graphics/src/widget/qr_code.rs b/graphics/src/widget/qr_code.rs index 1eb862ba8b..1a5c0b0aa8 100644 --- a/graphics/src/widget/qr_code.rs +++ b/graphics/src/widget/qr_code.rs @@ -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( @@ -128,13 +125,13 @@ where } } -impl<'a, Message, B, T> Into>> - for QRCode<'a> +impl<'a, Message, B, T> From> + for Element<'a, Message, Renderer> where B: Backend, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from(qr_code: QRCode<'a>) -> Self { + Self::new(qr_code) } } diff --git a/graphics/src/window/gl_compositor.rs b/graphics/src/window/gl_compositor.rs index 4ff17366a3..722e4d9c27 100644 --- a/graphics/src/window/gl_compositor.rs +++ b/graphics/src/window/gl_compositor.rs @@ -35,6 +35,9 @@ pub trait GLCompositor: Sized { /// Creates a new [`GLCompositor`] and [`Renderer`] with the given /// [`Settings`] and an OpenGL address loader function. /// + /// # Safety + /// The `loader_function` should resolve to valid OpenGL bindings. + /// /// [`Renderer`]: crate::Renderer /// [`Backend`]: crate::Backend /// [`Settings`]: Self::Settings diff --git a/lazy/src/component.rs b/lazy/src/component.rs index 2c6b6ffb3d..eac7e8ee35 100644 --- a/lazy/src/component.rs +++ b/lazy/src/component.rs @@ -38,7 +38,7 @@ pub trait Component { /// Produces the widgets of the [`Component`], which may trigger an [`Event`](Component::Event) /// on user interaction. - fn view(&mut self) -> Element; + fn view(&mut self) -> Element<'_, Self::Event, Renderer>; } /// Turns an implementor of [`Component`] into an [`Element`] that can be @@ -350,7 +350,7 @@ where layout: Layout<'_>, cursor_position: Point, ) { - self.with_overlay_maybe(|overlay| { + let _ = self.with_overlay_maybe(|overlay| { overlay.draw(renderer, theme, style, layout, cursor_position); }); } @@ -396,7 +396,7 @@ where &mut local_shell, ) }) - .unwrap_or_else(|| iced_native::event::Status::Ignored); + .unwrap_or(iced_native::event::Status::Ignored); local_shell.revalidate_layout(|| shell.invalidate_layout()); diff --git a/lazy/src/lib.rs b/lazy/src/lib.rs index 916f945883..aed11e9f52 100644 --- a/lazy/src/lib.rs +++ b/lazy/src/lib.rs @@ -1,6 +1,21 @@ #![doc( html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg" )] +#![deny( + missing_debug_implementations, + unused_results, + clippy::extra_unused_lifetimes, + clippy::from_over_into, + clippy::needless_borrow, + clippy::new_without_default, + clippy::useless_conversion +)] +#![forbid(unsafe_code)] +#![allow( + clippy::await_holding_refcell_ref, + clippy::inherent_to_string, + clippy::type_complexity +)] #![cfg_attr(docsrs, feature(doc_cfg))] pub mod component; pub mod responsive; diff --git a/lazy/src/pure/component.rs b/lazy/src/pure/component.rs index 9b29b62872..b414a14992 100644 --- a/lazy/src/pure/component.rs +++ b/lazy/src/pure/component.rs @@ -43,7 +43,7 @@ pub trait Component { /// Produces the widgets of the [`Component`], which may trigger an [`Event`](Component::Event) /// on user interaction. - fn view(&self, state: &Self::State) -> Element; + fn view(&self, state: &Self::State) -> Element<'_, Self::Event, Renderer>; } /// Turns an implementor of [`Component`] into an [`Element`] that can be @@ -382,7 +382,7 @@ where layout: Layout<'_>, cursor_position: Point, ) { - self.with_overlay_maybe(|overlay| { + let _ = self.with_overlay_maybe(|overlay| { overlay.draw(renderer, theme, style, layout, cursor_position); }); } @@ -428,7 +428,7 @@ where &mut local_shell, ) }) - .unwrap_or_else(|| iced_native::event::Status::Ignored); + .unwrap_or(iced_native::event::Status::Ignored); local_shell.revalidate_layout(|| shell.invalidate_layout()); diff --git a/lazy/src/pure/responsive.rs b/lazy/src/pure/responsive.rs index 96b89fd6af..0964ebc83d 100644 --- a/lazy/src/pure/responsive.rs +++ b/lazy/src/pure/responsive.rs @@ -341,7 +341,7 @@ where layout: Layout<'_>, cursor_position: Point, ) { - self.with_overlay_maybe(|overlay| { + let _ = self.with_overlay_maybe(|overlay| { overlay.draw(renderer, theme, style, layout, cursor_position); }); } @@ -383,6 +383,6 @@ where shell, ) }) - .unwrap_or_else(|| iced_native::event::Status::Ignored) + .unwrap_or(iced_native::event::Status::Ignored) } } diff --git a/lazy/src/responsive.rs b/lazy/src/responsive.rs index 86c8db6b4b..4a3eb5c6ac 100644 --- a/lazy/src/responsive.rs +++ b/lazy/src/responsive.rs @@ -224,7 +224,7 @@ where where R: Deref, { - self.content.resolve(&mut self.state, renderer, f) + self.content.resolve(self.state, renderer, f) } } @@ -363,7 +363,7 @@ where layout: Layout<'_>, cursor_position: Point, ) { - self.with_overlay_maybe(|overlay| { + let _ = self.with_overlay_maybe(|overlay| { overlay.draw(renderer, theme, style, layout, cursor_position); }); } @@ -405,6 +405,6 @@ where shell, ) }) - .unwrap_or_else(|| iced_native::event::Status::Ignored) + .unwrap_or(iced_native::event::Status::Ignored) } } diff --git a/native/src/debug/basic.rs b/native/src/debug/basic.rs index d706bb0091..603f2fd555 100644 --- a/native/src/debug/basic.rs +++ b/native/src/debug/basic.rs @@ -186,6 +186,12 @@ impl Debug { } } +impl Default for Debug { + fn default() -> Self { + Self::new() + } +} + #[derive(Debug)] struct TimeBuffer { head: usize, diff --git a/native/src/debug/null.rs b/native/src/debug/null.rs index 60e6122de4..2db0eebb7e 100644 --- a/native/src/debug/null.rs +++ b/native/src/debug/null.rs @@ -1,5 +1,5 @@ #![allow(missing_docs)] -#[derive(Debug)] +#[derive(Debug, Default)] pub struct Debug; impl Debug { diff --git a/native/src/hasher.rs b/native/src/hasher.rs index 9f6aaccebd..fa52f16d8a 100644 --- a/native/src/hasher.rs +++ b/native/src/hasher.rs @@ -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) diff --git a/native/src/lib.rs b/native/src/lib.rs index 2d0dd6ecd9..131739011c 100644 --- a/native/src/lib.rs +++ b/native/src/lib.rs @@ -31,11 +31,19 @@ #![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)] +#![cfg_attr(docsrs, feature(doc_cfg))] pub mod clipboard; pub mod command; pub mod event; diff --git a/native/src/overlay/menu.rs b/native/src/overlay/menu.rs index 979a13c39a..fc3f52b2a2 100644 --- a/native/src/overlay/menu.rs +++ b/native/src/overlay/menu.rs @@ -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; @@ -485,15 +489,15 @@ where } } -impl<'a, T, Message, Renderer> Into> - for List<'a, T, Renderer> +impl<'a, T, Message, Renderer> From> + for Element<'a, Message, Renderer> where T: ToString + Clone, Message: 'a, Renderer: 'a + text::Renderer, Renderer::Theme: StyleSheet, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from(list: List<'a, T, Renderer>) -> Self { + Element::new(list) } } diff --git a/native/src/program/state.rs b/native/src/program/state.rs index 7ec2a04fe7..2ddde2c2ea 100644 --- a/native/src/program/state.rs +++ b/native/src/program/state.rs @@ -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(); diff --git a/native/src/renderer/null.rs b/native/src/renderer/null.rs index c591f4e2c9..b1743dbfb7 100644 --- a/native/src/renderer/null.rs +++ b/native/src/renderer/null.rs @@ -5,7 +5,7 @@ use crate::{Background, Font, Point, Rectangle, Size, Theme, Vector}; /// A renderer that does nothing. /// /// It can be useful if you are writing tests! -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, Default)] pub struct Null; impl Null { diff --git a/native/src/user_interface.rs b/native/src/user_interface.rs index 97a004e7a3..ef6f437e4e 100644 --- a/native/src/user_interface.rs +++ b/native/src/user_interface.rs @@ -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, diff --git a/native/src/widget/button.rs b/native/src/widget/button.rs index d4e8842492..a33ee7f75d 100644 --- a/native/src/widget/button.rs +++ b/native/src/widget/button.rs @@ -382,7 +382,7 @@ where self.on_press.is_some(), theme, self.style, - || &self.state, + || self.state, ); self.content.draw( diff --git a/native/src/widget/checkbox.rs b/native/src/widget/checkbox.rs index 9e7f183acd..a49d2fa2b0 100644 --- a/native/src/widget/checkbox.rs +++ b/native/src/widget/checkbox.rs @@ -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) } diff --git a/native/src/widget/column.rs b/native/src/widget/column.rs index 01ddd9f1db..4eee7d3c43 100644 --- a/native/src/widget/column.rs +++ b/native/src/widget/column.rs @@ -102,6 +102,12 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> { } } +impl<'a, Message, Renderer> Default for Column<'a, Message, Renderer> { + fn default() -> Self { + Self::new() + } +} + impl<'a, Message, Renderer> Widget for Column<'a, Message, Renderer> where diff --git a/native/src/widget/pane_grid.rs b/native/src/widget/pane_grid.rs index eb969dbf68..70ca772c74 100644 --- a/native/src/widget/pane_grid.rs +++ b/native/src/widget/pane_grid.rs @@ -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)) diff --git a/native/src/widget/pane_grid/node.rs b/native/src/widget/pane_grid/node.rs index af6573a0e1..cc304b96a7 100644 --- a/native/src/widget/pane_grid/node.rs +++ b/native/src/widget/pane_grid/node.rs @@ -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); diff --git a/native/src/widget/pane_grid/state.rs b/native/src/widget/pane_grid/state.rs index 6a282d2486..4e90f64543 100644 --- a/native/src/widget/pane_grid/state.rs +++ b/native/src/widget/pane_grid/state.rs @@ -66,6 +66,11 @@ impl State { 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) diff --git a/native/src/widget/pick_list.rs b/native/src/widget/pick_list.rs index c6cfcc0115..61b0eb9639 100644 --- a/native/src/widget/pick_list.rs +++ b/native/src/widget/pick_list.rs @@ -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( 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, ) @@ -526,7 +525,7 @@ where ) -> Option> { overlay( layout, - &mut self.state, + self.state, self.padding, self.text_size, self.font.clone(), @@ -536,8 +535,8 @@ where } } -impl<'a, T: 'a, Message, Renderer> Into> - for PickList<'a, T, Message, Renderer> +impl<'a, T: 'a, Message, Renderer> From> + for Element<'a, Message, Renderer> where T: Clone + ToString + Eq, [T]: ToOwned>, @@ -550,7 +549,7 @@ where ::Style: Into<::Style>, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from(pick_list: PickList<'a, T, Message, Renderer>) -> Self { + Element::new(pick_list) } } diff --git a/native/src/widget/progress_bar.rs b/native/src/widget/progress_bar.rs index 4eb7438a4d..50bdcda60f 100644 --- a/native/src/widget/progress_bar.rs +++ b/native/src/widget/progress_bar.rs @@ -76,7 +76,7 @@ where } } -impl<'a, Message, Renderer> Widget for ProgressBar +impl Widget for ProgressBar where Renderer: crate::Renderer, Renderer::Theme: StyleSheet, diff --git a/native/src/widget/radio.rs b/native/src/widget/radio.rs index ba45a0f4f9..647e3c5ae2 100644 --- a/native/src/widget/radio.rs +++ b/native/src/widget/radio.rs @@ -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) } diff --git a/native/src/widget/row.rs b/native/src/widget/row.rs index 9cff74c61c..9d8cc71512 100644 --- a/native/src/widget/row.rs +++ b/native/src/widget/row.rs @@ -102,6 +102,12 @@ impl<'a, Message, Renderer> Row<'a, Message, Renderer> { } } +impl<'a, Message, Renderer> Default for Row<'a, Message, Renderer> { + fn default() -> Self { + Self::new() + } +} + impl<'a, Message, Renderer> Widget for Row<'a, Message, Renderer> where diff --git a/native/src/widget/rule.rs b/native/src/widget/rule.rs index 26285df46f..f0fda8a9cc 100644 --- a/native/src/widget/rule.rs +++ b/native/src/widget/rule.rs @@ -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(), diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs index 5d5503155c..1b255860ee 100644 --- a/native/src/widget/scrollable.rs +++ b/native/src/widget/scrollable.rs @@ -662,7 +662,7 @@ where shell: &mut Shell<'_, Message>, ) -> event::Status { update( - &mut self.state, + self.state, event, layout, cursor_position, @@ -693,7 +693,7 @@ where renderer: &Renderer, ) -> mouse::Interaction { mouse_interaction( - &self.state, + self.state, layout, cursor_position, self.scrollbar_width, @@ -720,7 +720,7 @@ where _viewport: &Rectangle, ) { draw( - &self.state, + self.state, renderer, theme, layout, diff --git a/native/src/widget/slider.rs b/native/src/widget/slider.rs index bda31327bd..a5ff611c83 100644 --- a/native/src/widget/slider.rs +++ b/native/src/widget/slider.rs @@ -303,7 +303,7 @@ pub fn draw( 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; @@ -410,7 +410,7 @@ where layout, cursor_position, shell, - &mut self.state, + self.state, &mut self.value, &self.range, self.step, @@ -432,7 +432,7 @@ where renderer, layout, cursor_position, - &self.state, + self.state, self.value, &self.range, theme, @@ -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) } } diff --git a/native/src/widget/text.rs b/native/src/widget/text.rs index 242247b0f6..8d173b8a84 100644 --- a/native/src/widget/text.rs +++ b/native/src/widget/text.rs @@ -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.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, diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index d345cec326..98265ef2ee 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -176,7 +176,7 @@ where theme, layout, cursor_position, - &self.state, + self.state, value.unwrap_or(&self.value), &self.placeholder, self.size, @@ -198,7 +198,7 @@ pub fn layout( 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::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( ); 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( measure_cursor_and_scroll_offset( renderer, text_bounds, - &value, + value, size, left, font.clone(), @@ -674,7 +674,7 @@ pub fn draw( measure_cursor_and_scroll_offset( renderer, text_bounds, - &value, + value, size, right, font.clone(), @@ -998,16 +998,16 @@ fn find_cursor_position( 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, diff --git a/native/src/widget/text_input/editor.rs b/native/src/widget/text_input/editor.rs index bac530e16e..d53fa8d964 100644 --- a/native/src/widget/text_input/editor.rs +++ b/native/src/widget/text_input/editor.rs @@ -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); diff --git a/native/src/widget/text_input/value.rs b/native/src/widget/text_input/value.rs index 2034cca418..cf4da562f4 100644 --- a/native/src/widget/text_input/value.rs +++ b/native/src/widget/text_input/value.rs @@ -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() diff --git a/native/src/widget/toggler.rs b/native/src/widget/toggler.rs index 0936c2711d..3deaf28756 100644 --- a/native/src/widget/toggler.rs +++ b/native/src/widget/toggler.rs @@ -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(), diff --git a/pure/src/lib.rs b/pure/src/lib.rs index 95aa3098d2..9c5f3bc863 100644 --- a/pure/src/lib.rs +++ b/pure/src/lib.rs @@ -82,10 +82,18 @@ #![doc( html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg" )] -#![deny(missing_docs)] -#![deny(unused_results)] -#![forbid(unsafe_code)] -#![forbid(rust_2018_idioms)] +#![deny( + missing_docs, + unused_results, + clippy::extra_unused_lifetimes, + clippy::from_over_into, + clippy::needless_borrow, + clippy::new_without_default, + clippy::useless_conversion +)] +#![forbid(rust_2018_idioms, unsafe_code)] +#![allow(clippy::inherent_to_string, clippy::type_complexity)] +#![cfg_attr(docsrs, feature(doc_cfg))] pub mod flex; pub mod helpers; @@ -146,7 +154,7 @@ where content: impl Into>, ) -> Self { let element = content.into(); - let _ = state.diff(&element); + state.diff(&element); Self { state, element } } @@ -272,13 +280,13 @@ where } } -impl<'a, Message, Renderer> Into> - for Pure<'a, Message, Renderer> +impl<'a, Message, Renderer> From> + for iced_native::Element<'a, Message, Renderer> where Message: 'a, Renderer: iced_native::Renderer + 'a, { - fn into(self) -> iced_native::Element<'a, Message, Renderer> { - iced_native::Element::new(self) + fn from(pure: Pure<'a, Message, Renderer>) -> Self { + Self::new(pure) } } diff --git a/pure/src/widget/button.rs b/pure/src/widget/button.rs index dd7688e2ec..eb174e5731 100644 --- a/pure/src/widget/button.rs +++ b/pure/src/widget/button.rs @@ -159,7 +159,7 @@ where self.height, self.padding, |renderer, limits| { - self.content.as_widget().layout(renderer, &limits) + self.content.as_widget().layout(renderer, limits) }, ) } @@ -261,14 +261,14 @@ where } } -impl<'a, Message, Renderer> Into> - for Button<'a, Message, Renderer> +impl<'a, Message, Renderer> From> + for Element<'a, Message, Renderer> where Message: Clone + 'a, Renderer: iced_native::Renderer + 'a, Renderer::Theme: StyleSheet, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from(button: Button<'a, Message, Renderer>) -> Self { + Self::new(button) } } diff --git a/pure/src/widget/checkbox.rs b/pure/src/widget/checkbox.rs index 9d6a78cee9..e0f9b76432 100644 --- a/pure/src/widget/checkbox.rs +++ b/pure/src/widget/checkbox.rs @@ -96,14 +96,14 @@ where } } -impl<'a, Message, Renderer> Into> - for Checkbox<'a, Message, Renderer> +impl<'a, Message, Renderer> From> + for Element<'a, Message, Renderer> where Message: 'a, Renderer: text::Renderer + 'a, Renderer::Theme: StyleSheet + widget::text::StyleSheet, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from(checkbox: Checkbox<'a, Message, Renderer>) -> Self { + Self::new(checkbox) } } diff --git a/pure/src/widget/column.rs b/pure/src/widget/column.rs index 74d789a173..027eff0a09 100644 --- a/pure/src/widget/column.rs +++ b/pure/src/widget/column.rs @@ -95,6 +95,12 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> { } } +impl<'a, Message, Renderer> Default for Column<'a, Message, Renderer> { + fn default() -> Self { + Self::new() + } +} + impl<'a, Message, Renderer> Widget for Column<'a, Message, Renderer> where @@ -228,13 +234,13 @@ where } } -impl<'a, Message, Renderer> Into> - for Column<'a, Message, Renderer> +impl<'a, Message, Renderer> From> + for Element<'a, Message, Renderer> where Message: 'a, Renderer: iced_native::Renderer + 'a, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from(column: Column<'a, Message, Renderer>) -> Self { + Self::new(column) } } diff --git a/pure/src/widget/image.rs b/pure/src/widget/image.rs index c42113dcae..58f81a6f9c 100644 --- a/pure/src/widget/image.rs +++ b/pure/src/widget/image.rs @@ -56,14 +56,14 @@ where } } -impl<'a, Message, Renderer, Handle> Into> - for Image +impl<'a, Message, Renderer, Handle> From> + for Element<'a, Message, Renderer> where Message: Clone + 'a, Renderer: iced_native::image::Renderer + 'a, Handle: Clone + Hash + 'a, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from(image: Image) -> Self { + Self::new(image) } } diff --git a/pure/src/widget/pick_list.rs b/pure/src/widget/pick_list.rs index 2c46593257..9264544ac4 100644 --- a/pure/src/widget/pick_list.rs +++ b/pure/src/widget/pick_list.rs @@ -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, ) @@ -225,8 +225,8 @@ where } } -impl<'a, T: 'a, Message, Renderer> Into> - for PickList<'a, T, Message, Renderer> +impl<'a, T: 'a, Message, Renderer> From> + for Element<'a, Message, Renderer> where T: Clone + ToString + Eq + 'static, [T]: ToOwned>, @@ -234,7 +234,7 @@ where Renderer: text::Renderer + 'a, Renderer::Theme: StyleSheet, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from(pick_list: PickList<'a, T, Message, Renderer>) -> Self { + Self::new(pick_list) } } diff --git a/pure/src/widget/progress_bar.rs b/pure/src/widget/progress_bar.rs index 69c7d30226..c96448531e 100644 --- a/pure/src/widget/progress_bar.rs +++ b/pure/src/widget/progress_bar.rs @@ -10,7 +10,7 @@ use iced_native::{Clipboard, Length, Point, Rectangle, Shell}; pub use iced_native::widget::progress_bar::*; -impl<'a, Message, Renderer> Widget for ProgressBar +impl Widget for ProgressBar where Renderer: iced_native::Renderer, Renderer::Theme: StyleSheet, @@ -93,13 +93,13 @@ where } } -impl<'a, Message, Renderer> Into> - for ProgressBar +impl<'a, Message, Renderer> From> + for Element<'a, Message, Renderer> where Renderer: iced_native::Renderer + 'a, Renderer::Theme: StyleSheet, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from(progress_bar: ProgressBar) -> Self { + Self::new(progress_bar) } } diff --git a/pure/src/widget/radio.rs b/pure/src/widget/radio.rs index 7a6ffbac12..604c2785f9 100644 --- a/pure/src/widget/radio.rs +++ b/pure/src/widget/radio.rs @@ -96,14 +96,14 @@ where } } -impl<'a, Message, Renderer> Into> - for Radio +impl<'a, Message, Renderer> From> + for Element<'a, Message, Renderer> where Message: 'a + Clone, Renderer: text::Renderer + 'a, Renderer::Theme: StyleSheet + widget::text::StyleSheet, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from(radio: Radio) -> Self { + Self::new(radio) } } diff --git a/pure/src/widget/row.rs b/pure/src/widget/row.rs index e747adfc42..a288a68df6 100644 --- a/pure/src/widget/row.rs +++ b/pure/src/widget/row.rs @@ -85,6 +85,12 @@ impl<'a, Message, Renderer> Row<'a, Message, Renderer> { } } +impl<'a, Message, Renderer> Default for Row<'a, Message, Renderer> { + fn default() -> Self { + Self::new() + } +} + impl<'a, Message, Renderer> Widget for Row<'a, Message, Renderer> where @@ -215,13 +221,13 @@ where } } -impl<'a, Message, Renderer> Into> - for Row<'a, Message, Renderer> +impl<'a, Message, Renderer> From> + for Element<'a, Message, Renderer> where Message: 'a, Renderer: iced_native::Renderer + 'a, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from(row: Row<'a, Message, Renderer>) -> Self { + Self::new(row) } } diff --git a/pure/src/widget/rule.rs b/pure/src/widget/rule.rs index 66a476536f..0fb4ebab7f 100644 --- a/pure/src/widget/rule.rs +++ b/pure/src/widget/rule.rs @@ -10,7 +10,7 @@ use iced_native::{Clipboard, Length, Point, Rectangle, Shell}; pub use iced_native::widget::rule::*; -impl<'a, Message, Renderer> Widget for Rule +impl Widget for Rule where Renderer: iced_native::Renderer, Renderer::Theme: StyleSheet, @@ -93,13 +93,13 @@ where } } -impl<'a, Message, Renderer> Into> - for Rule +impl<'a, Message, Renderer> From> + for Element<'a, Message, Renderer> where Renderer: iced_native::Renderer + 'a, Renderer::Theme: StyleSheet, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from(rule: Rule) -> Self { + Self::new(rule) } } diff --git a/pure/src/widget/space.rs b/pure/src/widget/space.rs index 7d95ebd7ea..408cb6470f 100644 --- a/pure/src/widget/space.rs +++ b/pure/src/widget/space.rs @@ -9,7 +9,7 @@ use iced_native::{Clipboard, Length, Point, Rectangle, Shell}; pub use iced_native::widget::Space; -impl<'a, Message, Renderer> Widget for Space +impl Widget for Space where Renderer: iced_native::Renderer, { @@ -91,11 +91,11 @@ where } } -impl<'a, Message, Renderer> Into> for Space +impl<'a, Message, Renderer> From for Element<'a, Message, Renderer> where Renderer: iced_native::Renderer + 'a, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from(space: Space) -> Self { + Self::new(space) } } diff --git a/pure/src/widget/svg.rs b/pure/src/widget/svg.rs index 501d9bfaad..ae4e8cffce 100644 --- a/pure/src/widget/svg.rs +++ b/pure/src/widget/svg.rs @@ -54,12 +54,12 @@ where } } -impl<'a, Message, Renderer> Into> for Svg +impl<'a, Message, Renderer> From for Element<'a, Message, Renderer> where Message: Clone + 'a, Renderer: iced_native::svg::Renderer + 'a, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from(svg: Svg) -> Self { + Self::new(svg) } } diff --git a/pure/src/widget/text.rs b/pure/src/widget/text.rs index 23999a2cff..7c6f6ce977 100644 --- a/pure/src/widget/text.rs +++ b/pure/src/widget/text.rs @@ -55,23 +55,23 @@ where } } -impl<'a, Message, Renderer> Into> - for Text +impl<'a, Message, Renderer> From> + for Element<'a, Message, Renderer> where Renderer: text::Renderer + 'a, Renderer::Theme: widget::text::StyleSheet, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from(text: Text) -> Self { + Self::new(text) } } -impl<'a, Message, Renderer> Into> for &'a str +impl<'a, Message, Renderer> From<&'a str> for Element<'a, Message, Renderer> where Renderer: text::Renderer + 'a, Renderer::Theme: widget::text::StyleSheet, { - fn into(self) -> Element<'a, Message, Renderer> { - Text::new(self).into() + fn from(contents: &'a str) -> Self { + Text::new(contents).into() } } diff --git a/pure/src/widget/toggler.rs b/pure/src/widget/toggler.rs index 5efa39ab31..8d0044d296 100644 --- a/pure/src/widget/toggler.rs +++ b/pure/src/widget/toggler.rs @@ -96,14 +96,14 @@ where } } -impl<'a, Message, Renderer> Into> - for Toggler<'a, Message, Renderer> +impl<'a, Message, Renderer> From> + for Element<'a, Message, Renderer> where Message: 'a, Renderer: text::Renderer + 'a, Renderer::Theme: StyleSheet + widget::text::StyleSheet, { - fn into(self) -> Element<'a, Message, Renderer> { - Element::new(self) + fn from(toggler: Toggler<'a, Message, Renderer>) -> Self { + Self::new(toggler) } } diff --git a/src/application.rs b/src/application.rs index e8d8e982fc..aca97367be 100644 --- a/src/application.rs +++ b/src/application.rs @@ -215,6 +215,7 @@ pub trait Application: Sized { where Self: 'static, { + #[allow(clippy::needless_update)] let renderer_settings = crate::renderer::Settings { default_font: settings.default_font, default_text_size: settings.default_text_size, diff --git a/src/lib.rs b/src/lib.rs index d64941f4bd..4e8d67879e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -174,12 +174,20 @@ #![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(rust_2018_idioms, unsafe_code)] +#![allow(clippy::inherent_to_string, clippy::type_complexity)] #![cfg_attr(docsrs, feature(doc_cfg))] + mod element; mod error; mod result; diff --git a/style/src/lib.rs b/style/src/lib.rs index ee426e9887..0dde9582d4 100644 --- a/style/src/lib.rs +++ b/style/src/lib.rs @@ -7,6 +7,16 @@ #![doc( html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg" )] +#![deny( + 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 use iced_core::{Background, Color}; pub mod application; diff --git a/style/src/text.rs b/style/src/text.rs index 69a4ed85ad..6e3aeef824 100644 --- a/style/src/text.rs +++ b/style/src/text.rs @@ -6,13 +6,7 @@ pub trait StyleSheet { fn appearance(&self, style: Self::Style) -> Appearance; } -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, Default)] pub struct Appearance { pub color: Option, } - -impl Default for Appearance { - fn default() -> Self { - Self { color: None } - } -} diff --git a/style/src/theme.rs b/style/src/theme.rs index d2de8a5d37..5697b24097 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -419,7 +419,7 @@ impl radio::StyleSheet for Theme { radio::Appearance { background: Color::TRANSPARENT.into(), - dot_color: palette.primary.strong.color.into(), + dot_color: palette.primary.strong.color, border_width: 1.0, border_color: palette.primary.strong.color, text_color: None, @@ -431,7 +431,7 @@ impl radio::StyleSheet for Theme { let palette = self.extended_palette(); radio::Appearance { - dot_color: palette.primary.strong.color.into(), + dot_color: palette.primary.strong.color, background: palette.primary.weak.color.into(), ..active } @@ -599,7 +599,7 @@ impl scrollable::StyleSheet for Theme { border_width: 0.0, border_color: Color::TRANSPARENT, scroller: scrollable::Scroller { - color: palette.background.strong.color.into(), + color: palette.background.strong.color, border_radius: 2.0, border_width: 0.0, border_color: Color::TRANSPARENT, @@ -616,7 +616,7 @@ impl scrollable::StyleSheet for Theme { border_width: 0.0, border_color: Color::TRANSPARENT, scroller: scrollable::Scroller { - color: palette.primary.strong.color.into(), + color: palette.primary.strong.color, border_radius: 2.0, border_width: 0.0, border_color: Color::TRANSPARENT, diff --git a/wgpu/src/backend.rs b/wgpu/src/backend.rs index 05b4af9bda..8c875254ac 100644 --- a/wgpu/src/backend.rs +++ b/wgpu/src/backend.rs @@ -93,7 +93,7 @@ impl Backend { &layer, staging_belt, encoder, - &frame, + frame, target_size.width, target_size.height, ); @@ -230,7 +230,6 @@ impl Backend { wgpu_glyph::VerticalAlign::Bottom } }), - ..Default::default() }; self.text_pipeline.queue(text); diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs index 750ad62a39..d964aed7a8 100644 --- a/wgpu/src/image.rs +++ b/wgpu/src/image.rs @@ -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(), ), }], }); diff --git a/wgpu/src/image/atlas.rs b/wgpu/src/image/atlas.rs index c1347e550d..953dd4e23a 100644 --- a/wgpu/src/image/atlas.rs +++ b/wgpu/src/image/atlas.rs @@ -113,13 +113,7 @@ impl Atlas { match &entry { Entry::Contiguous(allocation) => { self.upload_allocation( - &buffer, - width, - height, - padding, - 0, - &allocation, - encoder, + &buffer, width, height, padding, 0, allocation, encoder, ); } Entry::Fragmented { fragments, .. } => { diff --git a/wgpu/src/image/atlas/layer.rs b/wgpu/src/image/atlas/layer.rs index b1084ed9e6..cf08960187 100644 --- a/wgpu/src/image/atlas/layer.rs +++ b/wgpu/src/image/atlas/layer.rs @@ -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) } } diff --git a/wgpu/src/image/raster.rs b/wgpu/src/image/raster.rs index ec5e911f04..2b4d4af397 100644 --- a/wgpu/src/image/raster.rs +++ b/wgpu/src/image/raster.rs @@ -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() @@ -103,7 +103,7 @@ impl Cache { if let Memory::Host(image) = memory { let (width, height) = image.dimensions(); - let entry = atlas.upload(width, height, &image, device, encoder)?; + let entry = atlas.upload(width, height, image, device, encoder)?; *memory = Memory::Device(entry); } diff --git a/wgpu/src/image/vector.rs b/wgpu/src/image/vector.rs index 4c83091344..b08a0aa287 100644 --- a/wgpu/src/image/vector.rs +++ b/wgpu/src/image/vector.rs @@ -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) diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index d1ad6cd97c..3a98c6bd3f 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -23,11 +23,19 @@ #![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)] -#![deny(unsafe_code)] +#![deny( + missing_debug_implementations, + missing_docs, + unsafe_code, + unused_results, + clippy::extra_unused_lifetimes, + clippy::from_over_into, + clippy::needless_borrow, + clippy::new_without_default, + clippy::useless_conversion +)] #![forbid(rust_2018_idioms)] +#![allow(clippy::inherent_to_string, clippy::type_complexity)] #![cfg_attr(docsrs, feature(doc_cfg))] pub mod settings; diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index 45f1f2de82..e17b84c15d 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -188,7 +188,8 @@ impl Pipeline { } b_count += utf8_len; } - return byte_index; + + byte_index }; if !nearest_only { diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs index 40e2f8551d..fd06dddf0b 100644 --- a/wgpu/src/triangle.rs +++ b/wgpu/src/triangle.rs @@ -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::() * 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::() * 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(); + { + let mut vertex_buffer = staging_belt.write_buffer( + encoder, + &self.vertex_buffer.raw, + (std::mem::size_of::() * 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::() * 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(); } } diff --git a/wgpu/src/triangle/msaa.rs b/wgpu/src/triangle/msaa.rs index 7edeeb9440..a3016ff8fb 100644 --- a/wgpu/src/triangle/msaa.rs +++ b/wgpu/src/triangle/msaa.rs @@ -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, diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index fa1f441a0e..a36d2a8761 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -225,7 +225,7 @@ impl iced_graphics::window::Compositor for Compositor { renderer.with_primitives(|backend, primitives| { backend.present( - &mut self.device, + &self.device, &mut self.staging_belt, &mut encoder, view, diff --git a/winit/src/application.rs b/winit/src/application.rs index 9c7dd74e81..99402cf564 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -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(()) } diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs index 8e6c0b37c8..74f6f7a072 100644 --- a/winit/src/conversion.rs +++ b/winit/src/conversion.rs @@ -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}' + ) } diff --git a/winit/src/lib.rs b/winit/src/lib.rs index 22e7efdfb9..3bde0f2b2c 100644 --- a/winit/src/lib.rs +++ b/winit/src/lib.rs @@ -17,11 +17,19 @@ #![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(rust_2018_idioms, unsafe_code)] +#![allow(clippy::inherent_to_string, clippy::type_complexity)] +#![cfg_attr(docsrs, feature(doc_cfg))] #[doc(no_inline)] pub use iced_native::*; diff --git a/winit/src/system.rs b/winit/src/system.rs index 0ed61dc965..0303707ebc 100644 --- a/winit/src/system.rs +++ b/winit/src/system.rs @@ -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 {