diff --git a/src/function_entry.rs b/src/function_entry.rs index afe02a2..0a7934c 100644 --- a/src/function_entry.rs +++ b/src/function_entry.rs @@ -10,7 +10,10 @@ use egui::{ }; use epaint::Color32; use parsing::parsing::{process_func_str, BackingFunction}; -use std::fmt::{self, Debug}; +use std::{ + fmt::{self, Debug}, + intrinsics::assume, +}; #[cfg(threading)] use rayon::iter::ParallelIterator; @@ -233,6 +236,8 @@ impl FunctionEntry { let resolution: f64 = settings.plot_width as f64 / (max_x.abs() + min_x.abs()); let resolution_iter = resolution_helper(&settings.plot_width + 1, min_x, &resolution); + unsafe { assume(!resolution_iter.is_empty()) } + // Makes sure proper arguments are passed when integral is enabled if self.integral && settings.integral_changed { self.invalidate_integral(); @@ -330,6 +335,10 @@ impl FunctionEntry { .collect(); debug_assert_eq!(data.len(), settings.plot_width + 1); self.derivative_data = data; + + unsafe { + assume(!self.derivative_data.is_empty()); + } } if self.nth_derviative && self.nth_derivative_data.is_none() { @@ -338,6 +347,10 @@ impl FunctionEntry { .collect(); debug_assert_eq!(data.len(), settings.plot_width + 1); self.nth_derivative_data = Some(data); + + unsafe { + assume(self.nth_derivative_data.is_some()); + } } } @@ -351,6 +364,9 @@ impl FunctionEntry { ); self.integral_data = Some((data.iter().map(|(x, y)| Bar::new(*x, *y)).collect(), area)); + unsafe { + assume(self.integral_data.is_some()); + } } } else { self.invalidate_integral(); diff --git a/src/lib.rs b/src/lib.rs index f46ce7f..06fcfa2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,7 @@ #![feature(let_chains)] #![feature(stmt_expr_attributes)] #![feature(const_trait_impl)] +#![feature(core_intrinsics)] #[macro_use] extern crate static_assertions; diff --git a/src/main.rs b/src/main.rs index d33928e..5bfdce3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ #![feature(let_chains)] #![feature(stmt_expr_attributes)] #![feature(const_trait_impl)] +#![feature(core_intrinsics)] #[macro_use] extern crate static_assertions; diff --git a/src/widgets.rs b/src/widgets.rs index 664d993..013fbe2 100644 --- a/src/widgets.rs +++ b/src/widgets.rs @@ -1,3 +1,5 @@ +use std::intrinsics::assume; + use egui::{text::CCursor, text_edit::CursorRange, TextEdit}; use epaint::text::cursor::{Cursor, PCursor, RCursor}; use parsing::suggestions::{self, generate_hint, Hint}; @@ -52,6 +54,12 @@ impl<'a> AutoComplete<'a> { match self.hint { Hint::Many(hints) => { + // Impossible for plural hints to be singular or non-existant + unsafe { + assume(hints.len() > 1); + assume(!hints.is_empty()); + } + match movement { Movement::Up => { // subtract one, if fail, set to maximum index value. @@ -65,6 +73,8 @@ impl<'a> AutoComplete<'a> { } } Movement::Complete => { + unsafe { assume(hints.len() >= (self.i + 1)) } + self.apply_hint(hints[self.i]); } Movement::None => {} @@ -87,7 +97,7 @@ impl<'a> AutoComplete<'a> { /// Moves cursor of TextEdit `te_id` to the end pub fn move_cursor_to_end(ctx: &egui::Context, te_id: egui::Id) { - let mut state = TextEdit::load_state(ctx, te_id).expect("Expected TextEdit"); + let mut state = unsafe { TextEdit::load_state(ctx, te_id).unwrap_unchecked() }; state.set_cursor_range(Some(CursorRange::one(Cursor { ccursor: CCursor { index: 0,