mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 06:10:06 -04:00
Enable a few more clippy lints (#8064)
Enable these new clippy lints and fix all warnings: * `format_push_string` — use `write!` instead of `s += &format!(…)` to avoid extra allocations * `ignored_unit_patterns` — use `()` instead of `_` when matching unit * `missing_fields_in_debug` — ensure manual `Debug` impls account for all fields * `needless_raw_string_hashes` — remove unnecessary `r#` on string literals * `ref_option` — prefer `Option<&T>` over `&Option<T>` in function signatures
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use std::fmt::Write as _;
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Frame {
|
||||
/// `_main` is usually as the deepest depth.
|
||||
@@ -23,7 +25,7 @@ pub fn capture() -> String {
|
||||
if let Some(file_and_line) = &mut file_and_line
|
||||
&& let Some(line_nr) = symbol.lineno()
|
||||
{
|
||||
file_and_line.push_str(&format!(":{line_nr}"));
|
||||
write!(file_and_line, ":{line_nr}").ok();
|
||||
}
|
||||
let file_and_line = file_and_line.unwrap_or_default();
|
||||
|
||||
@@ -130,12 +132,14 @@ pub fn capture() -> String {
|
||||
|
||||
if frame.depth + 1 < last_depth || last_depth + 1 < frame.depth {
|
||||
// Show that some frames were elided
|
||||
formatted.push_str(&format!("{:widest_depth$} …\n", ""));
|
||||
writeln!(formatted, "{:widest_depth$} …", "").ok();
|
||||
}
|
||||
|
||||
formatted.push_str(&format!(
|
||||
"{depth:widest_depth$}: {file_and_line:widest_file_line$} {name}\n"
|
||||
));
|
||||
writeln!(
|
||||
formatted,
|
||||
"{depth:widest_depth$}: {file_and_line:widest_file_line$} {name}"
|
||||
)
|
||||
.ok();
|
||||
|
||||
last_depth = frame.depth;
|
||||
}
|
||||
|
||||
@@ -673,7 +673,7 @@ impl Window<'_> {
|
||||
|
||||
title_bar.ui(
|
||||
&mut area_content_ui,
|
||||
&content_response,
|
||||
content_response.as_ref(),
|
||||
open.as_deref_mut(),
|
||||
&mut collapsing,
|
||||
collapsible,
|
||||
@@ -1256,7 +1256,7 @@ impl TitleBar {
|
||||
fn ui(
|
||||
self,
|
||||
ui: &mut Ui,
|
||||
content_response: &Option<Response>,
|
||||
content_response: Option<&Response>,
|
||||
open: Option<&mut bool>,
|
||||
collapsing: &mut CollapsingState,
|
||||
collapsible: bool,
|
||||
@@ -1300,7 +1300,7 @@ impl TitleBar {
|
||||
ui.visuals().text_color(),
|
||||
);
|
||||
|
||||
if let Some(content_response) = &content_response {
|
||||
if let Some(content_response) = content_response {
|
||||
// Paint separator between title and content:
|
||||
let content_rect = content_response.rect;
|
||||
if false {
|
||||
|
||||
@@ -2428,6 +2428,7 @@ impl Context {
|
||||
#[cfg(debug_assertions)]
|
||||
fn debug_painting(&self) {
|
||||
#![expect(clippy::iter_over_hash_type)] // ok to be sloppy in debug painting
|
||||
use std::fmt::Write as _;
|
||||
|
||||
let paint_widget = |widget: &WidgetRect, text: &str, color: Color32| {
|
||||
let rect = widget.interact_rect;
|
||||
@@ -2500,13 +2501,17 @@ impl Context {
|
||||
for id in contains_pointer {
|
||||
let mut widget_text = format!("{id:?}");
|
||||
if let Some(rect) = widget_rects.get(id) {
|
||||
widget_text +=
|
||||
&format!(" {:?} {:?} {:?}", rect.layer_id, rect.rect, rect.sense);
|
||||
write!(
|
||||
widget_text,
|
||||
" {:?} {:?} {:?}",
|
||||
rect.layer_id, rect.rect, rect.sense
|
||||
)
|
||||
.ok();
|
||||
}
|
||||
if let Some(info) = widget_rects.info(id) {
|
||||
widget_text += &format!(" {info:?}");
|
||||
write!(widget_text, " {info:?}").ok();
|
||||
}
|
||||
debug_text += &format!("{widget_text}\n");
|
||||
writeln!(debug_text, "{widget_text}").ok();
|
||||
}
|
||||
self.debug_text(debug_text);
|
||||
}
|
||||
@@ -2571,7 +2576,7 @@ impl Context {
|
||||
);
|
||||
self.viewport(|vp| {
|
||||
for reason in &vp.output.request_discard_reasons {
|
||||
warning += &format!("\n {reason}");
|
||||
write!(warning, "\n {reason}").ok();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -376,12 +376,14 @@ impl ViewportInfo {
|
||||
ui.label(opt_as_str(&visible));
|
||||
ui.end_row();
|
||||
|
||||
#[expect(clippy::ref_option)]
|
||||
fn opt_rect_as_string(v: &Option<Rect>) -> String {
|
||||
v.as_ref().map_or(String::new(), |r| {
|
||||
format!("Pos: {:?}, size: {:?}", r.min, r.size())
|
||||
})
|
||||
}
|
||||
|
||||
#[expect(clippy::ref_option)]
|
||||
fn opt_as_str<T: std::fmt::Debug>(v: &Option<T>) -> String {
|
||||
v.as_ref().map_or(String::new(), |v| format!("{v:?}"))
|
||||
}
|
||||
|
||||
@@ -49,10 +49,15 @@ fn pos_in_galley(galley: &Galley, ccursor: CCursor) -> Pos2 {
|
||||
|
||||
impl std::fmt::Debug for WidgetTextCursor {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let Self {
|
||||
widget_id,
|
||||
ccursor,
|
||||
pos: _,
|
||||
} = self;
|
||||
f.debug_struct("WidgetTextCursor")
|
||||
.field("widget_id", &self.widget_id.short_debug_format())
|
||||
.field("ccursor", &self.ccursor.index)
|
||||
.finish()
|
||||
.field("widget_id", &widget_id.short_debug_format())
|
||||
.field("ccursor", &ccursor.index)
|
||||
.finish_non_exhaustive()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -551,7 +551,7 @@ impl Widget for DragValue<'_> {
|
||||
if let Some(value_text) = value_text {
|
||||
// We were editing the value as text last frame, but lost focus.
|
||||
// Make sure we applied the last text value:
|
||||
let parsed_value = parse(&custom_parser, &value_text);
|
||||
let parsed_value = parse(custom_parser.as_ref(), &value_text);
|
||||
if let Some(mut parsed_value) = parsed_value {
|
||||
// User edits always clamps:
|
||||
parsed_value = clamp_value_to_range(parsed_value, range.clone());
|
||||
@@ -591,7 +591,7 @@ impl Widget for DragValue<'_> {
|
||||
response.lost_focus() && !ui.input(|i| i.key_pressed(Key::Escape))
|
||||
};
|
||||
if update {
|
||||
let parsed_value = parse(&custom_parser, &value_text);
|
||||
let parsed_value = parse(custom_parser.as_ref(), &value_text);
|
||||
if let Some(mut parsed_value) = parsed_value {
|
||||
// User edits always clamps:
|
||||
parsed_value = clamp_value_to_range(parsed_value, range.clone());
|
||||
@@ -733,8 +733,8 @@ impl Widget for DragValue<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
fn parse(custom_parser: &Option<NumParser<'_>>, value_text: &str) -> Option<f64> {
|
||||
match &custom_parser {
|
||||
fn parse(custom_parser: Option<&NumParser<'_>>, value_text: &str) -> Option<f64> {
|
||||
match custom_parser {
|
||||
Some(parser) => parser(value_text),
|
||||
None => default_parser(value_text),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user