diff --git a/.cargo/config.toml b/.cargo/config.toml index b809c283..1d940b5c 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -50,7 +50,6 @@ rustflags = [ "-Wclippy::missing_enforced_import_renames", "-Wclippy::missing_errors_doc", "-Wclippy::missing_safety_doc", - # "-Wclippy::mod_module_files", // Enable when we update MSRV "-Wclippy::mut_mut", "-Wclippy::mutex_integer", "-Wclippy::needless_borrow", diff --git a/egui/src/input_state.rs b/egui/src/input_state.rs index 61f576a4..87e59cd4 100644 --- a/egui/src/input_state.rs +++ b/egui/src/input_state.rs @@ -101,9 +101,7 @@ impl Default for InputState { impl InputState { #[must_use] pub fn begin_frame(mut self, new: RawInput) -> InputState { - let time = new - .time - .unwrap_or_else(|| self.time + new.predicted_dt as f64); + let time = new.time.unwrap_or(self.time + new.predicted_dt as f64); let unstable_dt = (time - self.time) as f32; let screen_rect = new.screen_rect.unwrap_or(self.screen_rect); self.create_touch_states_for_new_devices(&new.events); diff --git a/egui/src/layout.rs b/egui/src/layout.rs index 40860983..a245a3ad 100644 --- a/egui/src/layout.rs +++ b/egui/src/layout.rs @@ -772,32 +772,30 @@ impl Layout { let cursor = region.cursor; let next_pos = self.next_widget_position(region); - let align; - let l = 64.0; - match self.main_dir { + let align = match self.main_dir { Direction::LeftToRight => { painter.line_segment([cursor.left_top(), cursor.left_bottom()], stroke); painter.arrow(next_pos, vec2(l, 0.0), stroke); - align = Align2([Align::LEFT, self.vertical_align()]); + Align2([Align::LEFT, self.vertical_align()]) } Direction::RightToLeft => { painter.line_segment([cursor.right_top(), cursor.right_bottom()], stroke); painter.arrow(next_pos, vec2(-l, 0.0), stroke); - align = Align2([Align::RIGHT, self.vertical_align()]); + Align2([Align::RIGHT, self.vertical_align()]) } Direction::TopDown => { painter.line_segment([cursor.left_top(), cursor.right_top()], stroke); painter.arrow(next_pos, vec2(0.0, l), stroke); - align = Align2([self.horizontal_align(), Align::TOP]); + Align2([self.horizontal_align(), Align::TOP]) } Direction::BottomUp => { painter.line_segment([cursor.left_bottom(), cursor.right_bottom()], stroke); painter.arrow(next_pos, vec2(0.0, -l), stroke); - align = Align2([self.horizontal_align(), Align::BOTTOM]); + Align2([self.horizontal_align(), Align::BOTTOM]) } - } + }; painter.debug_text(next_pos, align, stroke.color, text); } diff --git a/egui/src/menu.rs b/egui/src/menu.rs index cc2f4550..948d3fc3 100644 --- a/egui/src/menu.rs +++ b/egui/src/menu.rs @@ -213,7 +213,7 @@ impl MenuRootManager { ) -> Option> { if let Some(root) = self.inner.as_mut() { let (menu_response, inner_response) = root.show(response, add_contents); - if let MenuResponse::Close = menu_response { + if MenuResponse::Close == menu_response { self.inner = None; } inner_response diff --git a/egui_demo_lib/src/apps/demo/password.rs b/egui_demo_lib/src/apps/demo/password.rs index bb2f1d9c..487a44a7 100644 --- a/egui_demo_lib/src/apps/demo/password.rs +++ b/egui_demo_lib/src/apps/demo/password.rs @@ -8,6 +8,7 @@ /// ``` ignore /// password_ui(ui, &mut my_password); /// ``` +#[allow(clippy::ptr_arg)] // false positive pub fn password_ui(ui: &mut egui::Ui, password: &mut String) -> egui::Response { // This widget has its own state — show or hide password characters (`show_plaintext`). // In this case we use a simple `bool`, but you can also declare your own type. diff --git a/egui_demo_lib/src/backend_panel.rs b/egui_demo_lib/src/backend_panel.rs index f040102e..100d5de8 100644 --- a/egui_demo_lib/src/backend_panel.rs +++ b/egui_demo_lib/src/backend_panel.rs @@ -41,6 +41,7 @@ impl Default for RunMode { // ---------------------------------------------------------------------------- +#[derive(Default)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "serde", serde(default))] pub struct BackendPanel { @@ -60,18 +61,6 @@ pub struct BackendPanel { egui_windows: EguiWindows, } -impl Default for BackendPanel { - fn default() -> Self { - Self { - open: false, - run_mode: Default::default(), - pixels_per_point: Default::default(), - frame_history: Default::default(), - egui_windows: Default::default(), - } - } -} - impl BackendPanel { pub fn update(&mut self, ctx: &egui::Context, frame: &mut epi::Frame) { self.frame_history diff --git a/egui_demo_lib/src/easy_mark/easy_mark_parser.rs b/egui_demo_lib/src/easy_mark/easy_mark_parser.rs index ef66f8e6..5258c5b1 100644 --- a/egui_demo_lib/src/easy_mark/easy_mark_parser.rs +++ b/egui_demo_lib/src/easy_mark/easy_mark_parser.rs @@ -133,7 +133,7 @@ impl<'a> Parser<'a> { self.s = rest; self.start_of_line = false; self.style.code = true; - let rest_of_line = &self.s[..self.s.find('\n').unwrap_or_else(|| self.s.len())]; + let rest_of_line = &self.s[..self.s.find('\n').unwrap_or(self.s.len())]; if let Some(end) = rest_of_line.find('`') { let item = Item::Text(self.style, &self.s[..end]); self.s = &self.s[end + 1..]; @@ -153,7 +153,7 @@ impl<'a> Parser<'a> { /// `` or `[link](url)` fn url(&mut self) -> Option> { if self.s.starts_with('<') { - let this_line = &self.s[..self.s.find('\n').unwrap_or_else(|| self.s.len())]; + let this_line = &self.s[..self.s.find('\n').unwrap_or(self.s.len())]; if let Some(url_end) = this_line.find('>') { let url = &self.s[1..url_end]; self.s = &self.s[url_end + 1..]; @@ -164,7 +164,7 @@ impl<'a> Parser<'a> { // [text](url) if self.s.starts_with('[') { - let this_line = &self.s[..self.s.find('\n').unwrap_or_else(|| self.s.len())]; + let this_line = &self.s[..self.s.find('\n').unwrap_or(self.s.len())]; if let Some(bracket_end) = this_line.find(']') { let text = &this_line[1..bracket_end]; if this_line[bracket_end + 1..].starts_with('(') { @@ -217,7 +217,7 @@ impl<'a> Iterator for Parser<'a> { if self.start_of_line { // leading space (indentation) if self.s.starts_with(' ') { - let length = self.s.find(|c| c != ' ').unwrap_or_else(|| self.s.len()); + let length = self.s.find(|c| c != ' ').unwrap_or(self.s.len()); self.s = &self.s[length..]; self.start_of_line = true; // indentation doesn't count return Some(Item::Indentation(length)); diff --git a/egui_demo_lib/src/syntax_highlighting.rs b/egui_demo_lib/src/syntax_highlighting.rs index 2bf78167..086b20fa 100644 --- a/egui_demo_lib/src/syntax_highlighting.rs +++ b/egui_demo_lib/src/syntax_highlighting.rs @@ -404,7 +404,7 @@ impl Highlighter { while !text.is_empty() { if text.starts_with("//") { - let end = text.find('\n').unwrap_or_else(|| text.len()); + let end = text.find('\n').unwrap_or(text.len()); job.append(&text[..end], 0.0, theme.formats[TokenType::Comment].clone()); text = &text[end..]; } else if text.starts_with('"') { @@ -412,7 +412,7 @@ impl Highlighter { .find('"') .map(|i| i + 2) .or_else(|| text.find('\n')) - .unwrap_or_else(|| text.len()); + .unwrap_or(text.len()); job.append( &text[..end], 0.0, diff --git a/egui_glow/src/shader_version.rs b/egui_glow/src/shader_version.rs index 84c2434f..86749e3d 100644 --- a/egui_glow/src/shader_version.rs +++ b/egui_glow/src/shader_version.rs @@ -29,7 +29,9 @@ impl ShaderVersion { pub(crate) fn parse(glsl_ver: &str) -> Self { let start = glsl_ver.find(|c| char::is_ascii_digit(&c)).unwrap(); let es = glsl_ver[..start].contains(" ES "); - let ver = glsl_ver[start..].splitn(2, ' ').next().unwrap(); + let ver = glsl_ver[start..] + .split_once(' ') + .map_or(&glsl_ver[start..], |x| x.0); let [maj, min]: [u8; 2] = ver .splitn(3, '.') .take(2) diff --git a/egui_web/src/input.rs b/egui_web/src/input.rs index 042290e6..92ec2b2a 100644 --- a/egui_web/src/input.rs +++ b/egui_web/src/input.rs @@ -29,17 +29,16 @@ pub fn pos_from_touch_event( event: &web_sys::TouchEvent, touch_id_for_pos: &mut Option, ) -> egui::Pos2 { - let touch_for_pos; - if let Some(touch_id_for_pos) = touch_id_for_pos { + let touch_for_pos = if let Some(touch_id_for_pos) = touch_id_for_pos { // search for the touch we previously used for the position // (unfortunately, `event.touches()` is not a rust collection): - touch_for_pos = (0..event.touches().length()) + (0..event.touches().length()) .into_iter() .map(|i| event.touches().get(i).unwrap()) - .find(|touch| egui::TouchId::from(touch.identifier()) == *touch_id_for_pos); + .find(|touch| egui::TouchId::from(touch.identifier()) == *touch_id_for_pos) } else { - touch_for_pos = None; - } + None + }; // Use the touch found above or pick the first, or return a default position if there is no // touch at all. (The latter is not expected as the current method is only called when there is // at least one touch.) diff --git a/epaint/src/text/text_layout.rs b/epaint/src/text/text_layout.rs index 9294d1af..a03978cd 100644 --- a/epaint/src/text/text_layout.rs +++ b/epaint/src/text/text_layout.rs @@ -250,7 +250,9 @@ fn line_break( if row_start_idx < paragraph.glyphs.len() { if non_empty_rows == job.wrap.max_rows { - replace_last_glyph_with_overflow_character(fonts, job, out_rows); + if let Some(last_row) = out_rows.last_mut() { + replace_last_glyph_with_overflow_character(fonts, job, last_row); + } } else { let glyphs: Vec = paragraph.glyphs[row_start_idx..] .iter() @@ -277,18 +279,13 @@ fn line_break( fn replace_last_glyph_with_overflow_character( fonts: &mut FontsImpl, job: &LayoutJob, - out_rows: &mut Vec, + row: &mut Row, ) { let overflow_character = match job.wrap.overflow_character { Some(c) => c, None => return, }; - let row = match out_rows.last_mut() { - Some(r) => r, - None => return, - }; - loop { let (prev_glyph, last_glyph) = match row.glyphs.as_mut_slice() { [.., prev, last] => (Some(prev), last), diff --git a/sh/check.sh b/sh/check.sh index 51e344c0..d632be95 100755 --- a/sh/check.sh +++ b/sh/check.sh @@ -65,3 +65,5 @@ cargo deny check # what compiles slowly? # cargo llvm-lines --lib -p egui | head -20 + +echo "All checks passed."