From 43f8d7478e386c0bff6ee7e3b4c21b3839284df6 Mon Sep 17 00:00:00 2001 From: Daniel Rainer Date: Thu, 16 Oct 2025 17:33:06 +0200 Subject: [PATCH] style: change rustfmt edition to 2024 This commit adds `style_edition = "2024"` as a rustfmt config setting. All other changes are automatically generated by `cargo fmt`. The 2024 style edition fixes several bugs and changes some defaults. https://doc.rust-lang.org/edition-guide/rust-2024/rustfmt-style-edition.html Most of the changes made to our code result from a different sorting method for `use` statements, improved ability to split long lines, and contraction of short trailing expressions into single-line expressions. While our MSRV is still 1.70, we use more recent toolchains for development, so we can already benefit from the improvements of the new style edition. Formatting is not require for building fish, so builds with Rust 1.70 are not affected by this change. More context can be found at https://github.com/fish-shell/fish-shell/issues/11630#issuecomment-3406937077 Closes #11959 --- .rustfmt.toml | 1 + build.rs | 4 +- crates/build-man-pages/build.rs | 8 +- crates/gettext-extraction/src/lib.rs | 12 ++- crates/printf/src/fmt_fp/mod.rs | 4 +- crates/printf/src/lib.rs | 4 +- crates/printf/src/locale.rs | 6 +- crates/printf/src/tests.rs | 4 +- src/ast.rs | 15 ++-- src/autoload.rs | 32 ++++---- src/bin/fish.rs | 20 ++--- src/builtins/abbr.rs | 2 +- src/builtins/bind.rs | 6 +- src/builtins/cd.rs | 4 +- src/builtins/commandline.rs | 6 +- src/builtins/complete.rs | 8 +- src/builtins/disown.rs | 2 +- src/builtins/fish_indent.rs | 12 +-- src/builtins/fish_key_reader.rs | 12 +-- src/builtins/history.rs | 2 +- src/builtins/jobs.rs | 8 +- src/builtins/mod.rs | 3 +- src/builtins/path.rs | 6 +- src/builtins/printf.rs | 6 +- src/builtins/read.rs | 10 +-- src/builtins/return.rs | 2 +- src/builtins/set.rs | 6 +- src/builtins/set_color.rs | 4 +- src/builtins/shared.rs | 10 +-- src/builtins/source.rs | 2 +- src/builtins/status.rs | 8 +- src/builtins/string/escape.rs | 2 +- src/builtins/string/match.rs | 2 +- src/builtins/string/replace.rs | 2 +- src/builtins/string/unescape.rs | 2 +- src/builtins/test.rs | 6 +- src/builtins/tests/string_tests.rs | 2 +- src/builtins/ulimit.rs | 2 +- src/builtins/wait.rs | 2 +- src/common.rs | 6 +- src/complete.rs | 20 ++--- src/env/config_paths.rs | 4 +- src/env/environment.rs | 20 ++--- src/env/environment_impl.rs | 10 +-- src/env/mod.rs | 2 +- src/env/var.rs | 2 +- src/env_dispatch.rs | 6 +- src/env_universal_common.rs | 10 +-- src/event.rs | 4 +- src/exec.rs | 36 +++++---- src/expand.rs | 26 +++---- src/fd_monitor.rs | 2 +- src/fds.rs | 2 +- src/flog.rs | 2 +- src/fork_exec/postfork.rs | 2 +- src/fork_exec/spawn.rs | 4 +- src/fs.rs | 20 +++-- src/function.rs | 2 +- src/future.rs | 2 +- src/global_safety.rs | 2 +- src/highlight/file_tester.rs | 10 +-- src/highlight/highlight.rs | 18 ++--- src/highlight/tests.rs | 8 +- src/history.rs | 21 +++--- src/history/file.rs | 6 +- src/input.rs | 12 +-- src/input_common.rs | 14 ++-- src/io.rs | 6 +- src/key.rs | 6 +- src/locale.rs | 2 +- src/null_terminated_array.rs | 2 +- src/pager.rs | 10 +-- src/panic.rs | 4 +- src/parse_execution.rs | 42 +++++------ src/parse_tree.rs | 4 +- src/parse_util.rs | 33 ++++----- src/parser.rs | 22 +++--- src/path.rs | 6 +- src/proc.rs | 18 ++--- src/reader.rs | 106 ++++++++++++++------------- src/reader_history_search.rs | 2 +- src/screen.rs | 10 +-- src/signal.rs | 2 +- src/terminal.rs | 6 +- src/termsize.rs | 2 +- src/tests/abbrs.rs | 4 +- src/tests/ast.rs | 2 +- src/tests/common.rs | 2 +- src/tests/complete.rs | 26 ++++--- src/tests/debounce.rs | 6 +- src/tests/env_universal_common.rs | 4 +- src/tests/expand.rs | 8 +- src/tests/fd_monitor.rs | 10 +-- src/tests/history.rs | 4 +- src/tests/input.rs | 2 +- src/tests/key.rs | 2 +- src/tests/mod.rs | 2 +- src/tests/parse_util.rs | 12 +-- src/tests/parser.rs | 4 +- src/tests/reader.rs | 2 +- src/tests/screen.rs | 2 +- src/tests/string_escape.rs | 18 +++-- src/tests/termsize.rs | 2 +- src/tests/topic_monitor.rs | 2 +- src/tests/wgetopt.rs | 2 +- src/text_face.rs | 2 +- src/threads.rs | 2 +- src/timer.rs | 2 +- src/tinyexpr.rs | 14 +--- src/tokenizer.rs | 2 +- src/topic_monitor.rs | 4 +- src/universal_notifier/kqueue.rs | 2 +- src/util.rs | 2 +- src/wchar.rs | 6 +- src/wchar_ext.rs | 4 +- src/wcstringutil.rs | 8 +- src/wildcard.rs | 10 +-- src/wutil/dir_iter.rs | 6 +- src/wutil/hex_float.rs | 2 +- src/wutil/mod.rs | 12 +-- src/wutil/tests.rs | 2 +- src/wutil/wcstod.rs | 7 +- 122 files changed, 508 insertions(+), 500 deletions(-) create mode 100644 .rustfmt.toml diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 000000000..350113681 --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1 @@ +style_edition = "2024" diff --git a/build.rs b/build.rs index 4ad493d04..394cb74e3 100644 --- a/build.rs +++ b/build.rs @@ -57,7 +57,9 @@ fn main() { detect_cfgs(&mut target); #[cfg(all(target_env = "gnu", target_feature = "crt-static"))] - compile_error!("Statically linking against glibc has unavoidable crashes and is unsupported. Use dynamic linking or link statically against musl."); + compile_error!( + "Statically linking against glibc has unavoidable crashes and is unsupported. Use dynamic linking or link statically against musl." + ); } /// Check target system support for certain functionality dynamically when the build is invoked, diff --git a/crates/build-man-pages/build.rs b/crates/build-man-pages/build.rs index 1cb097d04..5b0a3d0db 100644 --- a/crates/build-man-pages/build.rs +++ b/crates/build-man-pages/build.rs @@ -62,10 +62,14 @@ fn build_man(man_dir: &Path) { { 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 to build man pages.\nInstall sphinx or disable building the docs by setting $FISH_BUILD_DOCS=0."); + panic!( + "Could not find sphinx-build to build man pages.\nInstall sphinx or disable building the docs by setting $FISH_BUILD_DOCS=0." + ); } rsconf::warn!("Cannot find sphinx-build to build man pages."); - rsconf::warn!("If you install it now you need to run `cargo clean` and rebuild, or set $FISH_BUILD_DOCS=1 explicitly."); + rsconf::warn!( + "If you install it now you need to run `cargo clean` and rebuild, or set $FISH_BUILD_DOCS=1 explicitly." + ); return; } Err(e) => { diff --git a/crates/gettext-extraction/src/lib.rs b/crates/gettext-extraction/src/lib.rs index 2ecc9f954..9004d1d91 100644 --- a/crates/gettext-extraction/src/lib.rs +++ b/crates/gettext-extraction/src/lib.rs @@ -50,7 +50,9 @@ fn append_po_entry_to_file(message: &TokenStream, file_name: &OsString) { .unwrap_or_else(|e| panic!("Could not open file {file_name:?}: {e}")); 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}'") + panic!( + "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('%') { @@ -84,7 +86,9 @@ pub fn gettext_extract(message: TokenStream) -> TokenStream { .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.") + panic!( + "Invalid number of tokens passed to gettext_extract. Expected one token, but got more." + ) } if let proc_macro2::TokenTree::Group(group) = first_token { let mut group_tokens = group.stream().into_iter(); @@ -92,7 +96,9 @@ pub fn gettext_extract(message: TokenStream) -> TokenStream { .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.") + panic!( + "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 { append_po_entry_to_file(&message, &file_path); diff --git a/crates/printf/src/fmt_fp/mod.rs b/crates/printf/src/fmt_fp/mod.rs index 03de1b880..85ce171d8 100644 --- a/crates/printf/src/fmt_fp/mod.rs +++ b/crates/printf/src/fmt_fp/mod.rs @@ -3,8 +3,8 @@ mod tests; use super::locale::Locale; -use super::printf_impl::{pad, ConversionSpec, Error, ModifierFlags}; -use decimal::{Decimal, DigitLimit, DIGIT_WIDTH}; +use super::printf_impl::{ConversionSpec, Error, ModifierFlags, pad}; +use decimal::{DIGIT_WIDTH, Decimal, DigitLimit}; use std::cmp::min; use std::fmt::Write; diff --git a/crates/printf/src/lib.rs b/crates/printf/src/lib.rs index b7d4ac5cb..b43f3c5f5 100644 --- a/crates/printf/src/lib.rs +++ b/crates/printf/src/lib.rs @@ -4,9 +4,9 @@ mod fmt_fp; mod printf_impl; -pub use printf_impl::{sprintf_locale, Error, FormatString}; +pub use printf_impl::{Error, FormatString, sprintf_locale}; pub mod locale; -pub use locale::{Locale, C_LOCALE, EN_US_LOCALE}; +pub use locale::{C_LOCALE, EN_US_LOCALE, Locale}; #[cfg(test)] mod tests; diff --git a/crates/printf/src/locale.rs b/crates/printf/src/locale.rs index cf8005332..bdb13effb 100644 --- a/crates/printf/src/locale.rs +++ b/crates/printf/src/locale.rs @@ -66,11 +66,7 @@ fn next_group_size(&self, digits_left: usize) -> usize { // Divide remaining digits by repeat_group. // Apply any remainder to the first group. let res = (digits_left - accum) % (repeat_group as usize); - if res > 0 { - res - } else { - repeat_group as usize - } + if res > 0 { res } else { repeat_group as usize } } } diff --git a/crates/printf/src/tests.rs b/crates/printf/src/tests.rs index 906dea1a4..186968d70 100644 --- a/crates/printf/src/tests.rs +++ b/crates/printf/src/tests.rs @@ -1,6 +1,6 @@ use crate::arg::ToArg; -use crate::locale::{Locale, C_LOCALE, EN_US_LOCALE}; -use crate::{sprintf_locale, Error, FormatString}; +use crate::locale::{C_LOCALE, EN_US_LOCALE, Locale}; +use crate::{Error, FormatString, sprintf_locale}; use libc::c_char; use std::f64::consts::{E, PI, TAU}; use std::fmt; diff --git a/src/ast.rs b/src/ast.rs index 3a2c0dac0..87a96b3b1 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -9,19 +9,19 @@ * * Most clients will be interested in visiting the nodes of an ast. */ -use crate::common::{unescape_string, UnescapeStringStyle}; +use crate::common::{UnescapeStringStyle, unescape_string}; use crate::flog::{FLOG, FLOGF}; use crate::parse_constants::{ - token_type_user_presentable_description, ParseError, ParseErrorCode, ParseErrorList, - ParseKeyword, ParseTokenType, ParseTreeFlags, SourceRange, StatementDecoration, - ERROR_BAD_COMMAND_ASSIGN_ERR_MSG, INVALID_PIPELINE_CMD_ERR_MSG, SOURCE_OFFSET_INVALID, + ERROR_BAD_COMMAND_ASSIGN_ERR_MSG, INVALID_PIPELINE_CMD_ERR_MSG, ParseError, ParseErrorCode, + ParseErrorList, ParseKeyword, ParseTokenType, ParseTreeFlags, SOURCE_OFFSET_INVALID, + SourceRange, StatementDecoration, token_type_user_presentable_description, }; use crate::parse_tree::ParseToken; #[cfg(test)] use crate::tests::prelude::*; use crate::tokenizer::{ - variable_assignment_equals_pos, TokFlags, TokenType, Tokenizer, TokenizerError, TOK_ACCEPT_UNFINISHED, TOK_ARGUMENT_LIST, TOK_CONTINUE_AFTER_ERROR, TOK_SHOW_COMMENTS, + TokFlags, TokenType, Tokenizer, TokenizerError, variable_assignment_equals_pos, }; use crate::wchar::prelude::*; use macro_rules_attribute::derive; @@ -1297,7 +1297,10 @@ pub fn parent(&self, node: &dyn Node) -> &'a dyn Node { return iter.next().expect("Node is root and has no parent"); } } - panic!("Node {:?} has either been popped off of the stack or not yet visited. Cannot find parent.", node.describe()); + panic!( + "Node {:?} has either been popped off of the stack or not yet visited. Cannot find parent.", + node.describe() + ); } // Skip the children of the last visited node, which must be passed diff --git a/src/autoload.rs b/src/autoload.rs index 9ac2090cd..546834fe1 100644 --- a/src/autoload.rs +++ b/src/autoload.rs @@ -1,17 +1,17 @@ //! The classes responsible for autoloading functions and completions. +use crate::FLOGF; #[cfg(feature = "embed-data")] use crate::common::wcs2string; -use crate::common::{escape, ScopeGuard}; +use crate::common::{ScopeGuard, escape}; use crate::env::Environment; use crate::io::IoChain; use crate::parser::Parser; #[cfg(test)] use crate::tests::prelude::*; -use crate::wchar::{wstr, WString, L}; +use crate::wchar::{L, WString, wstr}; use crate::wchar_ext::WExt; -use crate::wutil::{file_id_for_path, FileId, INVALID_FILE_ID}; -use crate::FLOGF; +use crate::wutil::{FileId, INVALID_FILE_ID, file_id_for_path}; use lru::LruCache; #[cfg(feature = "embed-data")] use rust_embed::RustEmbed; @@ -521,9 +521,11 @@ fn touch_file(path: &wstr) { let paths = &[p1.clone(), p2.clone()]; let mut autoload = Autoload::new(L!("test_var")); assert!(autoload.resolve_command_impl(L!("file1"), paths).is_none()); - assert!(autoload - .resolve_command_impl(L!("nothing"), paths) - .is_none()); + assert!( + autoload + .resolve_command_impl(L!("nothing"), paths) + .is_none() + ); assert!(autoload.get_autoloaded_commands().is_empty()); run!("touch %s/file1.fish", p1); @@ -549,9 +551,11 @@ fn touch_file(path: &wstr) { autoload.resolve_command_impl(L!("file1"), paths), AutoloadResult::Loaded )); - assert!(autoload - .resolve_command_impl(L!("nothing"), paths) - .is_none()); + assert!( + autoload + .resolve_command_impl(L!("nothing"), paths) + .is_none() + ); assert!(autoload.resolve_command_impl(L!("file2"), paths).is_some()); assert!(matches!( autoload.resolve_command_impl(L!("file2"), paths), @@ -571,9 +575,11 @@ fn touch_file(path: &wstr) { autoload.resolve_command_impl(L!("file1"), paths), AutoloadResult::Loaded )); - assert!(autoload - .resolve_command_impl(L!("nothing"), paths) - .is_none()); + assert!( + autoload + .resolve_command_impl(L!("nothing"), paths) + .is_none() + ); assert!(autoload.resolve_command_impl(L!("file2"), paths).is_some()); assert!(matches!( autoload.resolve_command_impl(L!("file2"), paths), diff --git a/src/bin/fish.rs b/src/bin/fish.rs index 486514ec3..549f7d843 100644 --- a/src/bin/fish.rs +++ b/src/bin/fish.rs @@ -31,21 +31,21 @@ }, }, common::{ - escape, save_term_foreground_process_group, str2wcstring, wcs2string, PACKAGE_NAME, - PROFILING_ACTIVE, PROGRAM_NAME, + PACKAGE_NAME, PROFILING_ACTIVE, PROGRAM_NAME, escape, save_term_foreground_process_group, + str2wcstring, wcs2string, }, env::{ - config_paths::ConfigPaths, - environment::{env_init, EnvStack, Environment}, EnvMode, Statuses, + config_paths::ConfigPaths, + environment::{EnvStack, Environment, env_init}, }, eprintf, event::{self, Event}, - flog::{self, activate_flog_categories_by_pattern, set_flog_file_fd, FLOG, FLOGF}, + flog::{self, FLOG, FLOGF, activate_flog_categories_by_pattern, set_flog_file_fd}, fprintf, function, future_feature_flags as features, history::{self, start_private_mode}, io::IoChain, - nix::{getpid, getrusage, isatty, RUsage}, + nix::{RUsage, getpid, getrusage, isatty}, panic::panic_handler, parse_constants::{ParseErrorList, ParseTreeFlags}, parse_tree::ParsedSource, @@ -54,8 +54,8 @@ path::path_get_config, printf, proc::{ - get_login, is_interactive_session, mark_login, mark_no_exec, proc_init, - set_interactive_session, Pid, + Pid, get_login, is_interactive_session, mark_login, mark_no_exec, proc_init, + set_interactive_session, }, reader::{reader_init, reader_read, term_copy_modes}, signal::{signal_clear_cancel, signal_unblock_all}, @@ -71,8 +71,8 @@ use std::fs::File; use std::os::unix::prelude::*; use std::path::Path; -use std::sync::atomic::Ordering; use std::sync::Arc; +use std::sync::atomic::Ordering; use std::{env, ops::ControlFlow}; #[cfg(feature = "embed-data")] @@ -242,7 +242,7 @@ fn run_command_list(parser: &Parser, cmds: &[OsString]) -> Result<(), libc::c_in } fn fish_parse_opt(args: &mut [WString], opts: &mut FishCmdOpts) -> ControlFlow { - use fish::wgetopt::{wopt, ArgType::*, WGetopter, WOption}; + use fish::wgetopt::{ArgType::*, WGetopter, WOption, wopt}; const RUSAGE_ARG: char = 1 as char; const PRINT_DEBUG_CATEGORIES_ARG: char = 2 as char; diff --git a/src/builtins/abbr.rs b/src/builtins/abbr.rs index 34704c9bc..13be94309 100644 --- a/src/builtins/abbr.rs +++ b/src/builtins/abbr.rs @@ -1,6 +1,6 @@ use super::prelude::*; use crate::abbrs::{self, Abbreviation, Position}; -use crate::common::{escape, escape_string, valid_func_name, EscapeStringStyle}; +use crate::common::{EscapeStringStyle, escape, escape_string, valid_func_name}; use crate::env::{EnvMode, EnvStackSetResult}; use crate::re::{regex_make_anchored, to_boxed_chars}; use pcre2::utf32::{Regex, RegexBuilder}; diff --git a/src/builtins/bind.rs b/src/builtins/bind.rs index f91519b97..e854c9b09 100644 --- a/src/builtins/bind.rs +++ b/src/builtins/bind.rs @@ -2,12 +2,12 @@ use super::prelude::*; use crate::common::{ - escape, escape_string, str2wcstring, valid_var_name, EscapeFlags, EscapeStringStyle, + EscapeFlags, EscapeStringStyle, escape, escape_string, str2wcstring, valid_var_name, }; use crate::highlight::{colorize, highlight_shell}; -use crate::input::{input_function_get_names, input_mappings, InputMappingSet, KeyNameStyle}; +use crate::input::{InputMappingSet, KeyNameStyle, input_function_get_names, input_mappings}; use crate::key::{ - self, char_to_symbol, function_key, parse_keys, Key, Modifiers, KEY_NAMES, MAX_FUNCTION_KEY, + self, KEY_NAMES, Key, MAX_FUNCTION_KEY, Modifiers, char_to_symbol, function_key, parse_keys, }; use crate::nix::isatty; use std::sync::MutexGuard; diff --git a/src/builtins/cd.rs b/src/builtins/cd.rs index eb538a291..e5721d0da 100644 --- a/src/builtins/cd.rs +++ b/src/builtins/cd.rs @@ -3,12 +3,12 @@ use super::prelude::*; use crate::{ env::{EnvMode, Environment}, - fds::{wopen_dir, BEST_O_SEARCH}, + fds::{BEST_O_SEARCH, wopen_dir}, path::path_apply_cdpath, wutil::{normalize_path, wperror, wreadlink}, }; use errno::Errno; -use libc::{fchdir, EACCES, ELOOP, ENOENT, ENOTDIR, EPERM}; +use libc::{EACCES, ELOOP, ENOENT, ENOTDIR, EPERM, fchdir}; use std::{os::fd::AsRawFd, sync::Arc}; // The cd builtin. Changes the current directory to the one specified or to $HOME if none is diff --git a/src/builtins/commandline.rs b/src/builtins/commandline.rs index fc57e5299..f1fd877dd 100644 --- a/src/builtins/commandline.rs +++ b/src/builtins/commandline.rs @@ -1,12 +1,12 @@ use super::prelude::*; use super::read::TokenOutputMode; use crate::ast::{self, Kind, Leaf}; -use crate::common::{unescape_string, UnescapeFlags, UnescapeStringStyle}; +use crate::common::{UnescapeFlags, UnescapeStringStyle, unescape_string}; use crate::complete::Completion; -use crate::expand::{expand_string, ExpandFlags, ExpandResultCode}; +use crate::expand::{ExpandFlags, ExpandResultCode, expand_string}; use crate::input::input_function_get_code; use crate::input_common::{CharEvent, ReadlineCmd}; -use crate::operation_context::{no_cancel, OperationContext}; +use crate::operation_context::{OperationContext, no_cancel}; use crate::parse_constants::{ParseTreeFlags, ParserTestErrorBits}; use crate::parse_util::{ parse_util_detect_errors, parse_util_get_offset_from_line, parse_util_job_extent, diff --git a/src/builtins/complete.rs b/src/builtins/complete.rs index ff5a5da4f..b311cf619 100644 --- a/src/builtins/complete.rs +++ b/src/builtins/complete.rs @@ -1,6 +1,6 @@ use super::prelude::*; -use crate::common::{unescape_string, ScopeGuard, UnescapeFlags, UnescapeStringStyle}; -use crate::complete::{complete_add_wrapper, complete_remove_wrapper, CompletionRequestOptions}; +use crate::common::{ScopeGuard, UnescapeFlags, UnescapeStringStyle, unescape_string}; +use crate::complete::{CompletionRequestOptions, complete_add_wrapper, complete_remove_wrapper}; use crate::highlight::colorize; use crate::highlight::highlight_shell; use crate::nix::isatty; @@ -14,8 +14,8 @@ use crate::{ common::str2wcstring, complete::{ - complete_add, complete_print, complete_remove, complete_remove_all, CompleteFlags, - CompleteOptionType, CompletionMode, + CompleteFlags, CompleteOptionType, CompletionMode, complete_add, complete_print, + complete_remove, complete_remove_all, }, }; use libc::STDOUT_FILENO; diff --git a/src/builtins/disown.rs b/src/builtins/disown.rs index e3a835788..996b3f90d 100644 --- a/src/builtins/disown.rs +++ b/src/builtins/disown.rs @@ -3,7 +3,7 @@ use super::prelude::*; use crate::io::IoStreams; use crate::parser::Parser; -use crate::proc::{add_disowned_job, Job}; +use crate::proc::{Job, add_disowned_job}; use crate::{builtins::shared::HelpOnlyCmdOpts, wchar::wstr, wutil::wgettext_fmt}; use libc::SIGCONT; diff --git a/src/builtins/fish_indent.rs b/src/builtins/fish_indent.rs index 24dde513d..3686052a4 100644 --- a/src/builtins/fish_indent.rs +++ b/src/builtins/fish_indent.rs @@ -17,27 +17,27 @@ use super::prelude::*; use crate::ast::{self, Ast, Kind, Leaf, Node, NodeVisitor, SourceRangeList, Traversal}; use crate::common::{ - str2wcstring, unescape_string, wcs2string, UnescapeFlags, UnescapeStringStyle, PROGRAM_NAME, + PROGRAM_NAME, UnescapeFlags, UnescapeStringStyle, str2wcstring, unescape_string, wcs2string, }; +use crate::env::EnvStack; use crate::env::env_init; use crate::env::environment::Environment; -use crate::env::EnvStack; use crate::expand::INTERNAL_SEPARATOR; #[allow(unused_imports)] use crate::future::{IsSomeAnd, IsSorted}; use crate::future_feature_flags; use crate::global_safety::RelaxedAtomicBool; -use crate::highlight::{colorize, highlight_shell, HighlightRole, HighlightSpec}; +use crate::highlight::{HighlightRole, HighlightSpec, colorize, highlight_shell}; use crate::operation_context::OperationContext; use crate::parse_constants::{ParseTokenType, ParseTreeFlags, SourceRange}; -use crate::parse_util::{apply_indents, parse_util_compute_indents, SPACES_PER_INDENT}; +use crate::parse_util::{SPACES_PER_INDENT, apply_indents, parse_util_compute_indents}; use crate::print_help::print_help; use crate::threads; -use crate::tokenizer::{TokenType, Tokenizer, TOK_SHOW_BLANK_LINES, TOK_SHOW_COMMENTS}; +use crate::tokenizer::{TOK_SHOW_BLANK_LINES, TOK_SHOW_COMMENTS, TokenType, Tokenizer}; use crate::topic_monitor::topic_monitor_init; use crate::wchar::prelude::*; use crate::wcstringutil::count_preceding_backslashes; -use crate::wgetopt::{wopt, ArgType, WGetopter, WOption}; +use crate::wgetopt::{ArgType, WGetopter, WOption, wopt}; use crate::wutil::fish_iswalnum; /// Note: this got somewhat more complicated after introducing the new AST, because that AST no diff --git a/src/builtins/fish_key_reader.rs b/src/builtins/fish_key_reader.rs index 46055264f..f95f7702e 100644 --- a/src/builtins/fish_key_reader.rs +++ b/src/builtins/fish_key_reader.rs @@ -15,14 +15,14 @@ use crate::future::IsSomeAnd; use crate::{ builtins::shared::BUILTIN_ERR_UNKNOWN, - common::{shell_modes, str2wcstring, PROGRAM_NAME}, - env::{env_init, EnvStack, Environment}, + common::{PROGRAM_NAME, shell_modes, str2wcstring}, + env::{EnvStack, Environment, env_init}, future_feature_flags, input_common::{ - match_key_event_to_key, CharEvent, ImplicitEvent, InputEventQueue, InputEventQueuer, - KeyEvent, QueryResultEvent, + CharEvent, ImplicitEvent, InputEventQueue, InputEventQueuer, KeyEvent, QueryResultEvent, + match_key_event_to_key, }, - key::{char_to_symbol, Key}, + key::{Key, char_to_symbol}, nix::isatty, panic::panic_handler, print_help::print_help, @@ -34,7 +34,7 @@ topic_monitor::topic_monitor_init, tty_handoff::TtyHandoff, wchar::prelude::*, - wgetopt::{wopt, ArgType, WGetopter, WOption}, + wgetopt::{ArgType, WGetopter, WOption, wopt}, }; use super::prelude::*; diff --git a/src/builtins/history.rs b/src/builtins/history.rs index 4263984fc..66e9a4b56 100644 --- a/src/builtins/history.rs +++ b/src/builtins/history.rs @@ -1,7 +1,7 @@ //! Implementation of the history builtin. use crate::history::in_private_mode; -use crate::history::{self, history_session_id, History}; +use crate::history::{self, History, history_session_id}; use crate::reader::commandline_get_state; use super::prelude::*; diff --git a/src/builtins/jobs.rs b/src/builtins/jobs.rs index a1a380f5b..b09376b2d 100644 --- a/src/builtins/jobs.rs +++ b/src/builtins/jobs.rs @@ -1,16 +1,16 @@ // Functions for executing the jobs builtin. use super::prelude::*; -use crate::common::{escape_string, timef, EscapeFlags, EscapeStringStyle}; +use crate::common::{EscapeFlags, EscapeStringStyle, escape_string, timef}; use crate::io::IoStreams; use crate::job_group::{JobId, MaybeJobId}; use crate::parser::Parser; -use crate::proc::{clock_ticks_to_seconds, have_proc_stat, proc_get_jiffies, Job}; +use crate::proc::{Job, clock_ticks_to_seconds, have_proc_stat, proc_get_jiffies}; use crate::wchar_ext::WExt; -use crate::wgetopt::{wopt, ArgType, WGetopter, WOption}; +use crate::wgetopt::{ArgType, WGetopter, WOption, wopt}; use crate::wutil::wgettext; use crate::{ - wchar::{wstr, WString, L}, + wchar::{L, WString, wstr}, wutil::{fish_wcstoi, wgettext_fmt}, }; use std::num::NonZeroU32; diff --git a/src/builtins/mod.rs b/src/builtins/mod.rs index d95d758f7..ab2e2d29d 100644 --- a/src/builtins/mod.rs +++ b/src/builtins/mod.rs @@ -63,9 +63,8 @@ mod prelude { parser::Parser, wchar::prelude::*, wgetopt::{ - wopt, ArgType::{self, *}, - WGetopter, WOption, NON_OPTION_CHAR, + NON_OPTION_CHAR, WGetopter, WOption, wopt, }, wutil::{fish_wcstoi, fish_wcstol, fish_wcstoul}, }; diff --git a/src/builtins/path.rs b/src/builtins/path.rs index ec182d687..77109b2f8 100644 --- a/src/builtins/path.rs +++ b/src/builtins/path.rs @@ -9,11 +9,11 @@ use crate::util::wcsfilecmp_glob; use crate::wcstringutil::split_string_tok; use crate::wutil::{ - file_id_for_path, lwstat, normalize_path, waccess, wbasename, wdirname, wrealpath, wstat, - INVALID_FILE_ID, + INVALID_FILE_ID, file_id_for_path, lwstat, normalize_path, waccess, wbasename, wdirname, + wrealpath, wstat, }; use bitflags::bitflags; -use libc::{mode_t, F_OK, PATH_MAX, R_OK, S_ISGID, S_ISUID, W_OK, X_OK}; +use libc::{F_OK, PATH_MAX, R_OK, S_ISGID, S_ISUID, W_OK, X_OK, mode_t}; macro_rules! path_error { ( diff --git a/src/builtins/printf.rs b/src/builtins/printf.rs index e69b968e8..9efb6a95d 100644 --- a/src/builtins/printf.rs +++ b/src/builtins/printf.rs @@ -49,15 +49,15 @@ // This file has been imported from source code of printf command in GNU Coreutils version 6.9. use super::prelude::*; -use crate::locale::{get_numeric_locale, Locale}; +use crate::locale::{Locale, get_numeric_locale}; use crate::wchar::encode_byte_to_char; use crate::wutil::{ errors::Error, wcstod::wcstod, - wcstoi::{wcstoi_partial, Options as WcstoiOpts}, + wcstoi::{Options as WcstoiOpts, wcstoi_partial}, wstr_offset_in, }; -use fish_printf::{sprintf_locale, ToArg}; +use fish_printf::{ToArg, sprintf_locale}; /// Return true if `c` is an octal digit. fn is_octal_digit(c: char) -> bool { diff --git a/src/builtins/read.rs b/src/builtins/read.rs index f8f67b888..f234623bd 100644 --- a/src/builtins/read.rs +++ b/src/builtins/read.rs @@ -1,28 +1,28 @@ //! Implementation of the read builtin. use super::prelude::*; +use crate::common::UnescapeStringStyle; use crate::common::escape; use crate::common::read_blocked; use crate::common::str2wcstring; use crate::common::unescape_string; use crate::common::valid_var_name; -use crate::common::UnescapeStringStyle; use crate::env::EnvMode; use crate::env::Environment; use crate::env::READ_BYTE_LIMIT; use crate::env::{EnvVar, EnvVarFlags}; -use crate::input_common::decode_input_byte; use crate::input_common::DecodeState; use crate::input_common::InvalidPolicy; +use crate::input_common::decode_input_byte; use crate::nix::isatty; +use crate::reader::ReaderConfig; use crate::reader::commandline_set_buffer; use crate::reader::reader_save_screen_state; -use crate::reader::ReaderConfig; use crate::reader::{reader_pop, reader_push, reader_readline}; -use crate::tokenizer::Tok; -use crate::tokenizer::Tokenizer; use crate::tokenizer::TOK_ACCEPT_UNFINISHED; use crate::tokenizer::TOK_ARGUMENT_LIST; +use crate::tokenizer::Tok; +use crate::tokenizer::Tokenizer; use crate::tty_handoff::TtyHandoff; use crate::wcstringutil::split_about; use crate::wcstringutil::split_string_tok; diff --git a/src/builtins/return.rs b/src/builtins/return.rs index 45908c3fc..c849da9b1 100644 --- a/src/builtins/return.rs +++ b/src/builtins/return.rs @@ -94,7 +94,7 @@ pub fn parse_return_value( let (opts, optind) = match parse_options(args, parser, streams) { ControlFlow::Continue(o) => o, ControlFlow::Break(error_code) => { - return ControlFlow::Break(BuiltinResult::Err(error_code)) + return ControlFlow::Break(BuiltinResult::Err(error_code)); } }; diff --git a/src/builtins/set.rs b/src/builtins/set.rs index c78a923d2..38209c853 100644 --- a/src/builtins/set.rs +++ b/src/builtins/set.rs @@ -1,11 +1,11 @@ use super::prelude::*; +use crate::common::EscapeFlags; +use crate::common::EscapeStringStyle; use crate::common::escape; use crate::common::escape_string; use crate::common::get_ellipsis_char; use crate::common::get_ellipsis_str; use crate::common::valid_var_name; -use crate::common::EscapeFlags; -use crate::common::EscapeStringStyle; use crate::env::EnvStackSetResult; use crate::env::EnvVarFlags; use crate::env::INHERITED_VARS; @@ -13,8 +13,8 @@ use crate::event::Event; use crate::expand::expand_escape_string; use crate::expand::expand_escape_variable; -use crate::history::history_session_id; use crate::history::History; +use crate::history::history_session_id; use crate::{ env::{EnvMode, EnvVar, Environment}, wutil::wcstoi::wcstoi_partial, diff --git a/src/builtins/set_color.rs b/src/builtins/set_color.rs index 91e346c7b..307d8ea39 100644 --- a/src/builtins/set_color.rs +++ b/src/builtins/set_color.rs @@ -4,9 +4,9 @@ use crate::color::Color; use crate::common::str2wcstring; use crate::screen::{is_dumb, only_grayscale}; -use crate::terminal::{use_terminfo, Outputter}; +use crate::terminal::{Outputter, use_terminfo}; use crate::text_face::{ - self, parse_text_face_and_options, PrintColorsArgs, SpecifiedTextFace, TextFace, TextStyling, + self, PrintColorsArgs, SpecifiedTextFace, TextFace, TextStyling, parse_text_face_and_options, }; fn print_colors( diff --git a/src/builtins/shared.rs b/src/builtins/shared.rs index 6c6ecf130..079fa6275 100644 --- a/src/builtins/shared.rs +++ b/src/builtins/shared.rs @@ -1,10 +1,10 @@ use super::prelude::*; -use crate::common::{escape, get_by_sorted_name, str2wcstring, Named}; +use crate::common::{Named, escape, get_by_sorted_name, str2wcstring}; use crate::io::OutputStream; use crate::parse_constants::UNKNOWN_BUILTIN_ERR_MSG; use crate::parse_util::parse_util_argument_is_help; use crate::parser::{BlockType, LoopStatus}; -use crate::proc::{no_exec, Pid, ProcStatus}; +use crate::proc::{Pid, ProcStatus, no_exec}; use crate::wchar::L; use crate::{builtins::*, wutil}; use errno::errno; @@ -125,11 +125,7 @@ pub trait BuiltinResultExt { impl BuiltinResultExt for BuiltinResult { fn from_dynamic(code: c_int) -> Self { - if code == 0 { - Ok(SUCCESS) - } else { - Err(code) - } + if code == 0 { Ok(SUCCESS) } else { Err(code) } } fn builtin_status_code(&self) -> c_int { match self { diff --git a/src/builtins/source.rs b/src/builtins/source.rs index 1e2622954..2b2d54c49 100644 --- a/src/builtins/source.rs +++ b/src/builtins/source.rs @@ -1,7 +1,7 @@ use std::os::fd::AsRawFd; use crate::{ - common::{escape, FilenameRef}, + common::{FilenameRef, escape}, fds::wopen_cloexec, nix::isatty, parser::Block, diff --git a/src/builtins/status.rs b/src/builtins/status.rs index 8ee219c7f..7b7b3873d 100644 --- a/src/builtins/status.rs +++ b/src/builtins/status.rs @@ -1,17 +1,17 @@ use std::os::unix::prelude::*; use super::prelude::*; -use crate::common::{get_executable_path, str2wcstring, PROGRAM_NAME}; +use crate::common::{PROGRAM_NAME, get_executable_path, str2wcstring}; use crate::future_feature_flags::{self as features, feature_test}; use crate::proc::{ - get_job_control_mode, get_login, is_interactive_session, set_job_control_mode, JobControl, + JobControl, get_job_control_mode, get_login, is_interactive_session, set_job_control_mode, }; use crate::reader::reader_in_interactive_read; use crate::tty_handoff::{get_scroll_content_up_capability, xtversion}; -use crate::wutil::{waccess, wbasename, wdirname, wrealpath, Error}; +use crate::wutil::{Error, waccess, wbasename, wdirname, wrealpath}; use libc::F_OK; -use nix::errno::Errno; use nix::NixPath; +use nix::errno::Errno; macro_rules! str_enum { ($name:ident, $(($val:ident, $str:expr)),* $(,)?) => { diff --git a/src/builtins/string/escape.rs b/src/builtins/string/escape.rs index a9dd152a4..1b509bb22 100644 --- a/src/builtins/string/escape.rs +++ b/src/builtins/string/escape.rs @@ -1,5 +1,5 @@ use super::*; -use crate::common::{escape_string, EscapeFlags, EscapeStringStyle}; +use crate::common::{EscapeFlags, EscapeStringStyle, escape_string}; #[derive(Default)] pub struct Escape { diff --git a/src/builtins/string/match.rs b/src/builtins/string/match.rs index 105cc236e..584512030 100644 --- a/src/builtins/string/match.rs +++ b/src/builtins/string/match.rs @@ -6,7 +6,7 @@ use crate::env::{EnvMode, EnvVar, EnvVarFlags}; use crate::flog::FLOG; use crate::parse_util::parse_util_unescape_wildcards; -use crate::wildcard::{wildcard_match, ANY_STRING}; +use crate::wildcard::{ANY_STRING, wildcard_match}; #[derive(Default)] pub struct Match<'args> { diff --git a/src/builtins/string/replace.rs b/src/builtins/string/replace.rs index 817b9d4e0..99da54172 100644 --- a/src/builtins/string/replace.rs +++ b/src/builtins/string/replace.rs @@ -3,7 +3,7 @@ use pcre2::utf32::{Regex, RegexBuilder}; use super::*; -use crate::future_feature_flags::{feature_test, FeatureFlag}; +use crate::future_feature_flags::{FeatureFlag, feature_test}; #[derive(Default)] pub struct Replace<'args> { diff --git a/src/builtins/string/unescape.rs b/src/builtins/string/unescape.rs index b446d964a..f635d4781 100644 --- a/src/builtins/string/unescape.rs +++ b/src/builtins/string/unescape.rs @@ -1,5 +1,5 @@ use super::*; -use crate::common::{unescape_string, UnescapeStringStyle}; +use crate::common::{UnescapeStringStyle, unescape_string}; #[derive(Default)] pub struct Unescape { diff --git a/src/builtins/test.rs b/src/builtins/test.rs index c460516f0..bc46a799c 100644 --- a/src/builtins/test.rs +++ b/src/builtins/test.rs @@ -1,6 +1,6 @@ use super::prelude::*; use crate::common; -use crate::future_feature_flags::{feature_test, FeatureFlag}; +use crate::future_feature_flags::{FeatureFlag, feature_test}; use crate::should_flog; mod test_expressions { @@ -8,8 +8,8 @@ mod test_expressions { use crate::nix::isatty; use crate::wutil::{ - file_id_for_path, fish_wcswidth, lwstat, waccess, wcstod::wcstod, wcstoi_opts, wstat, - Error, Options, + Error, Options, file_id_for_path, fish_wcswidth, lwstat, waccess, wcstod::wcstod, + wcstoi_opts, wstat, }; use once_cell::sync::Lazy; use std::collections::HashMap; diff --git a/src/builtins/tests/string_tests.rs b/src/builtins/tests/string_tests.rs index 34ed52c2d..cbe4181f0 100644 --- a/src/builtins/tests/string_tests.rs +++ b/src/builtins/tests/string_tests.rs @@ -11,7 +11,7 @@ fn test_string() { }; use crate::builtins::string::string; use crate::common::escape; - use crate::future_feature_flags::{scoped_test, FeatureFlag}; + use crate::future_feature_flags::{FeatureFlag, scoped_test}; use crate::io::{IoStreams, OutputStream, StringOutputStream}; use crate::tests::prelude::*; use crate::wchar::prelude::*; diff --git a/src/builtins/ulimit.rs b/src/builtins/ulimit.rs index f0516c684..e2a7cd73b 100644 --- a/src/builtins/ulimit.rs +++ b/src/builtins/ulimit.rs @@ -1,6 +1,6 @@ use std::cmp::Ordering; -use libc::{c_uint, rlim_t, RLIM_INFINITY}; +use libc::{RLIM_INFINITY, c_uint, rlim_t}; use nix::errno::Errno; use once_cell::sync::Lazy; diff --git a/src/builtins/wait.rs b/src/builtins/wait.rs index 8399c6b30..efadf241e 100644 --- a/src/builtins/wait.rs +++ b/src/builtins/wait.rs @@ -1,5 +1,5 @@ use super::prelude::*; -use crate::proc::{proc_wait_any, Job, Pid}; +use crate::proc::{Job, Pid, proc_wait_any}; use crate::signal::SigChecker; use crate::wait_handle::{WaitHandleRef, WaitHandleStore}; diff --git a/src/common.rs b/src/common.rs index 6cf7f2946..3bdf83f5d 100644 --- a/src/common.rs +++ b/src/common.rs @@ -5,7 +5,7 @@ PROCESS_EXPAND_SELF, PROCESS_EXPAND_SELF_STR, VARIABLE_EXPAND, VARIABLE_EXPAND_SINGLE, }; use crate::fallback::fish_wcwidth; -use crate::future_feature_flags::{feature_test, FeatureFlag}; +use crate::future_feature_flags::{FeatureFlag, feature_test}; use crate::global_safety::AtomicRef; use crate::global_safety::RelaxedAtomicBool; use crate::key; @@ -17,11 +17,11 @@ use crate::wcstringutil::wcs2string_callback; use crate::wildcard::{ANY_CHAR, ANY_STRING, ANY_STRING_RECURSIVE}; use crate::wutil::encoding::{ - mbrtowc, probe_is_multibyte_locale, wcrtomb, zero_mbstate, AT_LEAST_MB_LEN_MAX, + AT_LEAST_MB_LEN_MAX, mbrtowc, probe_is_multibyte_locale, wcrtomb, zero_mbstate, }; use crate::wutil::fish_iswalnum; use bitflags::bitflags; -use libc::{SIGTTOU, SIG_IGN, STDIN_FILENO}; +use libc::{SIG_IGN, SIGTTOU, STDIN_FILENO}; use once_cell::sync::OnceCell; use std::cell::{Cell, RefCell}; use std::env; diff --git a/src/complete.rs b/src/complete.rs index ba4e323be..b3943e23e 100644 --- a/src/complete.rs +++ b/src/complete.rs @@ -3,8 +3,8 @@ collections::{BTreeMap, BTreeSet, HashMap, HashSet}, mem, sync::{ - atomic::{self, AtomicUsize}, Mutex, MutexGuard, + atomic::{self, AtomicUsize}, }, time::{Duration, Instant}, }; @@ -14,7 +14,7 @@ common::charptr2wcstring, reader::{get_quote, is_backslashed}, util::wcsfilecmp, - wutil::{localizable_string, LocalizableString}, + wutil::{LocalizableString, localizable_string}, }; use bitflags::bitflags; use once_cell::sync::Lazy; @@ -24,18 +24,18 @@ autoload::Autoload, builtins::shared::{builtin_exists, builtin_get_desc, builtin_get_names}, common::{ - escape, unescape_string, valid_var_name_char, ScopeGuard, UnescapeFlags, - UnescapeStringStyle, + ScopeGuard, UnescapeFlags, UnescapeStringStyle, escape, unescape_string, + valid_var_name_char, }, env::{EnvMode, EnvStack, Environment}, exec::exec_subshell, expand::{ - expand_escape_string, expand_escape_variable, expand_one, expand_string, - expand_to_receiver, ExpandFlags, ExpandResultCode, + ExpandFlags, ExpandResultCode, expand_escape_string, expand_escape_variable, expand_one, + expand_string, expand_to_receiver, }, flog::{FLOG, FLOGF}, function, - history::{history_session_id, History}, + history::{History, history_session_id}, operation_context::OperationContext, parse_constants::SourceRange, parse_util::{ @@ -44,12 +44,12 @@ parser::{Block, Parser}, parser_keywords::parser_keywords_is_subcommand, path::{path_get_path, path_try_get_path}, - tokenizer::{variable_assignment_equals_pos, Tok, TokFlags, TokenType, Tokenizer}, + tokenizer::{Tok, TokFlags, TokenType, Tokenizer, variable_assignment_equals_pos}, wchar::prelude::*, wchar_ext::WExt, wcstringutil::{ - string_fuzzy_match_string, string_prefixes_string, string_prefixes_string_case_insensitive, - StringFuzzyMatch, + StringFuzzyMatch, string_fuzzy_match_string, string_prefixes_string, + string_prefixes_string_case_insensitive, }, wildcard::{wildcard_complete, wildcard_has, wildcard_match}, wutil::wrealpath, diff --git a/src/env/config_paths.rs b/src/env/config_paths.rs index 27c064887..563bd5f12 100644 --- a/src/env/config_paths.rs +++ b/src/env/config_paths.rs @@ -1,7 +1,7 @@ -use crate::common::wcs2string; use crate::common::BUILD_DIR; +use crate::common::wcs2string; use crate::wchar::prelude::*; -use crate::{common::get_executable_path, FLOG, FLOGF}; +use crate::{FLOG, FLOGF, common::get_executable_path}; use fish_build_helper::workspace_root; use std::ffi::OsString; use std::os::unix::ffi::OsStringExt; diff --git a/src/env/environment.rs b/src/env/environment.rs index 78f4199a1..f35420b70 100644 --- a/src/env/environment.rs +++ b/src/env/environment.rs @@ -1,18 +1,18 @@ -use super::environment_impl::{ - colon_split, uvars, EnvMutex, EnvMutexGuard, EnvScopedImpl, EnvStackImpl, ModResult, - UVAR_SCOPE_IS_GLOBAL, -}; use super::ElectricVar; -use crate::abbrs::{abbrs_get_set, Abbreviation, Position}; +use super::environment_impl::{ + EnvMutex, EnvMutexGuard, EnvScopedImpl, EnvStackImpl, ModResult, UVAR_SCOPE_IS_GLOBAL, + colon_split, uvars, +}; +use crate::abbrs::{Abbreviation, Position, abbrs_get_set}; use crate::builtins::shared::{BuiltinResult, SUCCESS}; -use crate::common::{str2wcstring, unescape_string, wcs2zstring, UnescapeStringStyle}; +use crate::common::{UnescapeStringStyle, str2wcstring, unescape_string, wcs2zstring}; use crate::env::config_paths::ConfigPaths; use crate::env::{EnvMode, EnvVar, Statuses}; use crate::env_dispatch::{env_dispatch_init, env_dispatch_var_change}; use crate::event::Event; use crate::flog::FLOG; use crate::global_safety::RelaxedAtomicBool; -use crate::input::{init_input, FISH_BIND_MODE_VAR}; +use crate::input::{FISH_BIND_MODE_VAR, init_input}; use crate::nix::{geteuid, getpid}; use crate::null_terminated_array::OwningNullTerminatedArray; use crate::path::{ @@ -441,11 +441,7 @@ fn get_hostname_identifier() -> Option { let cstr = unsafe { CStr::from_ptr(b.as_ptr()) }; let res = str2wcstring(cstr.to_bytes()); - if res.is_empty() { - None - } else { - Some(res) - } + if res.is_empty() { None } else { Some(res) } } else { None } diff --git a/src/env/environment_impl.rs b/src/env/environment_impl.rs index 05f769257..477b4c463 100644 --- a/src/env/environment_impl.rs +++ b/src/env/environment_impl.rs @@ -1,12 +1,12 @@ use crate::common::wcs2zstring; use crate::env::{ - is_read_only, ElectricVar, EnvMode, EnvStackSetResult, EnvVar, EnvVarFlags, Statuses, VarTable, - ELECTRIC_VARIABLES, PATH_ARRAY_SEP, + ELECTRIC_VARIABLES, ElectricVar, EnvMode, EnvStackSetResult, EnvVar, EnvVarFlags, + PATH_ARRAY_SEP, Statuses, VarTable, is_read_only, }; use crate::env_universal_common::EnvUniversal; use crate::flog::FLOG; use crate::global_safety::RelaxedAtomicBool; -use crate::history::{history_session_id_from_var, History}; +use crate::history::{History, history_session_id_from_var}; use crate::kill::kill_entries; use crate::nix::umask; use crate::null_terminated_array::OwningNullTerminatedArray; @@ -27,7 +27,7 @@ use portable_atomic::AtomicU64; #[cfg(target_has_atomic = "64")] use std::sync::atomic::AtomicU64; -use std::sync::{atomic::Ordering, Arc, Mutex, MutexGuard}; +use std::sync::{Arc, Mutex, MutexGuard, atomic::Ordering}; /// Getter for universal variables. /// This is typically initialized in env_init(), and is considered empty before then. @@ -222,7 +222,7 @@ impl Deref for EnvNodeRef { type Target = RefCell; fn deref(&self) -> &Self::Target { - &self.0 .0 + &self.0.0 } } diff --git a/src/env/mod.rs b/src/env/mod.rs index 610cc6355..c8d6eefdf 100644 --- a/src/env/mod.rs +++ b/src/env/mod.rs @@ -5,7 +5,7 @@ use crate::common::ToCString; pub use environment::*; -use std::sync::{atomic::AtomicUsize, Mutex}; +use std::sync::{Mutex, atomic::AtomicUsize}; pub use var::*; /// Limit `read` to 1 GiB (bytes, not wide chars) by default. This can be overridden with the diff --git a/src/env/var.rs b/src/env/var.rs index 0c2ba8a0e..f66c115ac 100644 --- a/src/env/var.rs +++ b/src/env/var.rs @@ -1,5 +1,5 @@ use crate::signal::Signal; -use crate::wchar::{wstr, WString, L}; +use crate::wchar::{L, WString, wstr}; use crate::wcstringutil::join_strings; use bitflags::bitflags; use libc::c_int; diff --git a/src/env_dispatch.rs b/src/env_dispatch.rs index bad5f3396..9d407b944 100644 --- a/src/env_dispatch.rs +++ b/src/env_dispatch.rs @@ -1,6 +1,6 @@ use crate::complete::complete_invalidate_path; -use crate::env::{setenv_lock, unsetenv_lock, EnvMode, EnvStack, Environment}; use crate::env::{DEFAULT_READ_BYTE_LIMIT, READ_BYTE_LIMIT}; +use crate::env::{EnvMode, EnvStack, Environment, setenv_lock, unsetenv_lock}; use crate::flog::FLOG; use crate::input_common::{update_wait_on_escape_ms, update_wait_on_sequence_key_ms}; use crate::reader::{ @@ -8,10 +8,10 @@ reader_schedule_prompt_repaint, reader_set_autosuggestion_enabled, reader_set_transient_prompt, }; use crate::screen::{ - screen_set_midnight_commander_hack, IS_DUMB, LAYOUT_CACHE_SHARED, ONLY_GRAYSCALE, + IS_DUMB, LAYOUT_CACHE_SHARED, ONLY_GRAYSCALE, screen_set_midnight_commander_hack, }; -use crate::terminal::use_terminfo; use crate::terminal::ColorSupport; +use crate::terminal::use_terminfo; use crate::tty_handoff::xtversion; use crate::wchar::prelude::*; use crate::wutil::encoding::probe_is_multibyte_locale; diff --git a/src/env_universal_common.rs b/src/env_universal_common.rs index 374b767c0..b1d0e0487 100644 --- a/src/env_universal_common.rs +++ b/src/env_universal_common.rs @@ -1,17 +1,17 @@ #![allow(clippy::bad_bit_mask)] use crate::common::{ - unescape_string, valid_var_name, wcs2zstring, UnescapeFlags, UnescapeStringStyle, + UnescapeFlags, UnescapeStringStyle, unescape_string, valid_var_name, wcs2zstring, }; use crate::env::{EnvVar, EnvVarFlags, VarTable}; use crate::flog::{FLOG, FLOGF}; -use crate::fs::{lock_and_load, rewrite_via_temporary_file, PotentialUpdate}; +use crate::fs::{PotentialUpdate, lock_and_load, rewrite_via_temporary_file}; use crate::path::path_get_config; use crate::wchar::{decode_byte_from_char, prelude::*}; -use crate::wcstringutil::{join_strings, LineIterator}; -use crate::wutil::{file_id_for_file, file_id_for_path_narrow, wrealpath, FileId, INVALID_FILE_ID}; -use std::collections::hash_map::Entry; +use crate::wcstringutil::{LineIterator, join_strings}; +use crate::wutil::{FileId, INVALID_FILE_ID, file_id_for_file, file_id_for_path_narrow, wrealpath}; use std::collections::HashSet; +use std::collections::hash_map::Entry; use std::ffi::CString; use std::fs::File; use std::io::{Read, Write}; diff --git a/src/event.rs b/src/event.rs index a7402fb32..4faa75748 100644 --- a/src/event.rs +++ b/src/event.rs @@ -7,13 +7,13 @@ use std::sync::atomic::{AtomicBool, AtomicU32, Ordering}; use std::sync::{Arc, Mutex}; -use crate::common::{escape, ScopeGuard}; +use crate::common::{ScopeGuard, escape}; use crate::flog::FLOG; use crate::io::{IoChain, IoStreams}; use crate::job_group::MaybeJobId; use crate::parser::{Block, Parser}; use crate::proc::Pid; -use crate::signal::{signal_check_cancel, signal_handle, Signal}; +use crate::signal::{Signal, signal_check_cancel, signal_handle}; use crate::termsize; use crate::wchar::prelude::*; diff --git a/src/exec.rs b/src/exec.rs index e89149d6a..11c8d964d 100644 --- a/src/exec.rs +++ b/src/exec.rs @@ -4,19 +4,20 @@ // performed have been massive. use crate::builtins::shared::{ - builtin_run, ErrorCode, STATUS_CMD_ERROR, STATUS_CMD_UNKNOWN, STATUS_NOT_EXECUTABLE, - STATUS_READ_TOO_MUCH, + ErrorCode, STATUS_CMD_ERROR, STATUS_CMD_UNKNOWN, STATUS_NOT_EXECUTABLE, STATUS_READ_TOO_MUCH, + builtin_run, }; use crate::common::{ - exit_without_destructors, str2wcstring, truncate_at_nul, wcs2string, wcs2zstring, write_loop, - ScopeGuard, + ScopeGuard, exit_without_destructors, str2wcstring, truncate_at_nul, wcs2string, wcs2zstring, + write_loop, }; -use crate::env::{EnvMode, EnvStack, Environment, Statuses, READ_BYTE_LIMIT}; +use crate::env::{EnvMode, EnvStack, Environment, READ_BYTE_LIMIT, Statuses}; #[cfg(FISH_USE_POSIX_SPAWN)] use crate::env_dispatch::use_posix_spawn; use crate::fds::make_fd_blocking; -use crate::fds::{make_autoclose_pipes, open_cloexec, PIPE_ERROR}; +use crate::fds::{PIPE_ERROR, make_autoclose_pipes, open_cloexec}; use crate::flog::{FLOG, FLOGF}; +use crate::fork_exec::PATH_BSHELL; use crate::fork_exec::blocked_signals_for_job; use crate::fork_exec::postfork::{ child_setup_process, execute_fork, execute_setpgid, report_setpgid_error, @@ -24,7 +25,6 @@ }; #[cfg(FISH_USE_POSIX_SPAWN)] use crate::fork_exec::spawn::PosixSpawner; -use crate::fork_exec::PATH_BSHELL; use crate::function::{self, FunctionProperties}; use crate::io::{ BufferedOutputStream, FdOutputStream, IoBufferfill, IoChain, IoClose, IoMode, IoPipe, @@ -36,11 +36,11 @@ #[cfg(FISH_USE_POSIX_SPAWN)] use crate::proc::Pid; use crate::proc::{ - hup_jobs, is_interactive_session, jobs_requiring_warning_on_exit, no_exec, - print_exit_warning_for_jobs, InternalProc, Job, JobGroupRef, ProcStatus, Process, ProcessType, + InternalProc, Job, JobGroupRef, ProcStatus, Process, ProcessType, hup_jobs, + is_interactive_session, jobs_requiring_warning_on_exit, no_exec, print_exit_warning_for_jobs, }; use crate::reader::{reader_run_count, safe_restore_term_mode}; -use crate::redirection::{dup2_list_resolve_chain, Dup2List}; +use crate::redirection::{Dup2List, dup2_list_resolve_chain}; use crate::threads::{iothread_perform_cant_wait, is_forked_child}; use crate::trace::trace_if_enabled_with_args; use crate::tty_handoff::TtyHandoff; @@ -49,8 +49,8 @@ use crate::wutil::{fish_wcstol, perror}; use errno::{errno, set_errno}; use libc::{ - c_char, EACCES, ENOENT, ENOEXEC, ENOTDIR, EPIPE, EXIT_FAILURE, EXIT_SUCCESS, STDERR_FILENO, - STDIN_FILENO, STDOUT_FILENO, + EACCES, ENOENT, ENOEXEC, ENOTDIR, EPIPE, EXIT_FAILURE, EXIT_SUCCESS, STDERR_FILENO, + STDIN_FILENO, STDOUT_FILENO, c_char, }; use nix::fcntl::OFlag; use nix::sys::stat; @@ -61,7 +61,7 @@ use std::os::fd::{AsRawFd, OwnedFd, RawFd}; use std::slice; use std::sync::atomic::Ordering; -use std::sync::{atomic::AtomicUsize, Arc}; +use std::sync::{Arc, atomic::AtomicUsize}; /// Execute the processes specified by `j` in the parser \p. /// On a true return, the job was successfully launched and the parser will take responsibility for @@ -289,11 +289,7 @@ pub fn exec_subshell_for_expand( true, ); // Only return an error code if we should break expansion. - if break_expand { - ret - } else { - Ok(()) - } + if break_expand { ret } else { Ok(()) } } /// Number of calls to fork() or posix_spawn(). @@ -1340,7 +1336,9 @@ fn exec_process_in_job( } ProcessType::Exec => { // We should have handled exec up above. - panic!("process_type_t::exec process found in pipeline, where it should never be. Aborting."); + panic!( + "process_type_t::exec process found in pipeline, where it should never be. Aborting." + ); } } } diff --git a/src/expand.rs b/src/expand.rs index 74f012762..fb4db92f4 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -8,27 +8,27 @@ STATUS_INVALID_ARGS, STATUS_NOT_EXECUTABLE, STATUS_READ_TOO_MUCH, STATUS_UNMATCHED_WILDCARD, }; use crate::common::{ - char_offset, charptr2wcstring, escape, escape_string, escape_string_for_double_quotes, - unescape_string, valid_var_name_char, wcs2zstring, EscapeFlags, EscapeStringStyle, - UnescapeFlags, UnescapeStringStyle, EXPAND_RESERVED_BASE, EXPAND_RESERVED_END, + EXPAND_RESERVED_BASE, EXPAND_RESERVED_END, EscapeFlags, EscapeStringStyle, UnescapeFlags, + UnescapeStringStyle, char_offset, charptr2wcstring, escape, escape_string, + escape_string_for_double_quotes, unescape_string, valid_var_name_char, wcs2zstring, }; use crate::complete::{CompleteFlags, Completion, CompletionList, CompletionReceiver}; use crate::env::{EnvVar, Environment}; use crate::exec::exec_subshell_for_expand; -use crate::future_feature_flags::{feature_test, FeatureFlag}; -use crate::history::{history_session_id, History}; +use crate::future_feature_flags::{FeatureFlag, feature_test}; +use crate::history::{History, history_session_id}; use crate::operation_context::OperationContext; use crate::parse_constants::{ParseError, ParseErrorCode, ParseErrorList, SOURCE_LOCATION_UNKNOWN}; use crate::parse_util::{ - parse_util_expand_variable_error, parse_util_locate_cmdsubst_range, MaybeParentheses, + MaybeParentheses, parse_util_expand_variable_error, parse_util_locate_cmdsubst_range, }; use crate::path::path_apply_working_directory; use crate::util::wcsfilecmp_glob; use crate::wchar::prelude::*; use crate::wcstringutil::{join_strings, trim}; +use crate::wildcard::{ANY_CHAR, ANY_STRING, ANY_STRING_RECURSIVE, WildcardResult}; use crate::wildcard::{wildcard_expand_string, wildcard_has_internal}; -use crate::wildcard::{WildcardResult, ANY_CHAR, ANY_STRING, ANY_STRING_RECURSIVE}; -use crate::wutil::{normalize_path, wcstoi_partial, Options}; +use crate::wutil::{Options, normalize_path, wcstoi_partial}; use bitflags::bitflags; use std::mem::MaybeUninit; @@ -1342,11 +1342,11 @@ fn stage_cmdsubst(&mut self, input: WString, out: &mut CompletionReceiver) -> Ex } MaybeParentheses::CommandSubstitution(parens) => { append_cmdsub_error!( - self.errors, - parens.start(), - parens.end()-1, - "command substitutions not allowed in command position. Try var=(your-cmd) $var ..." - ); + self.errors, + parens.start(), + parens.end() - 1, + "command substitutions not allowed in command position. Try var=(your-cmd) $var ..." + ); return ExpandResult::make_error(STATUS_EXPAND_ERROR); } } diff --git a/src/fd_monitor.rs b/src/fd_monitor.rs index 28a986985..fe3408eae 100644 --- a/src/fd_monitor.rs +++ b/src/fd_monitor.rs @@ -15,7 +15,7 @@ use crate::threads::assert_is_background_thread; use crate::wutil::perror; use errno::errno; -use libc::{c_void, EAGAIN, EINTR, EWOULDBLOCK}; +use libc::{EAGAIN, EINTR, EWOULDBLOCK, c_void}; #[cfg(not(HAVE_EVENTFD))] use crate::fds::{make_autoclose_pipes, make_fd_nonblocking}; diff --git a/src/fds.rs b/src/fds.rs index c54b0568f..7a1362664 100644 --- a/src/fds.rs +++ b/src/fds.rs @@ -5,7 +5,7 @@ use crate::tests::prelude::*; use crate::wchar::prelude::*; use crate::wutil::perror; -use libc::{c_int, EINTR, FD_CLOEXEC, F_GETFD, F_GETFL, F_SETFD, F_SETFL, O_NONBLOCK}; +use libc::{EINTR, F_GETFD, F_GETFL, F_SETFD, F_SETFL, FD_CLOEXEC, O_NONBLOCK, c_int}; use nix::fcntl::FcntlArg; use nix::{fcntl::OFlag, unistd}; use std::ffi::CStr; diff --git a/src/flog.rs b/src/flog.rs index c3aa3a7eb..15897f7f6 100644 --- a/src/flog.rs +++ b/src/flog.rs @@ -254,7 +254,7 @@ macro_rules! should_flog { }; } -pub use {should_flog, FLOG, FLOGF}; +pub use {FLOG, FLOGF, should_flog}; /// For each category, if its name matches the wildcard, set its enabled to the given sense. fn apply_one_wildcard(wc_esc: &wstr, sense: bool) { diff --git a/src/fork_exec/postfork.rs b/src/fork_exec/postfork.rs index 57337191a..f585188a9 100644 --- a/src/fork_exec/postfork.rs +++ b/src/fork_exec/postfork.rs @@ -7,7 +7,7 @@ use crate::redirection::Dup2List; use crate::signal::signal_reset_handlers; use crate::{common::exit_without_destructors, wutil::fstat}; -use libc::{pid_t, O_RDONLY}; +use libc::{O_RDONLY, pid_t}; use std::ffi::CStr; use std::num::NonZeroU32; use std::os::unix::fs::MetadataExt; diff --git a/src/fork_exec/spawn.rs b/src/fork_exec/spawn.rs index f733b8bbe..adbde6f41 100644 --- a/src/fork_exec/spawn.rs +++ b/src/fork_exec/spawn.rs @@ -1,8 +1,8 @@ //! Wrappers around posix_spawn. -use super::blocked_signals_for_job; use super::PATH_BSHELL; -use crate::exec::{is_thompson_shell_script, PgroupPolicy}; +use super::blocked_signals_for_job; +use crate::exec::{PgroupPolicy, is_thompson_shell_script}; use crate::proc::Job; use crate::redirection::Dup2List; use crate::signal::signals_to_default; diff --git a/src/fs.rs b/src/fs.rs index 5a65a2cc5..a7fa09e12 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -1,15 +1,15 @@ use crate::{ + FLOG, FLOGF, common::{str2wcstring, wcs2osstring, wcs2zstring}, fds::wopen_cloexec, - path::{path_remoteness, DirRemoteness}, + path::{DirRemoteness, path_remoteness}, wchar::prelude::*, wutil::{ - file_id_for_file, file_id_for_path, wdirname, wrename, wunlink, FileId, INVALID_FILE_ID, + FileId, INVALID_FILE_ID, file_id_for_file, file_id_for_path, wdirname, wrename, wunlink, }, - FLOG, FLOGF, }; use errno::errno; -use libc::{c_int, fchown, flock, LOCK_EX, LOCK_SH}; +use libc::{LOCK_EX, LOCK_SH, c_int, fchown, flock}; use nix::{fcntl::OFlag, sys::stat::Mode}; use std::{ ffi::CString, @@ -32,7 +32,7 @@ fn fish_mkstemp_cloexec(name_template: CString) -> std::io::Result<(File, CStrin }; #[cfg(apple)] let fd = { - use libc::{FD_CLOEXEC, F_SETFD}; + use libc::{F_SETFD, FD_CLOEXEC}; let fd = unsafe { libc::mkstemp(name) }; if fd != -1 { unsafe { libc::fcntl(fd, F_SETFD, FD_CLOEXEC) }; @@ -262,7 +262,10 @@ pub fn lock_and_load(path: &wstr, load: F) -> std::io::Result<(File // If the file id did not change, we assume that we loaded a consistent state. return Ok((final_file_id, loaded_data)); } - Err(std::io::Error::new(std::io::ErrorKind::Other, "Failed to update the file. Locking is disabled, and the fallback code did not succeed within the permissible number of attempts.")) + Err(std::io::Error::new( + std::io::ErrorKind::Other, + "Failed to update the file. Locking is disabled, and the fallback code did not succeed within the permissible number of attempts.", + )) } pub struct PotentialUpdate { @@ -470,7 +473,10 @@ fn try_rewriting( // (If we did write.) return Ok((final_file_id, potential_update)); } - Err(std::io::Error::new(std::io::ErrorKind::Other, "Failed to update the file. Locking is disabled, and the fallback code did not succeed within the permissible number of attempts.")) + Err(std::io::Error::new( + std::io::ErrorKind::Other, + "Failed to update the file. Locking is disabled, and the fallback code did not succeed within the permissible number of attempts.", + )) } const TMP_FILE_SUFFIX: &wstr = L!(".XXXXXX"); diff --git a/src/function.rs b/src/function.rs index f37c80a3b..ae20a20d8 100644 --- a/src/function.rs +++ b/src/function.rs @@ -4,7 +4,7 @@ use crate::ast::{self, Node}; use crate::autoload::Autoload; -use crate::common::{assert_sync, escape, valid_func_name, FilenameRef}; +use crate::common::{FilenameRef, assert_sync, escape, valid_func_name}; use crate::complete::complete_wrap_map; use crate::env::{EnvStack, Environment}; use crate::event::{self, EventDescription}; diff --git a/src/future.rs b/src/future.rs index bb2fe7734..a7e61d864 100644 --- a/src/future.rs +++ b/src/future.rs @@ -20,7 +20,7 @@ fn is_none_or(self, f: impl FnOnce(T) -> bool) -> bool { pub trait IsSorted { type T; fn is_sorted_by(&self, pred: impl Fn(&Self::T, &Self::T) -> Option) - -> bool; + -> bool; } impl IsSorted for &[T] { type T = T; diff --git a/src/global_safety.rs b/src/global_safety.rs index 94936da64..98c598e51 100644 --- a/src/global_safety.rs +++ b/src/global_safety.rs @@ -1,7 +1,7 @@ use crate::flog::FLOG; use std::cell::{Ref, RefMut}; -use std::sync::atomic::{AtomicBool, AtomicPtr, Ordering}; use std::sync::MutexGuard; +use std::sync::atomic::{AtomicBool, AtomicPtr, Ordering}; #[derive(Debug, Default)] pub struct RelaxedAtomicBool(AtomicBool); diff --git a/src/highlight/file_tester.rs b/src/highlight/file_tester.rs index 803f8dcfd..cc676acd5 100644 --- a/src/highlight/file_tester.rs +++ b/src/highlight/file_tester.rs @@ -2,17 +2,17 @@ // to support highlighting. // Because this may perform blocking I/O, we compute results in a separate thread, // and provide them optimistically. -use crate::common::{unescape_string, UnescapeFlags, UnescapeStringStyle}; +use crate::common::{UnescapeFlags, UnescapeStringStyle, unescape_string}; use crate::expand::{ - expand_one, BRACE_BEGIN, BRACE_END, BRACE_SEP, INTERNAL_SEPARATOR, PROCESS_EXPAND_SELF, - VARIABLE_EXPAND, VARIABLE_EXPAND_SINGLE, + BRACE_BEGIN, BRACE_END, BRACE_SEP, INTERNAL_SEPARATOR, PROCESS_EXPAND_SELF, VARIABLE_EXPAND, + VARIABLE_EXPAND_SINGLE, expand_one, }; -use crate::expand::{expand_tilde, ExpandFlags, HOME_DIRECTORY}; +use crate::expand::{ExpandFlags, HOME_DIRECTORY, expand_tilde}; use crate::operation_context::OperationContext; use crate::path::path_apply_working_directory; use crate::redirection::RedirectionMode; use crate::threads::assert_is_background_thread; -use crate::wchar::{wstr, WString, L}; +use crate::wchar::{L, WString, wstr}; use crate::wchar_ext::WExt; use crate::wcstringutil::{ string_prefixes_string, string_prefixes_string_case_insensitive, string_suffixes_string, diff --git a/src/highlight/highlight.rs b/src/highlight/highlight.rs index e58a0d209..6c49fc2af 100644 --- a/src/highlight/highlight.rs +++ b/src/highlight/highlight.rs @@ -7,34 +7,34 @@ use crate::builtins::shared::builtin_exists; use crate::color::Color; use crate::common::{ - valid_var_name, valid_var_name_char, ASCII_MAX, EXPAND_RESERVED_BASE, EXPAND_RESERVED_END, + ASCII_MAX, EXPAND_RESERVED_BASE, EXPAND_RESERVED_END, valid_var_name, valid_var_name_char, }; use crate::complete::complete_wrap_map; use crate::env::{EnvVar, Environment}; use crate::expand::{ - expand_one, expand_to_command_and_args, ExpandFlags, ExpandResultCode, PROCESS_EXPAND_SELF_STR, + ExpandFlags, ExpandResultCode, PROCESS_EXPAND_SELF_STR, expand_one, expand_to_command_and_args, }; use crate::function; -use crate::future_feature_flags::{feature_test, FeatureFlag}; +use crate::future_feature_flags::{FeatureFlag, feature_test}; use crate::highlight::file_tester::FileTester; -use crate::history::{all_paths_are_valid, HistoryItem}; +use crate::history::{HistoryItem, all_paths_are_valid}; use crate::operation_context::OperationContext; use crate::parse_constants::{ ParseKeyword, ParseTokenType, ParseTreeFlags, SourceRange, StatementDecoration, }; use crate::parse_util::{ - parse_util_locate_cmdsubst_range, parse_util_slice_length, MaybeParentheses, + MaybeParentheses, parse_util_locate_cmdsubst_range, parse_util_slice_length, }; use crate::path::{path_as_implicit_cd, path_get_cdpath, path_get_path, paths_are_same_file}; use crate::terminal::Outputter; -use crate::text_face::{parse_text_face, TextFace, UnderlineStyle}; +use crate::text_face::{TextFace, UnderlineStyle, parse_text_face}; use crate::threads::assert_is_background_thread; -use crate::tokenizer::{variable_assignment_equals_pos, PipeOrRedir}; -use crate::wchar::{wstr, WString, L}; +use crate::tokenizer::{PipeOrRedir, variable_assignment_equals_pos}; +use crate::wchar::{L, WString, wstr}; use crate::wchar_ext::WExt; use crate::wcstringutil::string_prefixes_string; -use std::collections::hash_map::Entry; use std::collections::HashMap; +use std::collections::hash_map::Entry; use super::file_tester::IsFile; diff --git a/src/highlight/tests.rs b/src/highlight/tests.rs index 1c1064740..9c25c81ec 100644 --- a/src/highlight/tests.rs +++ b/src/highlight/tests.rs @@ -7,9 +7,9 @@ use crate::wchar::prelude::*; use crate::{ env::EnvStack, - highlight::file_tester::{is_potential_path, PathFlags}, - highlight::{highlight_shell, HighlightRole, HighlightSpec}, - operation_context::{OperationContext, EXPANSION_LIMIT_BACKGROUND, EXPANSION_LIMIT_DEFAULT}, + highlight::file_tester::{PathFlags, is_potential_path}, + highlight::{HighlightRole, HighlightSpec, highlight_shell}, + operation_context::{EXPANSION_LIMIT_BACKGROUND, EXPANSION_LIMIT_DEFAULT, OperationContext}, }; use libc::PATH_MAX; @@ -722,7 +722,7 @@ mod file_tester_tests { use super::*; use crate::common::charptr2wcstring; use crate::redirection::RedirectionMode; - use std::fs::{self, create_dir_all, File, Permissions}; + use std::fs::{self, File, Permissions, create_dir_all}; use std::os::unix::fs::PermissionsExt; struct TempDir { diff --git a/src/history.rs b/src/history.rs index 0ea18b9da..da8d4f5ec 100644 --- a/src/history.rs +++ b/src/history.rs @@ -18,8 +18,8 @@ common::cstr2wcstring, env::EnvVar, fs::{ - lock_and_load, rewrite_via_temporary_file, LockedFile, LockingMode, PotentialUpdate, - WriteMethod, LOCKED_FILE_MODE, + LOCKED_FILE_MODE, LockedFile, LockingMode, PotentialUpdate, WriteMethod, lock_and_load, + rewrite_via_temporary_file, }, wcstringutil::trim, }; @@ -43,15 +43,15 @@ use crate::{ ast::{self, Kind, Node}, - common::{str2wcstring, unescape_string, valid_var_name, CancelChecker, UnescapeStringStyle}, + common::{CancelChecker, UnescapeStringStyle, str2wcstring, unescape_string, valid_var_name}, env::{EnvMode, EnvStack, Environment}, - expand::{expand_one, ExpandFlags}, + expand::{ExpandFlags, expand_one}, fds::wopen_cloexec, flog::{FLOG, FLOGF}, fs::fsync, - history::file::{append_history_item_to_buffer, HistoryFileContents}, + history::file::{HistoryFileContents, append_history_item_to_buffer}, io::IoStreams, - operation_context::{OperationContext, EXPANSION_LIMIT_BACKGROUND}, + operation_context::{EXPANSION_LIMIT_BACKGROUND, OperationContext}, parse_constants::{ParseTreeFlags, StatementDecoration}, parse_util::{parse_util_detect_errors, parse_util_unescape_wildcards}, path::{path_get_config, path_get_data, path_is_valid}, @@ -59,8 +59,8 @@ util::{find_subslice, get_rng}, wchar::prelude::*, wcstringutil::subsequence_in_string, - wildcard::{wildcard_match, ANY_STRING}, - wutil::{file_id_for_file, wgettext_fmt, wrealpath, wstat, wunlink, FileId, INVALID_FILE_ID}, + wildcard::{ANY_STRING, wildcard_match}, + wutil::{FileId, INVALID_FILE_ID, file_id_for_file, wgettext_fmt, wrealpath, wstat, wunlink}, }; mod file; @@ -370,7 +370,10 @@ fn history_file_path(&self) -> std::io::Result> { } let Some(mut path) = path_get_data() else { - return Err(std::io::Error::new(std::io::ErrorKind::NotFound, "Error obtaining data directory. This is a manually constructed error which does not indicate why this happened.")); + return Err(std::io::Error::new( + std::io::ErrorKind::NotFound, + "Error obtaining data directory. This is a manually constructed error which does not indicate why this happened.", + )); }; path.push('/'); diff --git a/src/history/file.rs b/src/history/file.rs index 57ed1c86f..261435d90 100644 --- a/src/history/file.rs +++ b/src/history/file.rs @@ -9,13 +9,13 @@ time::{Duration, SystemTime, UNIX_EPOCH}, }; -use libc::{mmap, munmap, ENODEV, MAP_ANONYMOUS, MAP_FAILED, MAP_PRIVATE, PROT_READ, PROT_WRITE}; +use libc::{ENODEV, MAP_ANONYMOUS, MAP_FAILED, MAP_PRIVATE, PROT_READ, PROT_WRITE, mmap, munmap}; use super::{HistoryItem, PersistenceMode}; use crate::{ common::{str2wcstring, subslice_position, wcs2string}, flog::FLOG, - path::{path_get_data_remoteness, DirRemoteness}, + path::{DirRemoteness, path_get_data_remoteness}, }; /// History file types. @@ -125,7 +125,7 @@ pub fn create(mut history_file: &File) -> std::io::Result { return Err(std::io::Error::new( std::io::ErrorKind::Unsupported, format!("Cannot convert u64 to usize: {err}"), - )) + )); } }; if len == 0 { diff --git a/src/input.rs b/src/input.rs index ec82acff5..cdd266744 100644 --- a/src/input.rs +++ b/src/input.rs @@ -1,4 +1,4 @@ -use crate::common::{escape, get_by_sorted_name, str2wcstring, Named}; +use crate::common::{Named, escape, get_by_sorted_name, str2wcstring}; use crate::env::Environment; use crate::event; use crate::flog::FLOG; @@ -7,13 +7,13 @@ use crate::future::IsSomeAnd; use crate::global_safety::RelaxedAtomicBool; use crate::input_common::{ - match_key_event_to_key, CharEvent, CharInputStyle, ImplicitEvent, InputData, InputEventQueuer, - KeyMatchQuality, ReadlineCmd, R_END_INPUT_FUNCTIONS, + CharEvent, CharInputStyle, ImplicitEvent, InputData, InputEventQueuer, KeyMatchQuality, + R_END_INPUT_FUNCTIONS, ReadlineCmd, match_key_event_to_key, }; -use crate::key::{self, canonicalize_raw_escapes, ctrl, Key, Modifiers}; +use crate::key::{self, Key, Modifiers, canonicalize_raw_escapes, ctrl}; use crate::proc::job_reap; use crate::reader::{ - reader_reading_interrupted, reader_reset_interrupted, reader_schedule_prompt_repaint, Reader, + Reader, reader_reading_interrupted, reader_reset_interrupted, reader_schedule_prompt_repaint, }; use crate::signal::signal_clear_cancel; use crate::threads::{assert_is_main_thread, iothread_service_main}; @@ -21,8 +21,8 @@ use once_cell::sync::Lazy; use std::mem; use std::sync::{ - atomic::{AtomicU32, Ordering}, Mutex, MutexGuard, + atomic::{AtomicU32, Ordering}, }; pub const FISH_BIND_MODE_VAR: &wstr = L!("fish_bind_mode"); diff --git a/src/input_common.rs b/src/input_common.rs index 55b282a04..a8eb79471 100644 --- a/src/input_common.rs +++ b/src/input_common.rs @@ -1,19 +1,19 @@ use crate::common::{ - fish_reserved_codepoint, get_is_multibyte_locale, is_windows_subsystem_for_linux, read_blocked, - shell_modes, str2wcstring, WSL, + WSL, fish_reserved_codepoint, get_is_multibyte_locale, is_windows_subsystem_for_linux, + read_blocked, shell_modes, str2wcstring, }; use crate::env::{EnvStack, Environment}; use crate::fd_readable_set::{FdReadableSet, Timeout}; -use crate::flog::{FloggableDebug, FloggableDisplay, FLOG}; +use crate::flog::{FLOG, FloggableDebug, FloggableDisplay}; use crate::key::{ - self, alt, canonicalize_control_char, canonicalize_keyed_control_char, char_to_symbol, - function_key, shift, Key, Modifiers, ViewportPosition, + self, Key, Modifiers, ViewportPosition, alt, canonicalize_control_char, + canonicalize_keyed_control_char, char_to_symbol, function_key, shift, }; use crate::reader::reader_test_and_clear_interrupted; use crate::threads::iothread_port; use crate::tty_handoff::{ - maybe_set_kitty_keyboard_capability, maybe_set_scroll_content_up_capability, - SCROLL_CONTENT_UP_TERMINFO_CODE, XTVERSION, + SCROLL_CONTENT_UP_TERMINFO_CODE, XTVERSION, maybe_set_kitty_keyboard_capability, + maybe_set_scroll_content_up_capability, }; use crate::universal_notifier::default_notifier; use crate::wchar::{encode_byte_to_char, prelude::*}; diff --git a/src/io.rs b/src/io.rs index 7f0b04a35..5a4a3dcda 100644 --- a/src/io.rs +++ b/src/io.rs @@ -1,10 +1,10 @@ use crate::builtins::shared::{STATUS_CMD_ERROR, STATUS_CMD_OK, STATUS_READ_TOO_MUCH}; -use crate::common::{str2wcstring, wcs2string, EMPTY_STRING}; +use crate::common::{EMPTY_STRING, str2wcstring, wcs2string}; use crate::fd_monitor::{Callback, FdMonitor, FdMonitorItemId}; use crate::fds::{ - make_autoclose_pipes, make_fd_nonblocking, wopen_cloexec, AutoCloseFd, PIPE_ERROR, + AutoCloseFd, PIPE_ERROR, make_autoclose_pipes, make_fd_nonblocking, wopen_cloexec, }; -use crate::flog::{should_flog, FLOG, FLOGF}; +use crate::flog::{FLOG, FLOGF, should_flog}; use crate::nix::isatty; use crate::path::path_apply_working_directory; use crate::proc::JobGroupRef; diff --git a/src/key.rs b/src/key.rs index 3edecd042..b2554b97b 100644 --- a/src/key.rs +++ b/src/key.rs @@ -1,10 +1,10 @@ use libc::VERASE; use crate::{ - common::{escape_string, EscapeFlags, EscapeStringStyle}, + common::{EscapeFlags, EscapeStringStyle, escape_string}, fallback::fish_wcwidth, flog::FloggableDebug, - future_feature_flags::{test as feature_test, FeatureFlag}, + future_feature_flags::{FeatureFlag, test as feature_test}, reader::safe_get_terminal_mode_on_startup, wchar::{decode_byte_from_char, prelude::*}, wutil::fish_wcstoul, @@ -285,7 +285,7 @@ pub(crate) fn parse_keys(value: &wstr) -> Result, WString> { "unknown modifier '%s' in '%s'", modifier, escape_nonprintables(full_key_name) - )) + )); } } } diff --git a/src/locale.rs b/src/locale.rs index 5e0bb4605..788e14eb2 100644 --- a/src/locale.rs +++ b/src/locale.rs @@ -1,5 +1,5 @@ /// Support for the "current locale." -pub use fish_printf::locale::{Locale, C_LOCALE}; +pub use fish_printf::locale::{C_LOCALE, Locale}; use std::sync::Mutex; /// Lock guarding libc `setlocale()` or `localeconv()` calls to avoid races. diff --git a/src/null_terminated_array.rs b/src/null_terminated_array.rs index 8393ed658..932141c9c 100644 --- a/src/null_terminated_array.rs +++ b/src/null_terminated_array.rs @@ -1,5 +1,5 @@ use crate::common::{assert_send, assert_sync}; -use std::ffi::{c_char, CStr, CString}; +use std::ffi::{CStr, CString, c_char}; use std::marker::PhantomData; use std::pin::Pin; use std::ptr; diff --git a/src/pager.rs b/src/pager.rs index c6d437534..f82650c62 100644 --- a/src/pager.rs +++ b/src/pager.rs @@ -1,19 +1,19 @@ //! Pager support. -use std::collections::hash_map::Entry; use std::collections::HashMap; +use std::collections::hash_map::Entry; use crate::common::{ - escape_string, get_ellipsis_char, get_ellipsis_str, get_is_multibyte_locale, EscapeFlags, - EscapeStringStyle, + EscapeFlags, EscapeStringStyle, escape_string, get_ellipsis_char, get_ellipsis_str, + get_is_multibyte_locale, }; use crate::complete::Completion; use crate::editable_line::EditableLine; #[allow(unused_imports)] use crate::future::IsSomeAnd; -use crate::highlight::{highlight_shell, HighlightRole, HighlightSpec}; +use crate::highlight::{HighlightRole, HighlightSpec, highlight_shell}; use crate::operation_context::OperationContext; -use crate::screen::{wcswidth_rendered, wcwidth_rendered, CharOffset, Line, ScreenData}; +use crate::screen::{CharOffset, Line, ScreenData, wcswidth_rendered, wcwidth_rendered}; use crate::termsize::Termsize; use crate::wchar::prelude::*; use crate::wcstringutil::string_fuzzy_match_string; diff --git a/src/panic.rs b/src/panic.rs index 16b11f983..e0638fb4b 100644 --- a/src/panic.rs +++ b/src/panic.rs @@ -1,5 +1,5 @@ use std::{ - panic::{set_hook, take_hook, UnwindSafe}, + panic::{UnwindSafe, set_hook, take_hook}, sync::atomic::{AtomicBool, Ordering}, time::Duration, }; @@ -8,7 +8,7 @@ use once_cell::sync::OnceCell; use crate::{ - common::{read_blocked, PROGRAM_NAME}, + common::{PROGRAM_NAME, read_blocked}, nix::isatty, threads::{asan_maybe_exit, is_main_thread}, }; diff --git a/src/parse_execution.rs b/src/parse_execution.rs index 1264f500b..b5397c0d1 100644 --- a/src/parse_execution.rs +++ b/src/parse_execution.rs @@ -1,24 +1,24 @@ //! Provides the "linkage" between an ast and actual execution structures (job_t, etc.). use crate::ast::{ - self, unescape_keyword, BlockStatementHeader, Keyword, Leaf, Node, Statement, Token, + self, BlockStatementHeader, Keyword, Leaf, Node, Statement, Token, unescape_keyword, }; use crate::builtins; use crate::builtins::shared::{ - builtin_exists, BUILTIN_ERR_VARNAME, STATUS_CMD_ERROR, STATUS_CMD_OK, STATUS_CMD_UNKNOWN, - STATUS_EXPAND_ERROR, STATUS_ILLEGAL_CMD, STATUS_INVALID_ARGS, STATUS_NOT_EXECUTABLE, - STATUS_UNMATCHED_WILDCARD, + BUILTIN_ERR_VARNAME, STATUS_CMD_ERROR, STATUS_CMD_OK, STATUS_CMD_UNKNOWN, STATUS_EXPAND_ERROR, + STATUS_ILLEGAL_CMD, STATUS_INVALID_ARGS, STATUS_NOT_EXECUTABLE, STATUS_UNMATCHED_WILDCARD, + builtin_exists, }; use crate::common::{ - escape, should_suppress_stderr_for_tests, truncate_at_nul, valid_var_name, ScopeGuard, - ScopeGuarding, ScopedRefCell, + ScopeGuard, ScopeGuarding, ScopedRefCell, escape, should_suppress_stderr_for_tests, + truncate_at_nul, valid_var_name, }; use crate::complete::CompletionList; use crate::env::{EnvMode, EnvStackSetResult, EnvVar, EnvVarFlags, Environment, Statuses}; use crate::event::{self, Event}; use crate::exec::exec_job; use crate::expand::{ - expand_one, expand_string, expand_to_command_and_args, ExpandFlags, ExpandResultCode, + ExpandFlags, ExpandResultCode, expand_one, expand_string, expand_to_command_and_args, }; use crate::flog::FLOG; use crate::function; @@ -26,33 +26,33 @@ use crate::job_group::JobGroup; use crate::operation_context::OperationContext; use crate::parse_constants::{ - parse_error_offset_source_start, ParseError, ParseErrorCode, ParseErrorList, ParseKeyword, - ParseTokenType, StatementDecoration, CALL_STACK_LIMIT_EXCEEDED_ERR_MSG, ERROR_TIME_BACKGROUND, + CALL_STACK_LIMIT_EXCEEDED_ERR_MSG, ERROR_TIME_BACKGROUND, FAILED_EXPANSION_VARIABLE_NAME_ERR_MSG, ILLEGAL_FD_ERR_MSG, INFINITE_FUNC_RECURSION_ERR_MSG, - WILDCARD_ERR_MSG, + ParseError, ParseErrorCode, ParseErrorList, ParseKeyword, ParseTokenType, StatementDecoration, + WILDCARD_ERR_MSG, parse_error_offset_source_start, }; use crate::parse_tree::{LineCounter, NodeRef, ParsedSourceRef}; use crate::parse_util::{ - parse_util_locate_cmdsubst_range, parse_util_unescape_wildcards, - MaybeParentheses::CommandSubstitution, + MaybeParentheses::CommandSubstitution, parse_util_locate_cmdsubst_range, + parse_util_unescape_wildcards, }; use crate::parser::{Block, BlockData, BlockId, BlockType, LoopStatus, Parser, ProfileItem}; use crate::parser_keywords::parser_keywords_is_subcommand; use crate::path::{path_as_implicit_cd, path_try_get_path}; use crate::proc::{ - get_job_control_mode, job_reap, no_exec, ConcreteAssignment, Job, JobControl, JobProperties, - JobRef, Process, ProcessType, + ConcreteAssignment, Job, JobControl, JobProperties, JobRef, Process, ProcessType, + get_job_control_mode, job_reap, no_exec, }; use crate::reader::fish_is_unwinding_for_exit; use crate::redirection::{RedirectionMode, RedirectionSpec, RedirectionSpecList}; use crate::signal::Signal; use crate::timer::push_timer; -use crate::tokenizer::{variable_assignment_equals_pos, PipeOrRedir, TokenType}; +use crate::tokenizer::{PipeOrRedir, TokenType, variable_assignment_equals_pos}; use crate::trace::{trace_if_enabled, trace_if_enabled_with_args}; use crate::wchar::prelude::*; use crate::wchar_ext::WExt; use crate::wildcard::wildcard_match; -use libc::{c_int, ENOTDIR, EXIT_SUCCESS, STDERR_FILENO, STDOUT_FILENO}; +use libc::{ENOTDIR, EXIT_SUCCESS, STDERR_FILENO, STDOUT_FILENO, c_int}; use std::io::ErrorKind; use std::rc::Rc; use std::sync::Arc; @@ -421,11 +421,7 @@ fn infinite_recursive_statement_in_job_list<'b>( None, ) && &cmd == forbidden_function_name; - if forbidden { - Some(dc) - } else { - None - } + if forbidden { Some(dc) } else { None } }; // Check main statement. @@ -1464,7 +1460,9 @@ fn determine_redirections( _ => false, } } { - eprintf!("If you wish to use process substitution, consider the psub command, see: `help psub`\n"); + eprintf!( + "If you wish to use process substitution, consider the psub command, see: `help psub`\n" + ); } return error_ret; } diff --git a/src/parse_tree.rs b/src/parse_tree.rs index 10e3045c7..74c1f4804 100644 --- a/src/parse_tree.rs +++ b/src/parse_tree.rs @@ -7,8 +7,8 @@ use crate::ast::{self, Ast, JobList, Node}; use crate::common::{assert_send, assert_sync}; use crate::parse_constants::{ - token_type_user_presentable_description, ParseErrorCode, ParseErrorList, ParseKeyword, - ParseTokenType, ParseTreeFlags, SourceOffset, SourceRange, SOURCE_OFFSET_INVALID, + ParseErrorCode, ParseErrorList, ParseKeyword, ParseTokenType, ParseTreeFlags, + SOURCE_OFFSET_INVALID, SourceOffset, SourceRange, token_type_user_presentable_description, }; use crate::tokenizer::TokenizerError; use crate::wchar::prelude::*; diff --git a/src/parse_util.rs b/src/parse_util.rs index ee57b5ce9..0a2aa738e 100644 --- a/src/parse_util.rs +++ b/src/parse_util.rs @@ -1,29 +1,30 @@ //! Various mostly unrelated utility functions related to parsing, loading and evaluating fish code. use crate::ast::{ - self, is_same_node, Ast, Keyword, Kind, Leaf, Node, NodeVisitor, Token, Traversal, + self, Ast, Keyword, Kind, Leaf, Node, NodeVisitor, Token, Traversal, is_same_node, }; use crate::builtins::shared::builtin_exists; use crate::common::{ - escape_string, unescape_string, valid_var_name, valid_var_name_char, EscapeFlags, - EscapeStringStyle, UnescapeFlags, UnescapeStringStyle, + EscapeFlags, EscapeStringStyle, UnescapeFlags, UnescapeStringStyle, escape_string, + unescape_string, valid_var_name, valid_var_name_char, }; use crate::expand::{ - expand_one, expand_to_command_and_args, ExpandFlags, ExpandResultCode, BRACE_BEGIN, BRACE_END, - BRACE_SEP, INTERNAL_SEPARATOR, VARIABLE_EXPAND, VARIABLE_EXPAND_EMPTY, VARIABLE_EXPAND_SINGLE, + BRACE_BEGIN, BRACE_END, BRACE_SEP, ExpandFlags, ExpandResultCode, INTERNAL_SEPARATOR, + VARIABLE_EXPAND, VARIABLE_EXPAND_EMPTY, VARIABLE_EXPAND_SINGLE, expand_one, + expand_to_command_and_args, }; -use crate::future_feature_flags::{feature_test, FeatureFlag}; +use crate::future_feature_flags::{FeatureFlag, feature_test}; use crate::operation_context::OperationContext; use crate::parse_constants::{ - parse_error_offset_source_start, ParseError, ParseErrorCode, ParseErrorList, ParseKeyword, + ERROR_BAD_VAR_CHAR1, ERROR_BRACKETED_VARIABLE_QUOTED1, ERROR_BRACKETED_VARIABLE1, + ERROR_NO_VAR_NAME, ERROR_NOT_ARGV_AT, ERROR_NOT_ARGV_COUNT, ERROR_NOT_ARGV_STAR, ERROR_NOT_PID, + ERROR_NOT_STATUS, INVALID_BREAK_ERR_MSG, INVALID_CONTINUE_ERR_MSG, + INVALID_PIPELINE_CMD_ERR_MSG, ParseError, ParseErrorCode, ParseErrorList, ParseKeyword, ParseTokenType, ParseTreeFlags, ParserTestErrorBits, PipelinePosition, SourceRange, - StatementDecoration, ERROR_BAD_VAR_CHAR1, ERROR_BRACKETED_VARIABLE1, - ERROR_BRACKETED_VARIABLE_QUOTED1, ERROR_NOT_ARGV_AT, ERROR_NOT_ARGV_COUNT, ERROR_NOT_ARGV_STAR, - ERROR_NOT_PID, ERROR_NOT_STATUS, ERROR_NO_VAR_NAME, INVALID_BREAK_ERR_MSG, - INVALID_CONTINUE_ERR_MSG, INVALID_PIPELINE_CMD_ERR_MSG, UNKNOWN_BUILTIN_ERR_MSG, + StatementDecoration, UNKNOWN_BUILTIN_ERR_MSG, parse_error_offset_source_start, }; use crate::tokenizer::{ - comment_end, is_token_delimiter, quote_end, Tok, TokenType, Tokenizer, TOK_ACCEPT_UNFINISHED, - TOK_SHOW_COMMENTS, + TOK_ACCEPT_UNFINISHED, TOK_SHOW_COMMENTS, Tok, TokenType, Tokenizer, comment_end, + is_token_delimiter, quote_end, }; use crate::wchar::prelude::*; use crate::wcstringutil::count_newlines; @@ -1512,11 +1513,7 @@ pub fn parse_util_detect_errors_in_argument( err |= check_subtoken(checked, arg_src.len(), out_errors); - if err.is_empty() { - Ok(()) - } else { - Err(err) - } + if err.is_empty() { Ok(()) } else { Err(err) } } fn detect_errors_in_job_conjunction( diff --git a/src/parser.rs b/src/parser.rs index bc5fb7f50..d80044422 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -3,36 +3,36 @@ use crate::ast::{self, Node}; use crate::builtins::shared::STATUS_ILLEGAL_CMD; use crate::common::{ - escape_string, wcs2string, CancelChecker, EscapeFlags, EscapeStringStyle, FilenameRef, - ScopeGuarding, ScopedCell, ScopedRefCell, PROFILING_ACTIVE, + CancelChecker, EscapeFlags, EscapeStringStyle, FilenameRef, PROFILING_ACTIVE, ScopeGuarding, + ScopedCell, ScopedRefCell, escape_string, wcs2string, }; use crate::complete::CompletionList; use crate::env::{EnvMode, EnvStack, EnvStackSetResult, Environment, Statuses}; use crate::event::{self, Event}; use crate::expand::{ - expand_string, replace_home_directory_with_tilde, ExpandFlags, ExpandResultCode, + ExpandFlags, ExpandResultCode, expand_string, replace_home_directory_with_tilde, }; -use crate::fds::{open_dir, BEST_O_SEARCH}; +use crate::fds::{BEST_O_SEARCH, open_dir}; use crate::global_safety::RelaxedAtomicBool; use crate::input_common::TerminalQuery; use crate::io::IoChain; use crate::job_group::MaybeJobId; -use crate::operation_context::{OperationContext, EXPANSION_LIMIT_DEFAULT}; +use crate::operation_context::{EXPANSION_LIMIT_DEFAULT, OperationContext}; use crate::parse_constants::{ - ParseError, ParseErrorList, ParseTreeFlags, FISH_MAX_EVAL_DEPTH, FISH_MAX_STACK_DEPTH, + FISH_MAX_EVAL_DEPTH, FISH_MAX_STACK_DEPTH, ParseError, ParseErrorList, ParseTreeFlags, SOURCE_LOCATION_UNKNOWN, }; use crate::parse_execution::{EndExecutionReason, ExecutionContext}; use crate::parse_tree::NodeRef; -use crate::parse_tree::{parse_source, LineCounter, ParsedSourceRef}; -use crate::proc::{job_reap, JobGroupRef, JobList, JobRef, Pid, ProcStatus}; -use crate::signal::{signal_check_cancel, signal_clear_cancel, Signal}; +use crate::parse_tree::{LineCounter, ParsedSourceRef, parse_source}; +use crate::proc::{JobGroupRef, JobList, JobRef, Pid, ProcStatus, job_reap}; +use crate::signal::{Signal, signal_check_cancel, signal_clear_cancel}; use crate::util::get_time; use crate::wait_handle::WaitHandleStore; use crate::wchar::prelude::*; use crate::wchar_ext::WExt; use crate::wutil::perror; -use crate::{function, FLOG}; +use crate::{FLOG, function}; use libc::c_int; #[cfg(not(target_has_atomic = "64"))] use portable_atomic::AtomicU64; @@ -43,9 +43,9 @@ use std::num::NonZeroU32; use std::os::fd::OwnedFd; use std::rc::Rc; +use std::sync::Arc; #[cfg(target_has_atomic = "64")] use std::sync::atomic::AtomicU64; -use std::sync::Arc; use std::time::Duration; pub enum BlockData { diff --git a/src/path.rs b/src/path.rs index d77d6541f..21ea5dbd5 100644 --- a/src/path.rs +++ b/src/path.rs @@ -4,11 +4,11 @@ use crate::common::{wcs2osstring, wcs2zstring}; use crate::env::{EnvMode, EnvStack, Environment, FALLBACK_PATH}; -use crate::expand::{expand_tilde, HOME_DIRECTORY}; +use crate::expand::{HOME_DIRECTORY, expand_tilde}; use crate::flog::{FLOG, FLOGF}; use crate::wchar::prelude::*; use crate::wutil::{normalize_path, path_normalize_for_cd, waccess, wdirname, wstat}; -use errno::{errno, set_errno, Errno}; +use errno::{Errno, errno, set_errno}; use libc::{EACCES, ENOENT, ENOTDIR, F_OK, X_OK}; use once_cell::sync::Lazy; use std::ffi::OsStr; @@ -585,7 +585,7 @@ fn make_base_directory(xdg_var: &wstr, non_xdg_homepath: &wstr) -> BaseDirectory // the actual $HOME or $XDG_XXX directories. This prevents the tests from failing and/or stops // the tests polluting the user's actual $HOME if a sandbox environment has not been set up. { - use crate::common::{str2wcstring, BUILD_DIR}; + use crate::common::{BUILD_DIR, str2wcstring}; use std::path::PathBuf; let mut build_dir = PathBuf::from(BUILD_DIR); diff --git a/src/proc.rs b/src/proc.rs index 479352129..1fffec845 100644 --- a/src/proc.rs +++ b/src/proc.rs @@ -4,7 +4,7 @@ use crate::ast; use crate::common::{ - charptr2wcstring, escape, is_windows_subsystem_for_linux, timef, Timepoint, WSL, + Timepoint, WSL, charptr2wcstring, escape, is_windows_subsystem_for_linux, timef, }; use crate::env::Statuses; use crate::event::{self, Event}; @@ -16,16 +16,16 @@ use crate::parser::{Block, Parser}; use crate::reader::{fish_is_unwinding_for_exit, reader_schedule_prompt_repaint}; use crate::redirection::RedirectionSpecList; -use crate::signal::{signal_set_handlers_once, Signal}; -use crate::topic_monitor::{topic_monitor_principal, GenerationsList, Topic}; +use crate::signal::{Signal, signal_set_handlers_once}; +use crate::topic_monitor::{GenerationsList, Topic, topic_monitor_principal}; use crate::wait_handle::{InternalJobId, WaitHandle, WaitHandleRef, WaitHandleStore}; use crate::wchar::prelude::*; use crate::wchar_ext::ToWString; use crate::wutil::{wbasename, wperror}; use libc::{ - EXIT_SUCCESS, SIGABRT, SIGBUS, SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT, SIGKILL, SIGPIPE, - SIGQUIT, SIGSEGV, SIGSYS, SIGTTOU, SIG_DFL, SIG_IGN, WCONTINUED, WEXITSTATUS, WIFCONTINUED, - WIFEXITED, WIFSIGNALED, WIFSTOPPED, WNOHANG, WTERMSIG, WUNTRACED, _SC_CLK_TCK, + _SC_CLK_TCK, EXIT_SUCCESS, SIG_DFL, SIG_IGN, SIGABRT, SIGBUS, SIGCONT, SIGFPE, SIGHUP, SIGILL, + SIGINT, SIGKILL, SIGPIPE, SIGQUIT, SIGSEGV, SIGSYS, SIGTTOU, WCONTINUED, WEXITSTATUS, + WIFCONTINUED, WIFEXITED, WIFSIGNALED, WIFSTOPPED, WNOHANG, WTERMSIG, WUNTRACED, }; use once_cell::sync::Lazy; #[cfg(not(target_has_atomic = "64"))] @@ -891,11 +891,7 @@ pub fn get_statuses(&self) -> Option { return None; } st.status = if self.flags().negate { - if laststatus == 0 { - 1 - } else { - 0 - } + if laststatus == 0 { 1 } else { 0 } } else { laststatus }; diff --git a/src/reader.rs b/src/reader.rs index 89aff5541..395e44851 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -18,9 +18,9 @@ //! expansion, etc. use libc::{ - c_char, ECHO, EINTR, EIO, EISDIR, ENOTTY, EPERM, ESRCH, ICANON, ICRNL, IEXTEN, INLCR, IXOFF, - IXON, ONLCR, OPOST, O_NONBLOCK, O_RDONLY, SIGINT, SIGTTIN, STDERR_FILENO, STDIN_FILENO, - STDOUT_FILENO, TCSANOW, VMIN, VQUIT, VSUSP, VTIME, _POSIX_VDISABLE, + _POSIX_VDISABLE, ECHO, EINTR, EIO, EISDIR, ENOTTY, EPERM, ESRCH, ICANON, ICRNL, IEXTEN, INLCR, + IXOFF, IXON, O_NONBLOCK, O_RDONLY, ONLCR, OPOST, SIGINT, SIGTTIN, STDERR_FILENO, STDIN_FILENO, + STDOUT_FILENO, TCSANOW, VMIN, VQUIT, VSUSP, VTIME, c_char, }; use nix::fcntl::OFlag; use nix::sys::stat::Mode; @@ -41,39 +41,39 @@ use std::rc::Rc; #[cfg(target_has_atomic = "64")] use std::sync::atomic::AtomicU64; -use std::sync::atomic::{AtomicI32, AtomicU32, AtomicU8, Ordering}; +use std::sync::atomic::{AtomicI32, AtomicU8, AtomicU32, Ordering}; use std::sync::{Arc, Mutex, MutexGuard}; use std::time::{Duration, Instant}; -use errno::{errno, Errno}; +use errno::{Errno, errno}; use crate::abbrs::abbrs_match; -use crate::ast::{self, is_same_node, Kind}; +use crate::ast::{self, Kind, is_same_node}; use crate::builtins::shared::ErrorCode; use crate::builtins::shared::STATUS_CMD_ERROR; use crate::builtins::shared::STATUS_CMD_OK; use crate::common::ScopeGuarding; use crate::common::{ - escape, escape_string, exit_without_destructors, get_ellipsis_char, get_is_multibyte_locale, + EscapeFlags, EscapeStringStyle, PROGRAM_NAME, ScopeGuard, UTF8_BOM_WCHAR, escape, + escape_string, exit_without_destructors, get_ellipsis_char, get_is_multibyte_locale, get_obfuscation_read_char, restore_term_foreground_process_group_for_exit, shell_modes, - str2wcstring, write_loop, EscapeFlags, EscapeStringStyle, ScopeGuard, PROGRAM_NAME, - UTF8_BOM_WCHAR, + str2wcstring, write_loop, }; use crate::complete::{ - complete, complete_load, sort_and_prioritize, CompleteFlags, Completion, CompletionList, - CompletionRequestOptions, + CompleteFlags, Completion, CompletionList, CompletionRequestOptions, complete, complete_load, + sort_and_prioritize, }; -use crate::editable_line::{line_at_cursor, range_of_line_at_cursor, Edit, EditableLine}; +use crate::editable_line::{Edit, EditableLine, line_at_cursor, range_of_line_at_cursor}; use crate::env::EnvStack; use crate::env::{EnvMode, Environment, Statuses}; -use crate::env_dispatch::guess_emoji_width; use crate::env_dispatch::MIDNIGHT_COMMANDER_SID; +use crate::env_dispatch::guess_emoji_width; use crate::exec::exec_subshell; use crate::expand::expand_one; -use crate::expand::{expand_string, expand_tilde, ExpandFlags, ExpandResultCode}; +use crate::expand::{ExpandFlags, ExpandResultCode, expand_string, expand_tilde}; use crate::fallback::fish_wcwidth; use crate::fd_readable_set::poll_fd_readable; -use crate::fds::{make_fd_blocking, wopen_cloexec, AutoCloseFd}; +use crate::fds::{AutoCloseFd, make_fd_blocking, wopen_cloexec}; use crate::flog::{FLOG, FLOGF}; #[allow(unused_imports)] use crate::future::IsSomeAnd; @@ -81,32 +81,32 @@ use crate::future_feature_flags::FeatureFlag; use crate::global_safety::RelaxedAtomicBool; use crate::highlight::{ - autosuggest_validate_from_history, highlight_shell, parse_text_face_for_highlight, - HighlightRole, HighlightSpec, + HighlightRole, HighlightSpec, autosuggest_validate_from_history, highlight_shell, + parse_text_face_for_highlight, }; use crate::history::{ - history_session_id, in_private_mode, History, HistorySearch, PersistenceMode, SearchDirection, - SearchFlags, SearchType, + History, HistorySearch, PersistenceMode, SearchDirection, SearchFlags, SearchType, + history_session_id, in_private_mode, }; use crate::input_common::InputEventQueue; use crate::input_common::InputEventQueuer; use crate::input_common::QueryResponse; use crate::input_common::{ - stop_query, CharEvent, CharInputStyle, CursorPositionQuery, CursorPositionQueryKind, - ImplicitEvent, InputData, QueryResultEvent, ReadlineCmd, TerminalQuery, + CharEvent, CharInputStyle, CursorPositionQuery, CursorPositionQueryKind, ImplicitEvent, + InputData, QueryResultEvent, ReadlineCmd, TerminalQuery, stop_query, }; use crate::io::IoChain; use crate::key::ViewportPosition; use crate::kill::{kill_add, kill_replace, kill_yank, kill_yank_rotate}; use crate::nix::{getpgrp, getpid, isatty}; -use crate::operation_context::{get_bg_context, OperationContext}; +use crate::operation_context::{OperationContext, get_bg_context}; use crate::pager::{PageRendering, Pager, SelectionMotion}; use crate::panic::AT_EXIT; use crate::parse_constants::SourceRange; use crate::parse_constants::{ParseTreeFlags, ParserTestErrorBits}; -use crate::parse_util::parse_util_process_extent; use crate::parse_util::MaybeParentheses; use crate::parse_util::SPACES_PER_INDENT; +use crate::parse_util::parse_util_process_extent; use crate::parse_util::{ parse_util_cmdsubst_extent, parse_util_compute_indents, parse_util_contains_wildcards, parse_util_detect_errors, parse_util_escape_string_with_quote, parse_util_escape_wildcards, @@ -118,9 +118,9 @@ have_proc_stat, hup_jobs, is_interactive_session, job_reap, jobs_requiring_warning_on_exit, print_exit_warning_for_jobs, proc_update_jiffies, }; -use crate::reader_history_search::{smartcase_flags, ReaderHistorySearch, SearchMode}; +use crate::reader_history_search::{ReaderHistorySearch, SearchMode, smartcase_flags}; use crate::screen::is_dumb; -use crate::screen::{screen_force_clear_to_end, CharOffset, Screen}; +use crate::screen::{CharOffset, Screen, screen_force_clear_to_end}; use crate::should_flog; use crate::signal::{ signal_check_cancel, signal_clear_cancel, signal_reset_handlers, signal_set_handlers, @@ -136,28 +136,28 @@ QueryXtgettcap, QueryXtversion, }; use crate::termsize::{termsize_invalidate_tty, termsize_last, termsize_update}; -use crate::text_face::parse_text_face; use crate::text_face::TextFace; +use crate::text_face::parse_text_face; use crate::threads::{ - assert_is_background_thread, assert_is_main_thread, iothread_service_main_with_timeout, - Debounce, + Debounce, assert_is_background_thread, assert_is_main_thread, + iothread_service_main_with_timeout, }; use crate::tokenizer::quote_end; use crate::tokenizer::variable_assignment_equals_pos; use crate::tokenizer::{ - tok_command, MoveWordStateMachine, MoveWordStyle, TokenType, Tokenizer, TOK_ACCEPT_UNFINISHED, - TOK_SHOW_COMMENTS, + MoveWordStateMachine, MoveWordStyle, TOK_ACCEPT_UNFINISHED, TOK_SHOW_COMMENTS, TokenType, + Tokenizer, tok_command, }; use crate::tty_handoff::SCROLL_CONTENT_UP_TERMINFO_CODE; use crate::tty_handoff::{ - get_tty_protocols_active, initialize_tty_protocols, safe_deactivate_tty_protocols, TtyHandoff, + TtyHandoff, get_tty_protocols_active, initialize_tty_protocols, safe_deactivate_tty_protocols, }; use crate::wchar::prelude::*; -use crate::wcstringutil::string_prefixes_string_maybe_case_insensitive; use crate::wcstringutil::CaseSensitivity; +use crate::wcstringutil::string_prefixes_string_maybe_case_insensitive; use crate::wcstringutil::{ - count_preceding_backslashes, join_strings, string_prefixes_string, - string_prefixes_string_case_insensitive, StringFuzzyMatch, + StringFuzzyMatch, count_preceding_backslashes, join_strings, string_prefixes_string, + string_prefixes_string_case_insensitive, }; use crate::wildcard::wildcard_has; use crate::wutil::{fstat, perror, write_to_fd, wstat}; @@ -318,9 +318,9 @@ pub fn terminal_init(vars: &dyn Environment, inputfd: RawFd) -> InputEventQueue See 'help terminal-compatibility' or 'man fish-terminal-compatibility'. \ This %s process will no longer wait for outstanding queries, \ which disables some optional features.", - program, - INITIAL_QUERY_TIMEOUT_SECONDS, - program + program, + INITIAL_QUERY_TIMEOUT_SECONDS, + program ), ); input_queue @@ -2537,17 +2537,19 @@ fn handle_char_event(&mut self, injected_event: Option) -> ControlFlo return ControlFlow::Break(()); } - let event_needing_handling = injected_event.or_else(|| loop { - let event_needing_handling = self.read_normal_chars(); - if event_needing_handling.is_some() { - break event_needing_handling; - } - if self - .rls() - .nchars - .is_some_and(|nchars| usize::from(nchars) <= self.command_line_len()) - { - break None; + let event_needing_handling = injected_event.or_else(|| { + loop { + let event_needing_handling = self.read_normal_chars(); + if event_needing_handling.is_some() { + break event_needing_handling; + } + if self + .rls() + .nchars + .is_some_and(|nchars| usize::from(nchars) <= self.command_line_len()) + { + break None; + } } }); @@ -4559,7 +4561,13 @@ fn acquire_tty_or_exit(shell_pgid: libc::pid_t) { if check_for_orphaned_process(loop_count, shell_pgid) { // We're orphaned, so we just die. Another sad statistic. let pid = getpid(); - FLOG!(warning, sprintf!("I appear to be an orphaned process, so I am quitting politely. My pid is %d.", pid)); + FLOG!( + warning, + sprintf!( + "I appear to be an orphaned process, so I am quitting politely. My pid is %d.", + pid + ) + ); exit_without_destructors(1); } diff --git a/src/reader_history_search.rs b/src/reader_history_search.rs index 63e2a57c7..575577556 100644 --- a/src/reader_history_search.rs +++ b/src/reader_history_search.rs @@ -2,7 +2,7 @@ use crate::history::{self, History, HistorySearch, SearchDirection, SearchFlags, SearchType}; use crate::parse_constants::SourceRange; -use crate::tokenizer::{TokenType, Tokenizer, TOK_ACCEPT_UNFINISHED}; +use crate::tokenizer::{TOK_ACCEPT_UNFINISHED, TokenType, Tokenizer}; use crate::wchar::prelude::*; use crate::wcstringutil::ifind; use std::collections::HashSet; diff --git a/src/screen.rs b/src/screen.rs index 95bfda9dc..15d7f5ce5 100644 --- a/src/screen.rs +++ b/src/screen.rs @@ -7,16 +7,16 @@ //! The current implementation is less smart than ncurses allows and can not for example move blocks //! of text around to handle text insertion. +use crate::FLOG; use crate::editable_line::line_at_cursor; use crate::key::ViewportPosition; -use crate::pager::{PageRendering, Pager, PAGER_MIN_HEIGHT}; -use crate::FLOG; +use crate::pager::{PAGER_MIN_HEIGHT, PageRendering, Pager}; use std::cell::RefCell; use std::collections::LinkedList; use std::io::Write; use std::ops::Range; -use std::sync::atomic::AtomicU32; use std::sync::Mutex; +use std::sync::atomic::AtomicU32; use std::time::SystemTime; use libc::{ONLCR, STDERR_FILENO, STDOUT_FILENO}; @@ -36,8 +36,8 @@ self, ClearToEndOfLine, ClearToEndOfScreen, CursorDown, CursorLeft, CursorMove, CursorRight, CursorUp, EnterDimMode, ExitAttributeMode, Osc133PromptStart, ScrollContentUp, }; -use crate::terminal::{use_terminfo, BufferedOutputter, CardinalDirection, Output, Outputter}; -use crate::termsize::{termsize_last, Termsize}; +use crate::terminal::{BufferedOutputter, CardinalDirection, Output, Outputter, use_terminfo}; +use crate::termsize::{Termsize, termsize_last}; use crate::wchar::prelude::*; use crate::wcstringutil::{fish_wcwidth_visible, string_prefixes_string}; use crate::wutil::fstat; diff --git a/src/signal.rs b/src/signal.rs index 0c1930044..f776c633f 100644 --- a/src/signal.rs +++ b/src/signal.rs @@ -6,7 +6,7 @@ use crate::nix::getpid; use crate::reader::{reader_handle_sigint, reader_sighup, safe_restore_term_mode}; use crate::termsize::TermsizeContainer; -use crate::topic_monitor::{topic_monitor_principal, Generation, GenerationsList, Topic}; +use crate::topic_monitor::{Generation, GenerationsList, Topic, topic_monitor_principal}; use crate::tty_handoff::{safe_deactivate_tty_protocols, safe_mark_tty_invalid}; use crate::wchar::prelude::*; use crate::wutil::{fish_wcstoi, perror}; diff --git a/src/terminal.rs b/src/terminal.rs index 0f905b818..6fd6440c4 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -1,13 +1,13 @@ // Generic output functions. +use crate::FLOGF; use crate::color::{Color, Color24}; use crate::common::ToCString; -use crate::common::{self, escape_string, wcs2string, wcs2string_appending, EscapeStringStyle}; +use crate::common::{self, EscapeStringStyle, escape_string, wcs2string, wcs2string_appending}; use crate::future_feature_flags::{self, FeatureFlag}; use crate::screen::{is_dumb, only_grayscale}; use crate::text_face::{TextFace, TextStyling, UnderlineStyle}; use crate::threads::MainThread; use crate::wchar::prelude::*; -use crate::FLOGF; use bitflags::bitflags; use std::cell::{RefCell, RefMut}; use std::env; @@ -16,9 +16,9 @@ use std::os::fd::RawFd; use std::os::unix::ffi::OsStrExt; use std::path::PathBuf; -use std::sync::atomic::{AtomicU8, Ordering}; use std::sync::Arc; use std::sync::Mutex; +use std::sync::atomic::{AtomicU8, Ordering}; bitflags! { #[derive(Copy, Clone, Default)] diff --git a/src/termsize.rs b/src/termsize.rs index 701b84de1..ce2afa0bf 100644 --- a/src/termsize.rs +++ b/src/termsize.rs @@ -6,8 +6,8 @@ use crate::wchar::prelude::*; use crate::wutil::fish_wcstoi; use std::mem::MaybeUninit; -use std::sync::atomic::{AtomicBool, AtomicU32, Ordering}; use std::sync::Mutex; +use std::sync::atomic::{AtomicBool, AtomicU32, Ordering}; #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub struct Termsize { diff --git a/src/tests/abbrs.rs b/src/tests/abbrs.rs index 99936745b..7e60e8096 100644 --- a/src/tests/abbrs.rs +++ b/src/tests/abbrs.rs @@ -1,5 +1,5 @@ -use crate::abbrs::{self, abbrs_get_set, abbrs_match, Abbreviation}; -use crate::editable_line::{apply_edit, Edit}; +use crate::abbrs::{self, Abbreviation, abbrs_get_set, abbrs_match}; +use crate::editable_line::{Edit, apply_edit}; use crate::highlight::HighlightSpec; use crate::reader::reader_expand_abbreviation_at_cursor; use crate::tests::prelude::*; diff --git a/src/tests/ast.rs b/src/tests/ast.rs index 774aeb141..14d88e30b 100644 --- a/src/tests/ast.rs +++ b/src/tests/ast.rs @@ -1,4 +1,4 @@ -use crate::ast::{self, is_same_node, Node}; +use crate::ast::{self, Node, is_same_node}; use crate::wchar::prelude::*; const FISH_FUNC: &str = r#" diff --git a/src/tests/common.rs b/src/tests/common.rs index 6cd37d910..78661aeb3 100644 --- a/src/tests/common.rs +++ b/src/tests/common.rs @@ -1,4 +1,4 @@ -use crate::common::{truncate_at_nul, ScopeGuard, ScopedCell, ScopedRefCell}; +use crate::common::{ScopeGuard, ScopedCell, ScopedRefCell, truncate_at_nul}; use crate::wchar::prelude::*; #[test] diff --git a/src/tests/complete.rs b/src/tests/complete.rs index 3978254c3..9d1301ded 100644 --- a/src/tests/complete.rs +++ b/src/tests/complete.rs @@ -1,13 +1,13 @@ -use crate::abbrs::{self, with_abbrs_mut, Abbreviation}; +use crate::abbrs::{self, Abbreviation, with_abbrs_mut}; use crate::complete::{ - complete, complete_add, complete_add_wrapper, complete_get_wrap_targets, - complete_remove_wrapper, sort_and_prioritize, CompleteFlags, CompleteOptionType, - CompletionMode, CompletionRequestOptions, + CompleteFlags, CompleteOptionType, CompletionMode, CompletionRequestOptions, complete, + complete_add, complete_add_wrapper, complete_get_wrap_targets, complete_remove_wrapper, + sort_and_prioritize, }; use crate::env::{EnvMode, Environment}; use crate::io::IoChain; use crate::operation_context::{ - no_cancel, OperationContext, EXPANSION_LIMIT_BACKGROUND, EXPANSION_LIMIT_DEFAULT, + EXPANSION_LIMIT_BACKGROUND, EXPANSION_LIMIT_DEFAULT, OperationContext, no_cancel, }; use crate::reader::completion_apply_to_command_line; use crate::tests::prelude::*; @@ -323,16 +323,20 @@ macro_rules! unique_completion_applies_as { let completions = do_complete(L!("cat testfile te"), CompletionRequestOptions::default()); assert_eq!(completions.len(), 1); assert_eq!(completions[0].completion, L!("stfile")); - assert!(completions[0] - .flags - .contains(CompleteFlags::DUPLICATES_ARGUMENT)); + assert!( + completions[0] + .flags + .contains(CompleteFlags::DUPLICATES_ARGUMENT) + ); let completions = do_complete(L!("cat testfile TE"), CompletionRequestOptions::default()); assert_eq!(completions.len(), 1); assert_eq!(completions[0].completion, L!("testfile")); assert!(completions[0].flags.contains(CompleteFlags::REPLACES_TOKEN)); - assert!(completions[0] - .flags - .contains(CompleteFlags::DUPLICATES_ARGUMENT)); + assert!( + completions[0] + .flags + .contains(CompleteFlags::DUPLICATES_ARGUMENT) + ); let completions = do_complete( L!("something --abc=te"), CompletionRequestOptions::default(), diff --git a/src/tests/debounce.rs b/src/tests/debounce.rs index f36d478c6..3b21a7a8e 100644 --- a/src/tests/debounce.rs +++ b/src/tests/debounce.rs @@ -1,13 +1,13 @@ use std::sync::{ - atomic::{AtomicU32, Ordering}, Arc, Condvar, Mutex, + atomic::{AtomicU32, Ordering}, }; use std::time::Duration; use crate::global_safety::RelaxedAtomicBool; -use crate::reader::{fake_scoped_reader, Reader}; +use crate::reader::{Reader, fake_scoped_reader}; use crate::tests::prelude::*; -use crate::threads::{iothread_drain_all, iothread_service_main, Debounce}; +use crate::threads::{Debounce, iothread_drain_all, iothread_service_main}; #[test] #[serial] diff --git a/src/tests/env_universal_common.rs b/src/tests/env_universal_common.rs index 087f169be..60637ae94 100644 --- a/src/tests/env_universal_common.rs +++ b/src/tests/env_universal_common.rs @@ -1,13 +1,13 @@ +use crate::common::ENCODE_DIRECT_BASE; use crate::common::char_offset; use crate::common::wcs2osstring; -use crate::common::ENCODE_DIRECT_BASE; use crate::env::{EnvVar, EnvVarFlags, VarTable}; use crate::env_universal_common::{EnvUniversal, UvarFormat}; use crate::reader::fake_scoped_reader; use crate::tests::prelude::*; use crate::threads::{iothread_drain_all, iothread_perform}; use crate::wchar::prelude::*; -use crate::wutil::{file_id_for_path, INVALID_FILE_ID}; +use crate::wutil::{INVALID_FILE_ID, file_id_for_path}; const UVARS_PER_THREAD: usize = 8; const UVARS_TEST_PATH: &wstr = L!("test/fish_uvars_test/varsfile.txt"); diff --git a/src/tests/expand.rs b/src/tests/expand.rs index de80c71f4..66be6171f 100644 --- a/src/tests/expand.rs +++ b/src/tests/expand.rs @@ -3,18 +3,18 @@ use crate::abbrs::{with_abbrs, with_abbrs_mut}; use crate::complete::{CompletionList, CompletionReceiver}; use crate::env::{EnvMode, EnvStackSetResult}; -use crate::expand::{expand_to_receiver, ExpandResultCode}; -use crate::operation_context::{no_cancel, EXPANSION_LIMIT_DEFAULT}; +use crate::expand::{ExpandResultCode, expand_to_receiver}; +use crate::operation_context::{EXPANSION_LIMIT_DEFAULT, no_cancel}; use crate::parse_constants::ParseErrorList; use crate::tests::prelude::*; use crate::wildcard::ANY_STRING; use crate::{ - expand::{expand_string, ExpandFlags}, + expand::{ExpandFlags, expand_string}, operation_context::OperationContext, wchar::prelude::*, }; -use std::collections::hash_map::RandomState; use std::collections::HashSet; +use std::collections::hash_map::RandomState; fn expand_test_impl( input: &wstr, diff --git a/src/tests/fd_monitor.rs b/src/tests/fd_monitor.rs index bdee02c7d..0e94f3a94 100644 --- a/src/tests/fd_monitor.rs +++ b/src/tests/fd_monitor.rs @@ -14,7 +14,7 @@ use crate::fd_monitor::{FdEventSignaller, FdMonitor}; use crate::fd_readable_set::{FdReadableSet, Timeout}; -use crate::fds::{make_autoclose_pipes, AutoCloseFd, AutoClosePipes}; +use crate::fds::{AutoCloseFd, AutoClosePipes, make_autoclose_pipes}; use crate::tests::prelude::*; /// Helper to make an item which counts how many times its callback was invoked. @@ -184,11 +184,7 @@ fn do_something_bad_during_select(bad_action: F) -> Result // macOS will eagerly return EBADF if the fd is closed; Linux will hit the timeout. let timeout = Timeout::Duration(Duration::from_millis(500)); let ret = fd_set.check_readable(timeout); - if ret < 0 { - Err(errno().0) - } else { - Ok(ret) - } + if ret < 0 { Err(errno().0) } else { Ok(ret) } }); barrier.wait(); @@ -204,7 +200,7 @@ fn do_something_bad_during_select(bad_action: F) -> Result #[test] fn test_close_during_select_ebadf() { - use crate::common::{is_windows_subsystem_for_linux as is_wsl, WSL}; + use crate::common::{WSL, is_windows_subsystem_for_linux as is_wsl}; let close_it = |read_fd: OwnedFd| { drop(read_fd); None diff --git a/src/tests/history.rs b/src/tests/history.rs index 47887547e..b0d04d533 100644 --- a/src/tests/history.rs +++ b/src/tests/history.rs @@ -1,4 +1,4 @@ -use crate::common::{is_windows_subsystem_for_linux, str2wcstring, wcs2osstring, wcs2string, WSL}; +use crate::common::{WSL, is_windows_subsystem_for_linux, str2wcstring, wcs2osstring, wcs2string}; use crate::env::{EnvMode, EnvStack}; use crate::history::{ self, History, HistoryItem, HistorySearch, PathList, SearchDirection, VACUUM_FREQUENCY, @@ -10,8 +10,8 @@ use crate::wchar::prelude::*; use crate::wcstringutil::{string_prefixes_string, string_prefixes_string_case_insensitive}; use fish_build_helper::workspace_root; -use rand::rngs::SmallRng; use rand::Rng; +use rand::rngs::SmallRng; use std::collections::VecDeque; use std::ffi::CString; use std::io::BufReader; diff --git a/src/tests/input.rs b/src/tests/input.rs index ed89f755b..283223844 100644 --- a/src/tests/input.rs +++ b/src/tests/input.rs @@ -1,5 +1,5 @@ use crate::env::EnvStack; -use crate::input::{EventQueuePeeker, InputMappingSet, KeyNameStyle, DEFAULT_BIND_MODE}; +use crate::input::{DEFAULT_BIND_MODE, EventQueuePeeker, InputMappingSet, KeyNameStyle}; use crate::input_common::{CharEvent, InputData, InputEventQueuer, KeyEvent}; use crate::key::Key; use crate::wchar::prelude::*; diff --git a/src/tests/key.rs b/src/tests/key.rs index e99ee575a..4c6e4c960 100644 --- a/src/tests/key.rs +++ b/src/tests/key.rs @@ -1,4 +1,4 @@ -use crate::key::{self, ctrl, function_key, parse_keys, Key}; +use crate::key::{self, Key, ctrl, function_key, parse_keys}; use crate::wchar::prelude::*; #[test] diff --git a/src/tests/mod.rs b/src/tests/mod.rs index f2761bb67..6cddc8a29 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -29,7 +29,7 @@ mod wgetopt; pub mod prelude { - use crate::common::{ScopeGuard, ScopeGuarding, BUILD_DIR}; + use crate::common::{BUILD_DIR, ScopeGuard, ScopeGuarding}; use crate::env::{env_init, misc_init}; use crate::parser::{CancelBehavior, Parser}; use crate::reader::{reader_deinit, reader_init}; diff --git a/src/tests/parse_util.rs b/src/tests/parse_util.rs index 11da7e112..51d9a79bf 100644 --- a/src/tests/parse_util.rs +++ b/src/tests/parse_util.rs @@ -2,14 +2,14 @@ use crate::common::EscapeFlags; use crate::parse_constants::{ - ERROR_BAD_VAR_CHAR1, ERROR_BRACKETED_VARIABLE1, ERROR_BRACKETED_VARIABLE_QUOTED1, - ERROR_NOT_ARGV_AT, ERROR_NOT_ARGV_COUNT, ERROR_NOT_ARGV_STAR, ERROR_NOT_PID, ERROR_NOT_STATUS, - ERROR_NO_VAR_NAME, + ERROR_BAD_VAR_CHAR1, ERROR_BRACKETED_VARIABLE_QUOTED1, ERROR_BRACKETED_VARIABLE1, + ERROR_NO_VAR_NAME, ERROR_NOT_ARGV_AT, ERROR_NOT_ARGV_COUNT, ERROR_NOT_ARGV_STAR, ERROR_NOT_PID, + ERROR_NOT_STATUS, }; use crate::parse_util::{ - parse_util_cmdsubst_extent, parse_util_compute_indents, parse_util_detect_errors, - parse_util_escape_string_with_quote, parse_util_process_extent, parse_util_slice_length, - BOOL_AFTER_BACKGROUND_ERROR_MSG, + BOOL_AFTER_BACKGROUND_ERROR_MSG, parse_util_cmdsubst_extent, parse_util_compute_indents, + parse_util_detect_errors, parse_util_escape_string_with_quote, parse_util_process_extent, + parse_util_slice_length, }; use crate::tests::prelude::*; use crate::wchar::prelude::*; diff --git a/src/tests/parser.rs b/src/tests/parser.rs index cc08d11bd..7b1d951f7 100644 --- a/src/tests/parser.rs +++ b/src/tests/parser.rs @@ -1,11 +1,11 @@ -use crate::ast::{self, is_same_node, Ast, Castable, JobList, JobPipeline, Kind, Node, Traversal}; +use crate::ast::{self, Ast, Castable, JobList, JobPipeline, Kind, Node, Traversal, is_same_node}; use crate::env::EnvStack; use crate::expand::ExpandFlags; use crate::io::{IoBufferfill, IoChain}; use crate::parse_constants::{ ParseErrorCode, ParseTokenType, ParseTreeFlags, ParserTestErrorBits, StatementDecoration, }; -use crate::parse_tree::{parse_source, LineCounter}; +use crate::parse_tree::{LineCounter, parse_source}; use crate::parse_util::{parse_util_detect_errors, parse_util_detect_errors_in_argument}; use crate::parser::{CancelBehavior, Parser}; use crate::reader::{fake_scoped_reader, reader_reset_interrupted}; diff --git a/src/tests/reader.rs b/src/tests/reader.rs index 08584ac9b..30e619394 100644 --- a/src/tests/reader.rs +++ b/src/tests/reader.rs @@ -1,5 +1,5 @@ use crate::complete::CompleteFlags; -use crate::operation_context::{no_cancel, OperationContext}; +use crate::operation_context::{OperationContext, no_cancel}; use crate::reader::{combine_command_and_autosuggestion, completion_apply_to_command_line}; use crate::tests::prelude::*; use crate::wchar::prelude::*; diff --git a/src/tests/screen.rs b/src/tests/screen.rs index 4da65f41b..9627adbd1 100644 --- a/src/tests/screen.rs +++ b/src/tests/screen.rs @@ -1,7 +1,7 @@ use crate::common::get_ellipsis_char; use crate::highlight::HighlightSpec; use crate::parse_util::parse_util_compute_indents; -use crate::screen::{compute_layout, LayoutCache, PromptCacheEntry, PromptLayout, ScreenLayout}; +use crate::screen::{LayoutCache, PromptCacheEntry, PromptLayout, ScreenLayout, compute_layout}; use crate::tests::prelude::*; use crate::wchar::prelude::*; use crate::wcstringutil::join_strings; diff --git a/src/tests/string_escape.rs b/src/tests/string_escape.rs index 545c41d6e..5d6c53297 100644 --- a/src/tests/string_escape.rs +++ b/src/tests/string_escape.rs @@ -1,14 +1,14 @@ use std::sync::MutexGuard; use crate::common::{ - escape_string, fish_setlocale, str2wcstring, unescape_string, wcs2string, EscapeFlags, - EscapeStringStyle, UnescapeStringStyle, ENCODE_DIRECT_BASE, ENCODE_DIRECT_END, + ENCODE_DIRECT_BASE, ENCODE_DIRECT_END, EscapeFlags, EscapeStringStyle, UnescapeStringStyle, + escape_string, fish_setlocale, str2wcstring, unescape_string, wcs2string, }; use crate::locale::LOCALE_LOCK; use crate::util::{get_rng_seed, get_seeded_rng}; -use crate::wchar::{wstr, WString, L}; +use crate::wchar::{L, WString, wstr}; use crate::wutil::encoding::{ - probe_is_multibyte_locale, wcrtomb, zero_mbstate, AT_LEAST_MB_LEN_MAX, + AT_LEAST_MB_LEN_MAX, probe_is_multibyte_locale, wcrtomb, zero_mbstate, }; use rand::{Rng, RngCore}; @@ -124,7 +124,10 @@ fn escape_test(escape_style: EscapeStringStyle, unescape_style: UnescapeStringSt let slice = escaped_string.as_char_slice(); panic!("Failed to unescape string {slice:?}"); }; - assert_eq!(random_string, unescaped_string, "Escaped and then unescaped string {random_string:?}, but got back a different string {unescaped_string:?}. The intermediate escape looked like {escaped_string:?}."); + assert_eq!( + random_string, unescaped_string, + "Escaped and then unescaped string {random_string:?}, but got back a different string {unescaped_string:?}. The intermediate escape looked like {escaped_string:?}." + ); } } @@ -156,7 +159,10 @@ fn test_escape_no_printables() { panic!("Failed to unescape string <{escaped_string}>"); }; - assert_eq!(random_string, unescaped_string, "Escaped and then unescaped string '{random_string}', but got back a different string '{unescaped_string}'"); + assert_eq!( + random_string, unescaped_string, + "Escaped and then unescaped string '{random_string}', but got back a different string '{unescaped_string}'" + ); } /// The number of tests to run. diff --git a/src/tests/termsize.rs b/src/tests/termsize.rs index d7874200d..284dab8d9 100644 --- a/src/tests/termsize.rs +++ b/src/tests/termsize.rs @@ -2,8 +2,8 @@ use crate::termsize::*; use crate::tests::prelude::*; use crate::wchar::prelude::*; -use std::sync::atomic::AtomicBool; use std::sync::Mutex; +use std::sync::atomic::AtomicBool; #[test] #[serial] diff --git a/src/tests/topic_monitor.rs b/src/tests/topic_monitor.rs index 4e49544a6..06e1135ad 100644 --- a/src/tests/topic_monitor.rs +++ b/src/tests/topic_monitor.rs @@ -5,8 +5,8 @@ #[cfg(target_has_atomic = "64")] use std::sync::atomic::AtomicU64; use std::sync::{ - atomic::{AtomicU32, Ordering}, Arc, + atomic::{AtomicU32, Ordering}, }; #[test] diff --git a/src/tests/wgetopt.rs b/src/tests/wgetopt.rs index b4cf020ed..e97ffef8b 100644 --- a/src/tests/wgetopt.rs +++ b/src/tests/wgetopt.rs @@ -1,6 +1,6 @@ use crate::wchar::prelude::*; use crate::wcstringutil::join_strings; -use crate::wgetopt::{wopt, ArgType, WGetopter, WOption}; +use crate::wgetopt::{ArgType, WGetopter, WOption, wopt}; #[test] fn test_wgetopt() { diff --git a/src/text_face.rs b/src/text_face.rs index 32aaa32de..49aa09352 100644 --- a/src/text_face.rs +++ b/src/text_face.rs @@ -1,7 +1,7 @@ use crate::color::Color; use crate::terminal::{self, get_color_support}; use crate::wchar::prelude::*; -use crate::wgetopt::{wopt, ArgType, WGetopter, WOption}; +use crate::wgetopt::{ArgType, WGetopter, WOption, wopt}; trait StyleSet { fn union_prefer_right(self, other: Self) -> Self; diff --git a/src/threads.rs b/src/threads.rs index ecd9899d0..56b5178af 100644 --- a/src/threads.rs +++ b/src/threads.rs @@ -1,7 +1,7 @@ //! The rusty version of iothreads from the cpp code, to be consumed by native rust code. This isn't //! ported directly from the cpp code so we can use rust threads instead of using pthreads. -use crate::flog::{FloggableDebug, FLOG}; +use crate::flog::{FLOG, FloggableDebug}; use crate::reader::Reader; use std::marker::PhantomData; use std::mem::MaybeUninit; diff --git a/src/timer.rs b/src/timer.rs index f2ae453e1..53ab1f817 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -18,7 +18,7 @@ use std::io::Write; use std::time::{Duration, Instant}; -use crate::nix::{getrusage, RUsage}; +use crate::nix::{RUsage, getrusage}; enum Unit { Minutes, diff --git a/src/tinyexpr.rs b/src/tinyexpr.rs index 66e146047..179bf6033 100644 --- a/src/tinyexpr.rs +++ b/src/tinyexpr.rs @@ -32,7 +32,7 @@ use crate::{ wchar::prelude::*, - wutil::{wcstod::wcstod_underscores, wgettext, Error as wcstodError}, + wutil::{Error as wcstodError, wcstod::wcstod_underscores, wgettext}, }; #[derive(Clone, Copy)] @@ -196,11 +196,7 @@ fn maximum(n: &[f64]) -> f64 { if a == b { // treat +0 as larger than -0 - if a.is_sign_positive() { - a - } else { - b - } + if a.is_sign_positive() { a } else { b } } else if a > b { a } else { @@ -220,11 +216,7 @@ fn minimum(n: &[f64]) -> f64 { if a == b { // treat -0 as smaller than +0 - if a.is_sign_negative() { - a - } else { - b - } + if a.is_sign_negative() { a } else { b } } else if a < b { a } else { diff --git a/src/tokenizer.rs b/src/tokenizer.rs index f7f416530..1bedbe084 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -3,7 +3,7 @@ use crate::ast::unescape_keyword; use crate::common::valid_var_name_char; -use crate::future_feature_flags::{feature_test, FeatureFlag}; +use crate::future_feature_flags::{FeatureFlag, feature_test}; use crate::parse_constants::SOURCE_OFFSET_INVALID; use crate::parser_keywords::parser_keywords_is_subcommand; use crate::redirection::RedirectionMode; diff --git a/src/topic_monitor.rs b/src/topic_monitor.rs index 614cf6ba3..884416b7d 100644 --- a/src/topic_monitor.rs +++ b/src/topic_monitor.rs @@ -21,8 +21,8 @@ */ use crate::fd_readable_set::{FdReadableSet, Timeout}; -use crate::fds::{self, make_fd_nonblocking, AutoClosePipes}; -use crate::flog::{FloggableDebug, FLOG}; +use crate::fds::{self, AutoClosePipes, make_fd_nonblocking}; +use crate::flog::{FLOG, FloggableDebug}; use crate::wchar::WString; use crate::wutil::perror; use nix::errno::Errno; diff --git a/src/universal_notifier/kqueue.rs b/src/universal_notifier/kqueue.rs index 098b6ad13..d33e314b6 100644 --- a/src/universal_notifier/kqueue.rs +++ b/src/universal_notifier/kqueue.rs @@ -1,9 +1,9 @@ +use crate::FLOGF; use crate::common::wcs2osstring; use crate::env_universal_common::default_vars_path; use crate::universal_notifier::UniversalNotifier; use crate::wchar::prelude::*; use crate::wutil::wdirname; -use crate::FLOGF; use nix::sys::event::{EvFlags, EventFilter, FilterFlag, KEvent, Kqueue}; use std::fs::File; use std::os::fd::AsFd; diff --git a/src/util.rs b/src/util.rs index e1093a486..f31119e6a 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,7 +1,7 @@ //! Generic utilities library. use crate::wchar::prelude::*; -use rand::{rngs::SmallRng, SeedableRng}; +use rand::{SeedableRng, rngs::SmallRng}; use std::cmp::Ordering; use std::time; use std::time::{SystemTime, UNIX_EPOCH}; diff --git a/src/wchar.rs b/src/wchar.rs index 657e81f27..efcf3dc60 100644 --- a/src/wchar.rs +++ b/src/wchar.rs @@ -12,11 +12,11 @@ pub mod prelude { pub use crate::{ - wchar::{wstr, IntoCharIter, WString, L}, + wchar::{IntoCharIter, L, WString, wstr}, wchar_ext::{ToWString, WExt}, wutil::{ - eprintf, localizable_consts, localizable_string, sprintf, wgettext, wgettext_fmt, - LocalizableString, + LocalizableString, eprintf, localizable_consts, localizable_string, sprintf, wgettext, + wgettext_fmt, }, }; } diff --git a/src/wchar_ext.rs b/src/wchar_ext.rs index 89c96254d..3f8ac3a1c 100644 --- a/src/wchar_ext.rs +++ b/src/wchar_ext.rs @@ -1,9 +1,9 @@ use std::{iter, slice}; use crate::{ - common::subslice_position, - wchar::{wstr, WString}, L, + common::subslice_position, + wchar::{WString, wstr}, }; use widestring::utfstr::CharsUtf32; diff --git a/src/wcstringutil.rs b/src/wcstringutil.rs index d99f16597..dc61f30ce 100644 --- a/src/wcstringutil.rs +++ b/src/wcstringutil.rs @@ -5,7 +5,7 @@ use crate::fallback::{fish_wcwidth, wcscasecmp, wcscasecmp_fuzzy}; use crate::flog::FLOGF; use crate::wchar::{decode_byte_from_char, prelude::*}; -use crate::wutil::encoding::{wcrtomb, zero_mbstate, AT_LEAST_MB_LEN_MAX}; +use crate::wutil::encoding::{AT_LEAST_MB_LEN_MAX, wcrtomb, zero_mbstate}; /// Return the number of newlines in a string. pub fn count_newlines(s: &wstr) -> usize { @@ -96,11 +96,7 @@ pub fn ifind(haystack: &wstr, needle: &wstr, fuzzy: bool /* = false */) -> Optio .position(|window| { // In fuzzy matching treat treat `-` and `_` as equal (#3584). fn fuzzy_canonicalize(c: char) -> char { - if c == '_' { - '-' - } else { - c - } + if c == '_' { '-' } else { c } } wcscasecmp_fuzzy( diff --git a/src/wildcard.rs b/src/wildcard.rs index e96178976..9f97e9906 100644 --- a/src/wildcard.rs +++ b/src/wildcard.rs @@ -6,17 +6,17 @@ use std::fs; use crate::common::{ - char_offset, is_windows_subsystem_for_linux, unescape_string, UnescapeFlags, - UnescapeStringStyle, WILDCARD_RESERVED_BASE, WSL, + UnescapeFlags, UnescapeStringStyle, WILDCARD_RESERVED_BASE, WSL, char_offset, + is_windows_subsystem_for_linux, unescape_string, }; use crate::complete::{CompleteFlags, Completion, CompletionReceiver, PROG_COMPLETE_SEP}; use crate::expand::ExpandFlags; use crate::fallback::wcscasecmp; -use crate::future_feature_flags::feature_test; use crate::future_feature_flags::FeatureFlag; +use crate::future_feature_flags::feature_test; use crate::wchar::prelude::*; use crate::wcstringutil::{ - string_fuzzy_match_string, string_suffixes_string_case_insensitive, CaseSensitivity, + CaseSensitivity, string_fuzzy_match_string, string_suffixes_string_case_insensitive, }; use crate::wutil::dir_iter::DirEntryType; use crate::wutil::{dir_iter::DirEntry, lwstat, waccess}; @@ -437,7 +437,7 @@ mod expander { use crate::{ path::append_path_component, - wutil::{dir_iter::DirIter, normalize_path, DevInode}, + wutil::{DevInode, dir_iter::DirIter, normalize_path}, }; use super::*; diff --git a/src/wutil/dir_iter.rs b/src/wutil/dir_iter.rs index 41d3e0e2d..37bdf0b50 100644 --- a/src/wutil/dir_iter.rs +++ b/src/wutil/dir_iter.rs @@ -1,6 +1,6 @@ use super::wopendir; use crate::common::{str2wcstring, wcs2zstring}; -use crate::wchar::{wstr, WString}; +use crate::wchar::{WString, wstr}; use crate::wutil::DevInode; use cfg_if::cfg_if; use libc::{ @@ -12,7 +12,7 @@ use std::io; use std::mem::MaybeUninit; use std::os::fd::RawFd; -use std::ptr::{addr_of, NonNull}; +use std::ptr::{NonNull, addr_of}; use std::rc::Rc; /// Types of files that may be in a directory. @@ -372,7 +372,7 @@ fn test_dir_iter() { use crate::common::charptr2wcstring; use crate::common::wcs2osstring; use crate::wchar::L; - use libc::{close, mkfifo, open, symlink, O_CREAT, O_WRONLY}; + use libc::{O_CREAT, O_WRONLY, close, mkfifo, open, symlink}; use std::ffi::CString; let baditer = DirIter::new(L!("/definitely/not/a/valid/directory/for/sure")); diff --git a/src/wutil/hex_float.rs b/src/wutil/hex_float.rs index 703c0cf91..fefece087 100644 --- a/src/wutil/hex_float.rs +++ b/src/wutil/hex_float.rs @@ -222,7 +222,7 @@ pub fn parse_hex_float( #[cfg(test)] mod tests { - use super::{parse_hex_float, SyntaxError}; + use super::{SyntaxError, parse_hex_float}; // Helper to parse a float, expecting to succeed and consume the entire string. fn parse(input: &str) -> f64 { diff --git a/src/wutil/mod.rs b/src/wutil/mod.rs index 2d33f88ae..125c3568f 100644 --- a/src/wutil/mod.rs +++ b/src/wutil/mod.rs @@ -16,12 +16,12 @@ }; use crate::fallback; use crate::flog::FLOGF; -use crate::wchar::{wstr, WString, L}; +use crate::wchar::{L, WString, wstr}; use crate::wchar_ext::WExt; use crate::wcstringutil::{join_strings, wcs2string_callback}; use errno::errno; pub use gettext::{ - localizable_consts, localizable_string, wgettext, wgettext_fmt, LocalizableString, + LocalizableString, localizable_consts, localizable_string, wgettext, wgettext_fmt, }; use std::ffi::{CStr, OsStr}; use std::fs::{self, canonicalize}; @@ -31,7 +31,7 @@ pub use crate::wutil::printf::{eprintf, fprintf, printf, sprintf}; pub use fileid::{ - file_id_for_file, file_id_for_path, file_id_for_path_narrow, DevInode, FileId, INVALID_FILE_ID, + DevInode, FileId, INVALID_FILE_ID, file_id_for_file, file_id_for_path, file_id_for_path_narrow, }; pub use wcstoi::*; @@ -571,11 +571,7 @@ fn do_write(fd: RawFd, total_written: &mut usize, mut buf: &[u8]) -> bool { if success { success = flush_accum(&mut total_written, &accum, &mut accumlen); } - if success { - Some(total_written) - } else { - None - } + if success { Some(total_written) } else { None } } const PUA1_START: char = '\u{E000}'; diff --git a/src/wutil/tests.rs b/src/wutil/tests.rs index 7ac0ab701..a98530988 100644 --- a/src/wutil/tests.rs +++ b/src/wutil/tests.rs @@ -1,7 +1,7 @@ use crate::tests::prelude::*; use crate::util::get_rng; use crate::{fds::AutoCloseFd, fs::create_temporary_file}; -use libc::{c_void, O_CREAT, O_RDWR, O_TRUNC, SEEK_SET}; +use libc::{O_CREAT, O_RDWR, O_TRUNC, SEEK_SET, c_void}; use rand::Rng; use std::ffi::CString; use std::ptr; diff --git a/src/wutil/wcstod.rs b/src/wutil/wcstod.rs index 819f39ae2..036c05f7f 100644 --- a/src/wutil/wcstod.rs +++ b/src/wutil/wcstod.rs @@ -280,7 +280,7 @@ pub fn wcstod_underscores(s: Chars, consumed: &mut usize) -> Result