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

Add assert messages and print bad argument values in asserts (#5216)

Enabled the `missing_assert_message` lint

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

---------

Co-authored-by: Lucas Meurer <lucasmeurer96@gmail.com>
This commit is contained in:
Nicolas
2025-03-25 09:20:29 +01:00
committed by GitHub
parent 903bd81313
commit 58b2ac88c0
35 changed files with 331 additions and 108 deletions

View File

@@ -96,7 +96,7 @@ impl BytesLoader for FileLoader {
Err(err) => Err(err.to_string()),
};
let prev = cache.lock().insert(uri.clone(), Poll::Ready(result));
assert!(matches!(prev, Some(Poll::Pending)));
assert!(matches!(prev, Some(Poll::Pending)), "unexpected state");
ctx.request_repaint();
log::trace!("finished loading {uri:?}");
}

View File

@@ -32,7 +32,10 @@ impl Size {
/// Relative size relative to all available space. Values must be in range `0.0..=1.0`.
pub fn relative(fraction: f32) -> Self {
debug_assert!(0.0 <= fraction && fraction <= 1.0);
debug_assert!(
0.0 <= fraction && fraction <= 1.0,
"fraction should be in the range [0, 1], but was {fraction}"
);
Self::Relative {
fraction,
range: Rangef::new(0.0, f32::INFINITY),
@@ -121,7 +124,10 @@ impl Sizing {
.map(|&size| match size {
Size::Absolute { initial, .. } => initial,
Size::Relative { fraction, range } => {
assert!(0.0 <= fraction && fraction <= 1.0);
assert!(
0.0 <= fraction && fraction <= 1.0,
"fraction should be in the range [0, 1], but was {fraction}"
);
range.clamp(length * fraction)
}
Size::Remainder { .. } => {

View File

@@ -490,8 +490,15 @@ impl Highlighter {
fn as_byte_range(whole: &str, range: &str) -> std::ops::Range<usize> {
let whole_start = whole.as_ptr() as usize;
let range_start = range.as_ptr() as usize;
assert!(whole_start <= range_start);
assert!(range_start + range.len() <= whole_start + whole.len());
assert!(
whole_start <= range_start,
"range must be within whole, but was {range}"
);
assert!(
range_start + range.len() <= whole_start + whole.len(),
"range_start + range length must be smaller than whole_start + whole length, but was {}",
range_start + range.len()
);
let offset = range_start - whole_start;
offset..(offset + range.len())
}