1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 21:30:03 -04:00

Enable the clippy::pedantic lint group (#8429)

Instead of opting in to pedantic lints one by one, enable the whole
group and opt out of the noisy ones.

64% of the pedantic lints were already listed individually. This deletes
90 explicit lint lines, enables 51 pedantic lints we never listed, and
picks up new pedantic lints for free. Each opt-out carries its hit
count, so the cost of turning one back on is visible.

`restriction` and `nursery` stay opt-in per lint.

Stacked on top of #8430, which fixes the one real bug the new lints
found.

* [x] I have followed the instructions in the PR template

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Emil Ernerfeldt
2026-08-17 21:55:53 -07:00
committed by GitHub
parent 9bb36b0ac2
commit 34b39d564b
12 changed files with 97 additions and 159 deletions

View File

@@ -41,7 +41,6 @@ impl Hsva {
/// From linear RGBA with premultiplied alpha
#[inline]
pub fn from_rgba_premultiplied(r: f32, g: f32, b: f32, a: f32) -> Self {
#![expect(clippy::many_single_char_names)]
if a <= 0.0 {
if r == 0.0 && b == 0.0 && a == 0.0 {
Self::default()
@@ -57,7 +56,6 @@ impl Hsva {
/// From linear RGBA without premultiplied alpha
#[inline]
pub fn from_rgba_unmultiplied(r: f32, g: f32, b: f32, a: f32) -> Self {
#![expect(clippy::many_single_char_names)]
let (h, s, v) = hsv_from_rgb([r, g, b]);
Self { h, s, v, a }
}
@@ -189,7 +187,6 @@ impl From<Color32> for Hsva {
/// All ranges in 0-1, rgb is linear.
#[inline]
pub fn hsv_from_rgb([r, g, b]: [f32; 3]) -> (f32, f32, f32) {
#![expect(clippy::many_single_char_names)]
let min = r.min(g.min(b));
let max = r.max(g.max(b)); // value
@@ -213,7 +210,6 @@ pub fn hsv_from_rgb([r, g, b]: [f32; 3]) -> (f32, f32, f32) {
/// All ranges in 0-1, rgb is linear.
#[inline]
pub fn rgb_from_hsv((h, s, v): (f32, f32, f32)) -> [f32; 3] {
#![expect(clippy::many_single_char_names)]
let h = (h.fract() + 1.0).fract(); // wrap
let s = s.clamp(0.0, 1.0);

View File

@@ -161,16 +161,16 @@ fn set_app_icon_windows(icon_data: &IconData) -> AppIconStatus {
if icon_big.is_null() {
log::warn!("Failed to create HICON (for big icon) from embedded png data.");
return AppIconStatus::NotSetIgnored; // We could try independently with the small icon but what's the point, it would look bad!
} else {
// SAFETY: Unsafe WinApi function, takes objects previously created with WinAPI, all checked for null prior.
unsafe {
SendMessageW(
window_handle,
WM_SETICON,
ICON_BIG as usize,
icon_big as isize,
);
}
}
// SAFETY: Unsafe WinApi function, takes objects previously created with WinAPI, all checked for null prior.
unsafe {
SendMessageW(
window_handle,
WM_SETICON,
ICON_BIG as usize,
icon_big as isize,
);
}
}
{
@@ -180,16 +180,16 @@ fn set_app_icon_windows(icon_data: &IconData) -> AppIconStatus {
if icon_small.is_null() {
log::warn!("Failed to create HICON (for small icon) from embedded png data.");
return AppIconStatus::NotSetIgnored;
} else {
// SAFETY: Unsafe WinApi function, takes objects previously created with WinAPI, all checked for null prior.
unsafe {
SendMessageW(
window_handle,
WM_SETICON,
ICON_SMALL as usize,
icon_small as isize,
);
}
}
// SAFETY: Unsafe WinApi function, takes objects previously created with WinAPI, all checked for null prior.
unsafe {
SendMessageW(
window_handle,
WM_SETICON,
ICON_SMALL as usize,
icon_small as isize,
);
}
}

View File

@@ -67,7 +67,7 @@ fn roaming_appdata() -> Option<PathBuf> {
&FOLDERID_RoamingAppData,
KF_FLAG_DONT_VERIFY as u32,
core::ptr::null_mut(),
&mut path_raw,
&raw mut path_raw,
)
};

View File

@@ -1761,11 +1761,11 @@ impl Context {
.get(&id)
.map(|v| v.repaint.cumulative_frame_nr)
.unwrap_or_else(|| {
if cfg!(debug_assertions) {
panic!("cumulative_frame_nr_for failed to find the viewport {id:?}");
} else {
0
}
debug_assert!(
false,
"cumulative_frame_nr_for failed to find the viewport {id:?}"
);
0
})
})
}

View File

@@ -41,6 +41,13 @@ impl<T: core::hash::Hash + core::fmt::Debug> AsId for T {}
/// This is niche-optimized to that `Option<Id>` is the same size as `Id`.
#[derive(Clone, Copy, Hash, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(
feature = "serde",
expect(
clippy::unsafe_derive_deserialize,
reason = "`from_high_entropy_bits` is only `unsafe` about entropy, not memory safety"
)
)]
pub struct Id(NonZeroU64);
impl nohash_hasher::IsEnabled for Id {}

View File

@@ -118,15 +118,15 @@ impl<'a> Parser<'a> {
{
let language = &language_start[..newline];
let code_start = &language_start[newline + 1..];
if let Some(end) = code_start.find("\n```") {
return if let Some(end) = code_start.find("\n```") {
let code = &code_start[..end].trim();
self.s = &code_start[end + 4..];
self.start_of_line = false;
return Some(Item::CodeBlock(language, code));
Some(Item::CodeBlock(language, code))
} else {
self.s = "";
return Some(Item::CodeBlock(language, code_start));
}
Some(Item::CodeBlock(language, code_start))
};
}
None
}
@@ -138,18 +138,18 @@ impl<'a> Parser<'a> {
self.start_of_line = false;
self.style.code = true;
let rest_of_line = &self.s[..self.s.find('\n').unwrap_or(self.s.len())];
if let Some(end) = rest_of_line.find('`') {
return if let Some(end) = rest_of_line.find('`') {
let item = Item::Text(self.style, &self.s[..end]);
self.s = &self.s[end + 1..];
self.style.code = false;
return Some(item);
Some(item)
} else {
let end = rest_of_line.len();
let item = Item::Text(self.style, rest_of_line);
self.s = &self.s[end..];
self.style.code = false;
return Some(item);
}
Some(item)
};
}
None
}

View File

@@ -210,6 +210,13 @@ impl SyntectTheme {
derive(serde::Deserialize, serde::Serialize),
serde(default)
)]
#[cfg_attr(
all(feature = "serde", not(feature = "syntect")),
expect(
clippy::unsafe_derive_deserialize,
reason = "the `enum_map!` macro expands to `unsafe` code"
)
)]
pub struct CodeTheme {
dark_mode: bool,

View File

@@ -247,16 +247,16 @@ impl<'a, State> Harness<'a, State> {
pub fn step(&mut self) {
let events = core::mem::take(&mut *self.queued_events.lock());
if events.is_empty() {
self._step(false);
self.step_impl(false);
}
for event in events {
self.input.events.push(event);
self._step(false);
self.step_impl(false);
}
}
/// Run a single step. This will not process any events.
fn _step(&mut self, sizing_pass: bool) {
fn step_impl(&mut self, sizing_pass: bool) {
self.input.predicted_dt = self.step_dt;
let mut output = self.ctx.run_ui(self.input.take(), |ui| {
@@ -297,7 +297,7 @@ impl<'a, State> Harness<'a, State> {
/// [`Harness::new_ui`] / [`Harness::new_ui_state`] or
/// [`HarnessBuilder::build_ui`] / [`HarnessBuilder::build_ui_state`].
pub fn fit_contents(&mut self) {
self._step(true);
self.step_impl(true);
// Calculate size including all content (main UI + popups + tooltips)
if let Some(rect) = self.compute_total_rect_with_popups() {
@@ -333,7 +333,7 @@ impl<'a, State> Harness<'a, State> {
}
}
fn _try_run(&mut self, sleep: bool) -> Result<u64, ExceededMaxStepsError> {
fn try_run_impl(&mut self, sleep: bool) -> Result<u64, ExceededMaxStepsError> {
let mut steps = 0;
loop {
steps += 1;
@@ -374,7 +374,7 @@ impl<'a, State> Harness<'a, State> {
/// - [`Harness::run_steps`].
/// - [`Harness::try_run_realtime`].
pub fn try_run(&mut self) -> Result<u64, ExceededMaxStepsError> {
self._try_run(false)
self.try_run_impl(false)
}
/// Run until
@@ -414,7 +414,7 @@ impl<'a, State> Harness<'a, State> {
/// - [`Harness::run_steps`].
/// - [`Harness::try_run`].
pub fn try_run_realtime(&mut self) -> Result<u64, ExceededMaxStepsError> {
self._try_run(true)
self.try_run_impl(true)
}
/// Run a number of steps.

View File

@@ -535,31 +535,31 @@ fn try_image_snapshot_options_impl(
Ok(image) => image.to_rgba8(),
Err(err) => {
// No previous snapshot - probably a new test.
if mode.is_update() {
return update_snapshot();
return if mode.is_update() {
update_snapshot()
} else {
write_new_png()?;
return Err(SnapshotError::OpenSnapshot {
Err(SnapshotError::OpenSnapshot {
path: snapshot_path.clone(),
err,
});
}
})
};
}
};
if previous.dimensions() != new.dimensions() {
if mode.is_update() {
return update_snapshot();
return if mode.is_update() {
update_snapshot()
} else {
write_new_png()?;
return Err(SnapshotError::SizeMismatch {
Err(SnapshotError::SizeMismatch {
name,
expected: previous.dimensions(),
actual: new.dimensions(),
});
}
})
};
}
// Compare existing image to the new one:

View File

@@ -1,5 +1,3 @@
#![expect(clippy::many_single_char_names)]
use core::ops::Range;
use crate::{Color32, PathShape, PathStroke, Shape};

View File

@@ -1519,11 +1519,11 @@ impl Tessellator {
if stroke.is_empty() {
return; // we are done
} else {
// we still need to do the stroke
fill = Color32::TRANSPARENT; // don't fill again below
break;
}
// we still need to do the stroke
fill = Color32::TRANSPARENT; // don't fill again below
break;
}
}
}