From ddb3046ccd9f193b5457cd45bb4306042ee64d95 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Sat, 17 Jan 2026 03:13:21 +0000 Subject: [PATCH] clippy: fix clippy::manual_assert lint https://rust-lang.github.io/rust-clippy/master/index.html#manual_assert Closes #12341 --- Cargo.toml | 1 + crates/build-man-pages/build.rs | 19 ++++++++++--------- crates/gettext-extraction/src/lib.rs | 27 ++++++++++++--------------- crates/gettext-maps/build.rs | 11 +++++------ src/threads/threads.rs | 9 +++++---- 5 files changed, 33 insertions(+), 34 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 96ac30af5..b33999052 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -198,6 +198,7 @@ format_push_string = "warn" implicit_clone = "warn" len_without_is_empty = "allow" # we're not a library crate let_and_return = "allow" +manual_assert = "warn" manual_range_contains = "allow" map_unwrap_or = "warn" mut_mut = "warn" diff --git a/crates/build-man-pages/build.rs b/crates/build-man-pages/build.rs index 89d587eb9..98db12053 100644 --- a/crates/build-man-pages/build.rs +++ b/crates/build-man-pages/build.rs @@ -75,12 +75,12 @@ macro_rules! as_os_strs { .spawn() { Err(e) if e.kind() == std::io::ErrorKind::NotFound => { - if env_var("FISH_BUILD_DOCS") == Some("1".to_string()) { - panic!( - "Could not find sphinx-build required to build man pages.\n\ - Install Sphinx or disable building the docs by setting $FISH_BUILD_DOCS=0." - ); - } + assert_ne!( + env_var("FISH_BUILD_DOCS"), + Some("1".to_string()), + "Could not find sphinx-build required to build man pages.\n\ + Install Sphinx or disable building the docs by setting $FISH_BUILD_DOCS=0." + ); rsconf::warn!( "Could not find sphinx-build required to build man pages. \ If you install Sphinx now, you need to trigger a rebuild to include man pages. \ @@ -107,9 +107,10 @@ macro_rules! as_os_strs { rsconf::warn!("sphinx-build: {}", String::from_utf8_lossy(&out.stderr)); } assert_eq!(&String::from_utf8_lossy(&out.stdout), ""); - if !out.status.success() { - panic!("sphinx-build failed to build the man pages."); - } + assert!( + out.status.success(), + "sphinx-build failed to build the man pages." + ) } } } diff --git a/crates/gettext-extraction/src/lib.rs b/crates/gettext-extraction/src/lib.rs index 386351a5d..e16f82962 100644 --- a/crates/gettext-extraction/src/lib.rs +++ b/crates/gettext-extraction/src/lib.rs @@ -47,11 +47,10 @@ enum State { // unsynchronized writers to the same file. fn write_po_entry_to_file(message: &TokenStream, dir: &OsString) { let message_string = unescape_multiline_rust_string(message.to_string()); - if message_string.contains('\n') { - panic!( - "Gettext strings may not contain unescaped newlines. Unescaped newline found in '{message_string}'" - ) - } + assert!( + !message_string.contains('\n'), + "Gettext strings may not contain unescaped newlines. Unescaped newline found in '{message_string}'" + ); // Crude check for format strings. This might result in false positives. let format_string_annotation = if message_string.contains('%') { "#, c-format\n" @@ -90,11 +89,10 @@ pub fn gettext_extract(message: TokenStream) -> TokenStream { let first_token = token_trees .next() .expect("gettext_extract got empty token stream. Expected one token."); - if token_trees.next().is_some() { - panic!( - "Invalid number of tokens passed to gettext_extract. Expected one token, but got more." - ) - } + assert!( + token_trees.next().is_none(), + "Invalid number of tokens passed to gettext_extract. Expected one token, but got more." + ); let proc_macro2::TokenTree::Group(group) = first_token else { panic!("Expected group in gettext_extract, but got: {first_token:?}"); }; @@ -102,11 +100,10 @@ pub fn gettext_extract(message: TokenStream) -> TokenStream { let first_group_token = group_tokens .next() .expect("gettext_extract expected one group token but got none."); - if group_tokens.next().is_some() { - panic!( - "Invalid number of tokens in group passed to gettext_extract. Expected one token, but got more." - ) - } + assert!( + group_tokens.next().is_none(), + "Invalid number of tokens in group passed to gettext_extract. Expected one token, but got more." + ); if let proc_macro2::TokenTree::Literal(_) = first_group_token { write_po_entry_to_file(&message, &dir_path); } else { diff --git a/crates/gettext-maps/build.rs b/crates/gettext-maps/build.rs index a6a61bfd3..c437b73db 100644 --- a/crates/gettext-maps/build.rs +++ b/crates/gettext-maps/build.rs @@ -115,12 +115,11 @@ fn embed_localizations(cache_dir: &Path) { .output() .unwrap() }; - if !output.status.success() { - panic!( - "msgfmt failed:\n{}", - String::from_utf8(output.stderr).unwrap() - ); - } + assert!( + output.status.success(), + "msgfmt failed:\n{}", + String::from_utf8(output.stderr).unwrap() + ); let mo_data = tmp_mo_file.map_or(output.stdout, |path| std::fs::read(path).unwrap()); diff --git a/src/threads/threads.rs b/src/threads/threads.rs index eb6f0c6fa..eca17bcf7 100644 --- a/src/threads/threads.rs +++ b/src/threads/threads.rs @@ -508,11 +508,12 @@ struct Context { false }) .unwrap(); - if timeout.timed_out() { - panic!(concat!( + assert!( + !timeout.timed_out(), + concat!( "Timeout waiting for condition variable to be notified! ", "Does the platform support signalling a condvar without the mutex held?" - )); - } + ) + ) } }