clippy: fix clippy::manual_assert lint

https://rust-lang.github.io/rust-clippy/master/index.html#manual_assert

Closes #12341
This commit is contained in:
xtqqczze
2026-01-17 03:13:21 +00:00
committed by Johannes Altmanninger
parent 5e3bc86268
commit ddb3046ccd
5 changed files with 33 additions and 34 deletions

View File

@@ -198,6 +198,7 @@ format_push_string = "warn"
implicit_clone = "warn" implicit_clone = "warn"
len_without_is_empty = "allow" # we're not a library crate len_without_is_empty = "allow" # we're not a library crate
let_and_return = "allow" let_and_return = "allow"
manual_assert = "warn"
manual_range_contains = "allow" manual_range_contains = "allow"
map_unwrap_or = "warn" map_unwrap_or = "warn"
mut_mut = "warn" mut_mut = "warn"

View File

@@ -75,12 +75,12 @@ macro_rules! as_os_strs {
.spawn() .spawn()
{ {
Err(e) if e.kind() == std::io::ErrorKind::NotFound => { Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
if env_var("FISH_BUILD_DOCS") == Some("1".to_string()) { assert_ne!(
panic!( env_var("FISH_BUILD_DOCS"),
"Could not find sphinx-build required to build man pages.\n\ Some("1".to_string()),
Install Sphinx or disable building the docs by setting $FISH_BUILD_DOCS=0." "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!( rsconf::warn!(
"Could not find sphinx-build required to build man pages. \ "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. \ 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)); rsconf::warn!("sphinx-build: {}", String::from_utf8_lossy(&out.stderr));
} }
assert_eq!(&String::from_utf8_lossy(&out.stdout), ""); assert_eq!(&String::from_utf8_lossy(&out.stdout), "");
if !out.status.success() { assert!(
panic!("sphinx-build failed to build the man pages."); out.status.success(),
} "sphinx-build failed to build the man pages."
)
} }
} }
} }

View File

@@ -47,11 +47,10 @@ enum State {
// unsynchronized writers to the same file. // unsynchronized writers to the same file.
fn write_po_entry_to_file(message: &TokenStream, dir: &OsString) { fn write_po_entry_to_file(message: &TokenStream, dir: &OsString) {
let message_string = unescape_multiline_rust_string(message.to_string()); let message_string = unescape_multiline_rust_string(message.to_string());
if message_string.contains('\n') { assert!(
panic!( !message_string.contains('\n'),
"Gettext strings may not contain unescaped newlines. Unescaped newline found in '{message_string}'" "Gettext strings may not contain unescaped newlines. Unescaped newline found in '{message_string}'"
) );
}
// Crude check for format strings. This might result in false positives. // Crude check for format strings. This might result in false positives.
let format_string_annotation = if message_string.contains('%') { let format_string_annotation = if message_string.contains('%') {
"#, c-format\n" "#, c-format\n"
@@ -90,11 +89,10 @@ pub fn gettext_extract(message: TokenStream) -> TokenStream {
let first_token = token_trees let first_token = token_trees
.next() .next()
.expect("gettext_extract got empty token stream. Expected one token."); .expect("gettext_extract got empty token stream. Expected one token.");
if token_trees.next().is_some() { assert!(
panic!( token_trees.next().is_none(),
"Invalid number of tokens passed to gettext_extract. Expected one token, but got more." "Invalid number of tokens passed to gettext_extract. Expected one token, but got more."
) );
}
let proc_macro2::TokenTree::Group(group) = first_token else { let proc_macro2::TokenTree::Group(group) = first_token else {
panic!("Expected group in gettext_extract, but got: {first_token:?}"); 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 let first_group_token = group_tokens
.next() .next()
.expect("gettext_extract expected one group token but got none."); .expect("gettext_extract expected one group token but got none.");
if group_tokens.next().is_some() { assert!(
panic!( group_tokens.next().is_none(),
"Invalid number of tokens in group passed to gettext_extract. Expected one token, but got more." "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 { if let proc_macro2::TokenTree::Literal(_) = first_group_token {
write_po_entry_to_file(&message, &dir_path); write_po_entry_to_file(&message, &dir_path);
} else { } else {

View File

@@ -115,12 +115,11 @@ fn embed_localizations(cache_dir: &Path) {
.output() .output()
.unwrap() .unwrap()
}; };
if !output.status.success() { assert!(
panic!( output.status.success(),
"msgfmt failed:\n{}", "msgfmt failed:\n{}",
String::from_utf8(output.stderr).unwrap() String::from_utf8(output.stderr).unwrap()
); );
}
let mo_data = let mo_data =
tmp_mo_file.map_or(output.stdout, |path| std::fs::read(path).unwrap()); tmp_mo_file.map_or(output.stdout, |path| std::fs::read(path).unwrap());

View File

@@ -508,11 +508,12 @@ struct Context {
false false
}) })
.unwrap(); .unwrap();
if timeout.timed_out() { assert!(
panic!(concat!( !timeout.timed_out(),
concat!(
"Timeout waiting for condition variable to be notified! ", "Timeout waiting for condition variable to be notified! ",
"Does the platform support signalling a condvar without the mutex held?" "Does the platform support signalling a condvar without the mutex held?"
)); )
} )
} }
} }