From ded8dbd45bc8616475c364878f6b8e2f7293d12c Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 2 May 2024 17:04:25 +0200 Subject: [PATCH] Fix some clippy warning from Rust 1.78.0 (#4444) --- crates/eframe/src/epi.rs | 6 +++--- crates/eframe/src/native/glow_integration.rs | 15 --------------- crates/eframe/src/native/wgpu_integration.rs | 14 -------------- crates/eframe/src/native/winit_integration.rs | 6 ------ crates/egui-wgpu/src/renderer.rs | 2 +- crates/egui-wgpu/src/winit.rs | 4 ++-- crates/egui/src/frame_state.rs | 4 ++-- crates/egui/src/input_state.rs | 2 +- crates/egui/src/input_state/touch_state.rs | 2 +- crates/egui/src/layout.rs | 4 ++-- crates/egui/src/os.rs | 10 +++++----- crates/egui/src/style.rs | 2 +- crates/egui/src/util/undoer.rs | 4 ++-- crates/egui/src/viewport.rs | 2 +- crates/egui/src/widgets/text_edit/text_buffer.rs | 2 +- crates/egui_demo_app/src/wrap_app.rs | 2 +- .../src/easy_mark/easy_mark_highlighter.rs | 2 +- crates/egui_plot/src/items/values.rs | 14 +++++++------- crates/emath/src/rot2.rs | 4 ++-- crates/epaint/src/text/text_layout_types.rs | 6 +++--- examples/file_dialog/src/main.rs | 2 +- 21 files changed, 37 insertions(+), 72 deletions(-) diff --git a/crates/eframe/src/epi.rs b/crates/eframe/src/epi.rs index e7b53691cda..db39a08b15b 100644 --- a/crates/eframe/src/epi.rs +++ b/crates/eframe/src/epi.rs @@ -232,7 +232,7 @@ pub enum HardwareAcceleration { /// Do NOT use graphics acceleration. /// - /// On some platforms (MacOS) this is ignored and treated the same as [`Self::Preferred`]. + /// On some platforms (macOS) this is ignored and treated the same as [`Self::Preferred`]. Off, } @@ -518,10 +518,10 @@ pub enum WebGlContextOption { /// Force use WebGL2. WebGl2, - /// Use WebGl2 first. + /// Use WebGL2 first. BestFirst, - /// Use WebGl1 first + /// Use WebGL1 first CompatibilityFirst, } diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index f08ed14d623..0fbb48a09c7 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -360,21 +360,6 @@ impl WinitApp for GlowWinitApp { .map_or(0, |r| r.integration.egui_ctx.frame_nr_for(viewport_id)) } - fn is_focused(&self, window_id: WindowId) -> bool { - if let Some(running) = &self.running { - let glutin = running.glutin.borrow(); - if let Some(window_id) = glutin.viewport_from_window.get(&window_id) { - return glutin.focused_viewport == Some(*window_id); - } - } - - false - } - - fn integration(&self) -> Option<&EpiIntegration> { - self.running.as_ref().map(|r| &r.integration) - } - fn window(&self, window_id: WindowId) -> Option> { let running = self.running.as_ref()?; let glutin = running.glutin.borrow(); diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 1287ce8a01f..f365d74ad93 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -341,20 +341,6 @@ impl WinitApp for WgpuWinitApp { .map_or(0, |r| r.integration.egui_ctx.frame_nr_for(viewport_id)) } - fn is_focused(&self, window_id: WindowId) -> bool { - if let Some(running) = &self.running { - let shared = running.shared.borrow(); - let viewport_id = shared.viewport_from_window.get(&window_id).copied(); - shared.focused_viewport.is_some() && shared.focused_viewport == viewport_id - } else { - false - } - } - - fn integration(&self) -> Option<&EpiIntegration> { - self.running.as_ref().map(|r| &r.integration) - } - fn window(&self, window_id: WindowId) -> Option> { self.running .as_ref() diff --git a/crates/eframe/src/native/winit_integration.rs b/crates/eframe/src/native/winit_integration.rs index 541253c0818..fbbd7910732 100644 --- a/crates/eframe/src/native/winit_integration.rs +++ b/crates/eframe/src/native/winit_integration.rs @@ -9,8 +9,6 @@ use egui::ViewportId; #[cfg(feature = "accesskit")] use egui_winit::accesskit_winit; -use super::epi_integration::EpiIntegration; - /// Create an egui context, restoring it from storage if possible. pub fn create_egui_context(storage: Option<&dyn crate::Storage>) -> egui::Context { crate::profile_function!(); @@ -64,10 +62,6 @@ pub trait WinitApp { /// The current frame number, as reported by egui. fn frame_nr(&self, viewport_id: ViewportId) -> u64; - fn is_focused(&self, window_id: WindowId) -> bool; - - fn integration(&self) -> Option<&EpiIntegration>; - fn window(&self, window_id: WindowId) -> Option>; fn window_id_from_viewport_id(&self, id: ViewportId) -> Option; diff --git a/crates/egui-wgpu/src/renderer.rs b/crates/egui-wgpu/src/renderer.rs index 52ce7907a50..49397c9af89 100644 --- a/crates/egui-wgpu/src/renderer.rs +++ b/crates/egui-wgpu/src/renderer.rs @@ -162,7 +162,7 @@ pub struct Renderer { texture_bind_group_layout: wgpu::BindGroupLayout, /// Map of egui texture IDs to textures and their associated bindgroups (texture view + - /// sampler). The texture may be None if the TextureId is just a handle to a user-provided + /// sampler). The texture may be None if the `TextureId` is just a handle to a user-provided /// sampler. textures: HashMap, wgpu::BindGroup)>, next_user_texture_id: u64, diff --git a/crates/egui-wgpu/src/winit.rs b/crates/egui-wgpu/src/winit.rs index 84dd0b41235..4a909bfc75f 100644 --- a/crates/egui-wgpu/src/winit.rs +++ b/crates/egui-wgpu/src/winit.rs @@ -209,7 +209,7 @@ impl Painter { if let Some(window) = window { let size = window.inner_size(); - if self.surfaces.get(&viewport_id).is_none() { + if !self.surfaces.contains_key(&viewport_id) { let surface = self.instance.create_surface(window)?; self.add_surface(surface, viewport_id, size).await?; } @@ -235,7 +235,7 @@ impl Painter { if let Some(window) = window { let size = window.inner_size(); - if self.surfaces.get(&viewport_id).is_none() { + if !self.surfaces.contains_key(&viewport_id) { let surface = unsafe { self.instance .create_surface_unsafe(wgpu::SurfaceTargetUnsafe::from_window(&window)?)? diff --git a/crates/egui/src/frame_state.rs b/crates/egui/src/frame_state.rs index 87074c2a725..f160d742345 100644 --- a/crates/egui/src/frame_state.rs +++ b/crates/egui/src/frame_state.rs @@ -21,12 +21,12 @@ pub(crate) struct FrameState { /// All [`Id`]s that were used this frame. pub(crate) used_ids: IdMap, - /// Starts off as the screen_rect, shrinks as panels are added. + /// Starts off as the `screen_rect`, shrinks as panels are added. /// The [`CentralPanel`] does not change this. /// This is the area available to Window's. pub(crate) available_rect: Rect, - /// Starts off as the screen_rect, shrinks as panels are added. + /// Starts off as the `screen_rect`, shrinks as panels are added. /// The [`CentralPanel`] retracts from this. pub(crate) unused_rect: Rect, diff --git a/crates/egui/src/input_state.rs b/crates/egui/src/input_state.rs index 9c6103e0a54..57a9e6477bf 100644 --- a/crates/egui/src/input_state.rs +++ b/crates/egui/src/input_state.rs @@ -35,7 +35,7 @@ pub struct InputState { /// State of the mouse or simple touch gestures which can be mapped to mouse operations. pub pointer: PointerState, - /// State of touches, except those covered by PointerState (like clicks and drags). + /// State of touches, except those covered by `PointerState` (like clicks and drags). /// (We keep a separate [`TouchState`] for each encountered touch device.) touch_states: BTreeMap, diff --git a/crates/egui/src/input_state/touch_state.rs b/crates/egui/src/input_state/touch_state.rs index 43053f821e5..e9425dba24c 100644 --- a/crates/egui/src/input_state/touch_state.rs +++ b/crates/egui/src/input_state/touch_state.rs @@ -72,7 +72,7 @@ pub(crate) struct TouchState { /// Active touches, if any. /// - /// TouchId is the unique identifier of the touch. It is valid as long as the finger/pen touches the surface. The + /// `TouchId` is the unique identifier of the touch. It is valid as long as the finger/pen touches the surface. The /// next touch will receive a new unique ID. /// /// Refer to [`ActiveTouch`]. diff --git a/crates/egui/src/layout.rs b/crates/egui/src/layout.rs index a044dce9814..6c93297243a 100644 --- a/crates/egui/src/layout.rs +++ b/crates/egui/src/layout.rs @@ -13,7 +13,7 @@ pub(crate) struct Region { /// Always finite. /// /// The bounding box of all child widgets, but not necessarily a tight bounding box - /// since [`Ui`](crate::Ui) can start with a non-zero min_rect size. + /// since [`Ui`](crate::Ui) can start with a non-zero `min_rect` size. pub min_rect: Rect, /// The maximum size of this [`Ui`](crate::Ui). This is a *soft max* @@ -38,7 +38,7 @@ pub(crate) struct Region { /// So one can think of `cursor` as a constraint on the available region. /// /// If something has already been added, this will point to `style.spacing.item_spacing` beyond the latest child. - /// The cursor can thus be `style.spacing.item_spacing` pixels outside of the min_rect. + /// The cursor can thus be `style.spacing.item_spacing` pixels outside of the `min_rect`. pub(crate) cursor: Rect, } diff --git a/crates/egui/src/os.rs b/crates/egui/src/os.rs index 93db910deb4..766ecf55ae6 100644 --- a/crates/egui/src/os.rs +++ b/crates/egui/src/os.rs @@ -5,19 +5,19 @@ pub enum OperatingSystem { /// Unknown OS - could be wasm Unknown, - /// Android OS. + /// Android OS Android, - /// Apple iPhone OS. + /// Apple iPhone OS IOS, - /// Linux or Unix other than Android. + /// Linux or Unix other than Android Nix, - /// MacOS. + /// macOS Mac, - /// Windows. + /// Windows Windows, } diff --git a/crates/egui/src/style.rs b/crates/egui/src/style.rs index aad8e3eea2d..d2d7ce99188 100644 --- a/crates/egui/src/style.rs +++ b/crates/egui/src/style.rs @@ -152,7 +152,7 @@ pub struct Style { /// /// The most convenient way to look something up in this is to use [`TextStyle::resolve`]. /// - /// If you would like to overwrite app text_styles + /// If you would like to overwrite app `text_styles` /// /// ``` /// # let mut ctx = egui::Context::default(); diff --git a/crates/egui/src/util/undoer.rs b/crates/egui/src/util/undoer.rs index d5f004f86ae..cd11b6d1630 100644 --- a/crates/egui/src/util/undoer.rs +++ b/crates/egui/src/util/undoer.rs @@ -59,8 +59,8 @@ pub struct Undoer { /// Stores redos immediately after a sequence of undos. /// Gets cleared every time the state changes. - /// Does not need to be a deque, because there can only be up to undos.len() redos, - /// which is already limited to settings.max_undos. + /// Does not need to be a deque, because there can only be up to `undos.len()` redos, + /// which is already limited to `settings.max_undos`. redos: Vec, #[cfg_attr(feature = "serde", serde(skip))] diff --git a/crates/egui/src/viewport.rs b/crates/egui/src/viewport.rs index cce90487721..9dd71b4747b 100644 --- a/crates/egui/src/viewport.rs +++ b/crates/egui/src/viewport.rs @@ -1071,7 +1071,7 @@ pub enum ViewportCommand { /// This is equivalent to the system keyboard shortcut for copy (e.g. CTRL + C). RequestCopy, - /// Request a paste from the clipboard to the current focused TextEdit if any. + /// Request a paste from the clipboard to the current focused `TextEdit` if any. /// /// This is equivalent to the system keyboard shortcut for paste (e.g. CTRL + V). RequestPaste, diff --git a/crates/egui/src/widgets/text_edit/text_buffer.rs b/crates/egui/src/widgets/text_edit/text_buffer.rs index e70ce695af9..ea3992c57e4 100644 --- a/crates/egui/src/widgets/text_edit/text_buffer.rs +++ b/crates/egui/src/widgets/text_edit/text_buffer.rs @@ -220,7 +220,7 @@ impl TextBuffer for String { } fn replace_with(&mut self, text: &str) { - *self = text.to_owned(); + text.clone_into(self); } fn take(&mut self) -> String { diff --git a/crates/egui_demo_app/src/wrap_app.rs b/crates/egui_demo_app/src/wrap_app.rs index 98e74d0deea..42adf2b857a 100644 --- a/crates/egui_demo_app/src/wrap_app.rs +++ b/crates/egui_demo_app/src/wrap_app.rs @@ -464,7 +464,7 @@ impl WrapApp { // Collect dropped files: ctx.input(|i| { if !i.raw.dropped_files.is_empty() { - self.dropped_files = i.raw.dropped_files.clone(); + self.dropped_files.clone_from(&i.raw.dropped_files); } }); diff --git a/crates/egui_demo_lib/src/easy_mark/easy_mark_highlighter.rs b/crates/egui_demo_lib/src/easy_mark/easy_mark_highlighter.rs index 7431accc504..5c6bc2ef086 100644 --- a/crates/egui_demo_lib/src/easy_mark/easy_mark_highlighter.rs +++ b/crates/egui_demo_lib/src/easy_mark/easy_mark_highlighter.rs @@ -14,7 +14,7 @@ impl MemoizedEasymarkHighlighter { pub fn highlight(&mut self, egui_style: &egui::Style, code: &str) -> egui::text::LayoutJob { if (&self.style, self.code.as_str()) != (egui_style, code) { self.style = egui_style.clone(); - self.code = code.to_owned(); + code.clone_into(&mut self.code); self.output = highlight_easymark(egui_style, code); } self.output.clone() diff --git a/crates/egui_plot/src/items/values.rs b/crates/egui_plot/src/items/values.rs index 5f9fe8183f3..6e9bff096b6 100644 --- a/crates/egui_plot/src/items/values.rs +++ b/crates/egui_plot/src/items/values.rs @@ -123,12 +123,12 @@ impl LineStyle { } } -impl ToString for LineStyle { - fn to_string(&self) -> String { +impl std::fmt::Display for LineStyle { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Self::Solid => "Solid".into(), - Self::Dotted { spacing } => format!("Dotted{spacing}Px"), - Self::Dashed { length } => format!("Dashed{length}Px"), + Self::Solid => write!(f, "Solid"), + Self::Dotted { spacing } => write!(f, "Dotted({spacing} px)"), + Self::Dashed { length } => write!(f, "Dashed({length} px)"), } } } @@ -426,9 +426,9 @@ impl ExplicitGenerator { /// Result of [`super::PlotItem::find_closest()`] search, identifies an element inside the item for immediate use pub struct ClosestElem { - /// Position of hovered-over value (or bar/box-plot/...) in PlotItem + /// Position of hovered-over value (or bar/box-plot/...) in `PlotItem` pub index: usize, - /// Squared distance from the mouse cursor (needed to compare against other PlotItems, which might be nearer) + /// Squared distance from the mouse cursor (needed to compare against other `PlotItems`, which might be nearer) pub dist_sq: f32, } diff --git a/crates/emath/src/rot2.rs b/crates/emath/src/rot2.rs index da67acb0c9c..cb2272e2f8c 100644 --- a/crates/emath/src/rot2.rs +++ b/crates/emath/src/rot2.rs @@ -18,10 +18,10 @@ use super::Vec2; #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))] pub struct Rot2 { - /// angle.sin() + /// `angle.sin()` s: f32, - /// angle.cos() + /// `angle.cos()` c: f32, } diff --git a/crates/epaint/src/text/text_layout_types.rs b/crates/epaint/src/text/text_layout_types.rs index 5e4a56d9502..f0a18ba865d 100644 --- a/crates/epaint/src/text/text_layout_types.rs +++ b/crates/epaint/src/text/text_layout_types.rs @@ -453,9 +453,9 @@ pub struct Galley { /// `rect.top()` is always 0.0. /// /// With [`LayoutJob::halign`]: - /// * [`Align::LEFT`]: rect.left() == 0.0 - /// * [`Align::Center`]: rect.center() == 0.0 - /// * [`Align::RIGHT`]: rect.right() == 0.0 + /// * [`Align::LEFT`]: `rect.left() == 0.0` + /// * [`Align::Center`]: `rect.center() == 0.0` + /// * [`Align::RIGHT`]: `rect.right() == 0.0` pub rect: Rect, /// Tight bounding box around all the meshes in all the rows. diff --git a/examples/file_dialog/src/main.rs b/examples/file_dialog/src/main.rs index d0623a73a28..267c22e111c 100644 --- a/examples/file_dialog/src/main.rs +++ b/examples/file_dialog/src/main.rs @@ -78,7 +78,7 @@ impl eframe::App for MyApp { // Collect dropped files: ctx.input(|i| { if !i.raw.dropped_files.is_empty() { - self.dropped_files = i.raw.dropped_files.clone(); + self.dropped_files.clone_from(&i.raw.dropped_files); } }); }