Skip to content

Commit c2acff2

Browse files
xtqqczzecakebaker
authored andcommitted
1 parent ff6b2ef commit c2acff2

22 files changed

Lines changed: 77 additions & 61 deletions

File tree

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,6 @@ ignored_unit_patterns = "allow" # 21
748748
similar_names = "allow" # 20
749749
needless_pass_by_value = "allow" # 16
750750
float_cmp = "allow" # 12
751-
items_after_statements = "allow" # 11
752751
return_self_not_must_use = "allow" # 8
753752
inline_always = "allow" # 6
754753
fn_params_excessive_bools = "allow" # 6

src/bin/uudoc.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ use std::{
1616
use clap::{Arg, Command};
1717
use clap_complete::Shell;
1818
use clap_mangen::Man;
19-
use fluent_syntax::ast::{Entry, Message, Pattern};
20-
use fluent_syntax::parser;
19+
use fluent_syntax::{
20+
ast::{
21+
Entry, Expression, InlineExpression, Message, Pattern,
22+
PatternElement::{Placeable, TextElement},
23+
},
24+
parser,
25+
};
2126
use jiff::Zoned;
2227
use regex::Regex;
2328
use textwrap::{fill, indent, termwidth};
@@ -447,10 +452,6 @@ impl MDWriter<'_, '_> {
447452
if id.name == key {
448453
// Simple text extraction - just concatenate text elements
449454
let mut result = String::new();
450-
use fluent_syntax::ast::{
451-
Expression, InlineExpression,
452-
PatternElement::{Placeable, TextElement},
453-
};
454455
for element in elements {
455456
if let TextElement { ref value } = element {
456457
result.push_str(value);

src/uu/chcon/src/chcon.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,8 @@ fn change_file_context(
627627
context: &SELinuxSecurityContext,
628628
path: &Path,
629629
) -> Result<()> {
630+
type SetValueProc = fn(&OpaqueSecurityContext, &CStr) -> selinux::errors::Result<()>;
631+
630632
match &options.mode {
631633
CommandLineMode::Custom {
632634
user,
@@ -673,8 +675,6 @@ fn change_file_context(
673675
Error::from_io1(translate!("chcon-op-creating-security-context"), path, err)
674676
})?;
675677

676-
type SetValueProc = fn(&OpaqueSecurityContext, &CStr) -> selinux::errors::Result<()>;
677-
678678
let list: &[(&Option<OsString>, SetValueProc)] = &[
679679
(user, OpaqueSecurityContext::set_user),
680680
(role, OpaqueSecurityContext::set_role),

src/uu/cksum/src/cksum.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ use uucore::translate;
2222
/// 2>/dev/full does not abort
2323
/// This matches GNU cksum's --debug behavior
2424
fn print_cpu_debug_info() {
25-
let features = SimdPolicy::detect();
26-
2725
fn print_feature(name: &str, available: bool) {
2826
if available {
2927
let _ = writeln!(stderr(), "using {name} hardware support");
@@ -32,6 +30,8 @@ fn print_cpu_debug_info() {
3230
}
3331
}
3432

33+
let features = SimdPolicy::detect();
34+
3535
// x86/x86_64
3636
print_feature("avx512", features.has_avx512());
3737
print_feature("avx2", features.has_avx2());

src/uu/cp/src/cp.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2384,8 +2384,7 @@ fn calculate_dest_permissions(
23842384
let mode = handle_no_preserve_mode(options, permissions.mode());
23852385

23862386
// Apply umask
2387-
use uucore::mode::get_umask;
2388-
let mode = mode & !get_umask();
2387+
let mode = mode & !uucore::mode::get_umask();
23892388
permissions.set_mode(mode);
23902389
permissions
23912390
}

src/uu/df/src/table.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,6 @@ mod tests {
950950

951951
#[test]
952952
fn test_row_formatter_with_round_up_byte_values() {
953-
init();
954953
fn get_formatted_values(bytes: u64, bytes_used: u64, bytes_avail: u64) -> Vec<Cell> {
955954
let options = Options {
956955
block_size: BlockSize::Bytes(1000),
@@ -967,6 +966,8 @@ mod tests {
967966
RowFormatter::new(&row, &options, false).get_cells()
968967
}
969968

969+
init();
970+
970971
assert!(compare_cell_content(
971972
get_formatted_values(100, 100, 0),
972973
vec!("1", "1", "0")

src/uu/du/src/du.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,10 @@ fn safe_du(
426426
};
427427

428428
'file_loop: for entry_name in entries {
429+
const S_IFMT: u32 = 0o170_000;
430+
const S_IFDIR: u32 = 0o040_000;
431+
const S_IFLNK: u32 = 0o120_000;
432+
429433
// First get the lstat (without following symlinks) to check if it's a symlink
430434
let lstat = match dir_fd.stat_at(&entry_name, SymlinkBehavior::NoFollow) {
431435
Ok(stat) => stat,
@@ -439,9 +443,6 @@ fn safe_du(
439443
};
440444

441445
// Check if it's a symlink
442-
const S_IFMT: u32 = 0o170_000;
443-
const S_IFDIR: u32 = 0o040_000;
444-
const S_IFLNK: u32 = 0o120_000;
445446
#[allow(clippy::unnecessary_cast)]
446447
let is_symlink = (lstat.st_mode as u32 & S_IFMT) == S_IFLNK;
447448

@@ -575,11 +576,12 @@ fn du_regular(
575576
ancestors: Option<&mut HashSet<FileInfo>>,
576577
symlink_depth: Option<usize>,
577578
) -> Result<Stat, Box<mpsc::SendError<UResult<StatPrintInfo>>>> {
579+
// Maximum symlink depth to prevent infinite loops
580+
const MAX_SYMLINK_DEPTH: usize = 40;
581+
578582
let mut default_ancestors = HashSet::default();
579583
let ancestors = ancestors.unwrap_or(&mut default_ancestors);
580584
let symlink_depth = symlink_depth.unwrap_or(0);
581-
// Maximum symlink depth to prevent infinite loops
582-
const MAX_SYMLINK_DEPTH: usize = 40;
583585

584586
// Add current directory to ancestors if it's a directory
585587
let my_inode = if my_stat.metadata.is_dir() {

src/uu/expr/src/syntax_tree.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,9 @@ fn check_posix_regex_errors(pattern: &str) -> ExprResult<()> {
268268
/// Build a regex from a pattern string with locale-aware encoding
269269
fn build_regex(pattern_bytes: Vec<u8>) -> ExprResult<(Regex, String)> {
270270
use onig::EncodedBytes;
271-
use uucore::i18n::{UEncoding, get_locale_encoding};
271+
use uucore::i18n::UEncoding;
272272

273-
let encoding = get_locale_encoding();
273+
let encoding = uucore::i18n::get_locale_encoding();
274274

275275
// For pattern processing, we need to handle it based on locale
276276
let pattern_str = String::from_utf8(pattern_bytes.clone())
@@ -388,9 +388,9 @@ fn regex_search<T: onig::EncodedChars>(
388388
/// Find matches in the input using the compiled regex
389389
fn find_match(regex: Regex, re_string: String, left_bytes: Vec<u8>) -> String {
390390
use onig::EncodedBytes;
391-
use uucore::i18n::{UEncoding, get_locale_encoding};
391+
use uucore::i18n::UEncoding;
392392

393-
let encoding = get_locale_encoding();
393+
let encoding = uucore::i18n::get_locale_encoding();
394394

395395
// Match against the input using the appropriate encoding
396396
let mut region = onig::Region::new();
@@ -506,11 +506,12 @@ fn find_match(regex: Regex, re_string: String, left_bytes: Vec<u8>) -> String {
506506

507507
/// Evaluate a match expression with locale-aware regex matching
508508
fn evaluate_match_expression(left_bytes: Vec<u8>, right_bytes: Vec<u8>) -> ExprResult<NumOrStr> {
509+
use uucore::i18n::UEncoding;
510+
509511
let (regex, re_string) = build_regex(right_bytes)?;
510512

511513
// Special case for ASCII locale with capture groups that need to return raw bytes
512-
use uucore::i18n::{UEncoding, get_locale_encoding};
513-
let encoding = get_locale_encoding();
514+
let encoding = uucore::i18n::get_locale_encoding();
514515

515516
if matches!(encoding, UEncoding::Ascii) && regex.captures_len() > 0 {
516517
// Try to find the actual capture bytes for ASCII locale

src/uu/mknod/src/mknod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,28 +98,30 @@ fn mknod(file_name: &str, config: Config) -> i32 {
9898
// Apply SELinux context if requested
9999
#[cfg(feature = "selinux")]
100100
if config.set_security_context {
101+
use std::io::Write as _;
102+
101103
if let Err(e) = uucore::selinux::set_selinux_security_context(
102104
std::path::Path::new(file_name),
103105
config.context.as_ref(),
104106
) {
105107
// if it fails, delete the file
106108
let _ = std::fs::remove_file(file_name);
107-
use std::io::{Write, stderr};
108-
let _ = writeln!(stderr(), "mknod: {e}");
109+
let _ = writeln!(std::io::stderr(), "mknod: {e}");
109110
return 1;
110111
}
111112
}
112113

113114
// Apply SMACK context if requested
114115
#[cfg(feature = "smack")]
115116
if config.set_security_context {
117+
use std::io::Write as _;
118+
116119
if let Err(e) =
117120
uucore::smack::set_smack_label_and_cleanup(file_name, config.context.as_ref(), |p| {
118121
std::fs::remove_file(p)
119122
})
120123
{
121-
use std::io::{Write, stderr};
122-
let _ = writeln!(stderr(), "mknod: {e}");
124+
let _ = writeln!(std::io::stderr(), "mknod: {e}");
123125
return 1;
124126
}
125127
}

src/uu/sort/src/chunks.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ fn parse_lines<'a>(
269269
separator: u8,
270270
settings: &GlobalSettings,
271271
) {
272+
const SMALL_CHUNK_BYTES: usize = 64 * 1024;
273+
272274
let read = read.strip_suffix(&[separator]).unwrap_or(read);
273275

274276
assert!(lines.is_empty());
@@ -279,7 +281,6 @@ fn parse_lines<'a>(
279281
assert!(line_data.collation_key_buffer.is_empty());
280282
assert!(line_data.collation_key_ends.is_empty());
281283
token_buffer.clear();
282-
const SMALL_CHUNK_BYTES: usize = 64 * 1024;
283284
let mut estimated = (*line_count_hint).max(1);
284285
let mut exact_line_count = None;
285286
if *line_count_hint == 0 || read.len() <= SMALL_CHUNK_BYTES {

0 commit comments

Comments
 (0)