diff --git a/crates/printf/src/fmt_fp/decimal.rs b/crates/printf/src/fmt_fp/decimal.rs index bc8a8205a..e516d3b96 100644 --- a/crates/printf/src/fmt_fp/decimal.rs +++ b/crates/printf/src/fmt_fp/decimal.rs @@ -266,7 +266,7 @@ fn should_round_up(&self, digit_idx: i32, remainder: u32, mod_base: u32) -> bool if rounding_digit & 1 != 0 { round += 2.0; // round now has an odd lsb (though round itself is even). - debug_assert!(round.to_bits() & 1 != 0); + debug_assert_ne!(round.to_bits() & 1, 0); } // Set 'small' to a value which is less than halfway, exactly halfway, or more than halfway diff --git a/src/ast.rs b/src/ast.rs index 4740b234d..ed912de3e 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -2131,12 +2131,10 @@ fn peek_type(&mut self, idx: usize) -> ParseTokenType { /// Return the token. fn consume_any_token(&mut self) -> ParseToken { let tok = self.tokens.pop(); - assert!( - tok.typ != ParseTokenType::Comment, - "Should not be a comment" - ); - assert!( - tok.typ != ParseTokenType::Terminate, + assert_ne!(tok.typ, ParseTokenType::Comment, "Should not be a comment"); + assert_ne!( + tok.typ, + ParseTokenType::Terminate, "Cannot consume terminate token, caller should check status first" ); tok @@ -2144,8 +2142,9 @@ fn consume_any_token(&mut self) -> ParseToken { /// Consume the next token which is expected to be of the given type. fn consume_token_type(&mut self, typ: ParseTokenType) -> SourceRange { - assert!( - typ != ParseTokenType::Terminate, + assert_ne!( + typ, + ParseTokenType::Terminate, "Should not attempt to consume terminate token" ); let tok = self.consume_any_token(); diff --git a/src/expand.rs b/src/expand.rs index cb614bfeb..e647701f9 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -116,7 +116,7 @@ pub fn ok() -> Self { } /// Make an error value with the given status. pub fn make_error(status: libc::c_int) -> Self { - assert!(status != 0, "status cannot be 0 for an error result"); + assert_ne!(status, 0, "status cannot be 0 for an error result"); Self { result: ExpandResultCode::error, status, diff --git a/src/fds.rs b/src/fds.rs index 643b2d216..f6d58da76 100644 --- a/src/fds.rs +++ b/src/fds.rs @@ -340,7 +340,7 @@ fn test_pipes() { assert!(fd >= FIRST_HIGH_FD); let flags = unsafe { libc::fcntl(fd, F_GETFD, 0) }; assert!(flags >= 0); - assert!(flags & FD_CLOEXEC != 0); + assert_ne!(flags & FD_CLOEXEC, 0); } } } diff --git a/src/fork_exec/postfork.rs b/src/fork_exec/postfork.rs index cb37c5b75..c59e6e612 100644 --- a/src/fork_exec/postfork.rs +++ b/src/fork_exec/postfork.rs @@ -94,7 +94,7 @@ pub fn execute_setpgid(pid: libc::pid_t, pgroup: libc::pid_t, is_parent: bool) - return 0; } let err = errno::errno().0; - assert!(err != libc::EINTR); + assert_ne!(err, libc::EINTR); if err == libc::EACCES && is_parent { // We are the parent process and our child has called exec(). // This is an unavoidable benign race. diff --git a/src/history/file.rs b/src/history/file.rs index 2ffc004c2..9d54934cc 100644 --- a/src/history/file.rs +++ b/src/history/file.rs @@ -41,7 +41,7 @@ impl MmapRegion { /// /// `ptr` must be the result of a successful `mmap()` call with length `len`. unsafe fn new(ptr: *mut u8, len: usize) -> Self { - assert!(ptr.cast() != MAP_FAILED); + assert_ne!(ptr.cast(), MAP_FAILED); assert!(len > 0); Self { ptr, len } } diff --git a/src/history/history.rs b/src/history/history.rs index 8b30f8204..737549e11 100644 --- a/src/history/history.rs +++ b/src/history/history.rs @@ -819,7 +819,7 @@ fn resolve_pending(&mut self) { /// Enable / disable automatic saving. Main thread only! fn disable_automatic_saving(&mut self) { self.disable_automatic_save_counter += 1; - assert!(self.disable_automatic_save_counter != 0); // overflow! + assert_ne!(self.disable_automatic_save_counter, 0); // overflow! } fn enable_automatic_saving(&mut self) { @@ -1570,7 +1570,7 @@ pub fn original_term(&self) -> &wstr { } pub fn prepare_to_search_after_deletion(&mut self) { - assert!(self.current_index != 0); + assert_ne!(self.current_index, 0); self.current_index -= 1; self.current_item = None; } diff --git a/src/input_common.rs b/src/input_common.rs index 584f5716e..4d119d02a 100644 --- a/src/input_common.rs +++ b/src/input_common.rs @@ -720,18 +720,18 @@ pub fn function_set_status(&mut self, status: bool) { } } -#[derive(Clone, Default, Eq, PartialEq)] +#[derive(Clone, Debug, Default, Eq, PartialEq)] pub struct BackgroundColorQuery { pub result: Option, } -#[derive(Clone, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq)] pub enum CursorPositionQueryReason { NewPrompt, WindowHeightChange, } -#[derive(Clone, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq)] pub struct CursorPositionQuery { pub reason: CursorPositionQueryReason, pub result: Option, @@ -746,7 +746,7 @@ pub fn new(reason: CursorPositionQueryReason) -> Self { } } -#[derive(Clone, Default, Eq, PartialEq)] +#[derive(Clone, Debug, Default, Eq, PartialEq)] pub struct RecurrentQuery { pub background_color: Option, pub cursor_position: Option, diff --git a/src/pager.rs b/src/pager.rs index 4d56c3657..7469cc39b 100644 --- a/src/pager.rs +++ b/src/pager.rs @@ -1102,7 +1102,7 @@ fn divide_round_up(numer: usize, denom: usize) -> usize { if numer == 0 { return 0; } - assert!(denom != 0); + assert_ne!(denom, 0); let has_rem = (numer % denom) != 0; numer / denom + if has_rem { 1 } else { 0 } } diff --git a/src/reader/history_search.rs b/src/reader/history_search.rs index ee8f2907a..78f474d77 100644 --- a/src/reader/history_search.rs +++ b/src/reader/history_search.rs @@ -31,7 +31,7 @@ fn new(text: WString, offset: usize) -> Self { } } -#[derive(Clone, Copy, Eq, Default, PartialEq)] +#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] pub enum SearchMode { #[default] /// no search @@ -162,8 +162,9 @@ pub fn reset_to_mode( mode: SearchMode, token_offset: usize, ) { - assert!( - mode != SearchMode::Inactive, + assert_ne!( + mode, + SearchMode::Inactive, "mode cannot be inactive in this setter" ); self.skips = HashSet::from([text.clone()]); diff --git a/src/reader/reader.rs b/src/reader/reader.rs index 4be0157fe..a3dfc558f 100644 --- a/src/reader/reader.rs +++ b/src/reader/reader.rs @@ -1683,7 +1683,7 @@ fn combine_command_and_autosuggestion( impl<'a> Reader<'a> { fn query(&mut self, query_state: RecurrentQuery) { - assert!(query_state != RecurrentQuery::default()); + assert_ne!(query_state, RecurrentQuery::default()); if self .vars() .get_unless_empty(L!("FISH_TEST_NO_RECURRENT_QUERIES")) diff --git a/src/tokenizer.rs b/src/tokenizer.rs index 09139f036..b45c7f114 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -590,8 +590,9 @@ fn call_error( token_length: Option, error_len: usize, ) -> Tok { - assert!( - error_type != TokenizerError::None, + assert_ne!( + error_type, + TokenizerError::None, "TokenizerError::none passed to call_error" ); assert!(error_loc >= token_start, "Invalid error location"); @@ -1016,8 +1017,9 @@ fn try_from(buff: &wstr) -> Result { return Err(()); } consume(&mut cursor, '|'); - assert!( - buff.char_at(cursor) != '|', + assert_ne!( + buff.char_at(cursor), + '|', "|| passed as redirection, this should have been handled as 'or' by the caller" ); result.fd = STDOUT_FILENO; diff --git a/src/tty_handoff.rs b/src/tty_handoff.rs index 70ca15052..4639985c5 100644 --- a/src/tty_handoff.rs +++ b/src/tty_handoff.rs @@ -428,8 +428,9 @@ fn try_transfer(jg: &JobGroup) -> bool { // It should never be fish's pgroup. let fish_pgrp = crate::nix::getpgrp(); - assert!( - pgid.as_pid_t() != fish_pgrp, + assert_ne!( + pgid.as_pid_t(), + fish_pgrp, "Job should not have fish's pgroup" );