diff --git a/src/uu/cksum/src/cksum.rs b/src/uu/cksum/src/cksum.rs index 448f40ac4..8bbcfd836 100644 --- a/src/uu/cksum/src/cksum.rs +++ b/src/uu/cksum/src/cksum.rs @@ -27,7 +27,7 @@ const fn generate_crc_table() -> [u32; CRC_TABLE_LEN] { let mut i = 0; while i < CRC_TABLE_LEN { - table[i] = crc_entry(i as u8) as u32; + table[i] = crc_entry(i as u8); i += 1; } diff --git a/src/uu/csplit/src/csplit.rs b/src/uu/csplit/src/csplit.rs index e746acb84..bfe2f9512 100644 --- a/src/uu/csplit/src/csplit.rs +++ b/src/uu/csplit/src/csplit.rs @@ -228,7 +228,7 @@ impl<'a> SplitWriter<'a> { /// The creation of the split file may fail with some [`io::Error`]. fn new_writer(&mut self) -> io::Result<()> { let file_name = self.options.split_name.get(self.counter); - let file = File::create(&file_name)?; + let file = File::create(file_name)?; self.current_writer = Some(BufWriter::new(file)); self.counter += 1; self.size = 0; diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index e71ff21b0..555ae0ac0 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -715,7 +715,7 @@ fn calc_loop_bsize( Some(Num::Bytes(bmax)) => { let bmax: u128 = (*bmax).try_into().unwrap(); let bremain: u128 = bmax - wstat.bytes_total; - cmp::min(ideal_bsize as u128, bremain as u128) as usize + cmp::min(ideal_bsize as u128, bremain) as usize } None => ideal_bsize, } diff --git a/src/uu/dircolors/src/dircolors.rs b/src/uu/dircolors/src/dircolors.rs index 54e0db395..dcd79a7a9 100644 --- a/src/uu/dircolors/src/dircolors.rs +++ b/src/uu/dircolors/src/dircolors.rs @@ -67,7 +67,7 @@ pub fn guess_syntax() -> OutputFmt { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_ignore(); - let matches = uu_app().try_get_matches_from(&args)?; + let matches = uu_app().try_get_matches_from(args)?; let files = matches .get_many::(options::FILE) diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index 8e8664e27..f65afa32f 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -143,7 +143,7 @@ impl Stat { path, is_dir: metadata.is_dir(), size: metadata.len(), - blocks: metadata.blocks() as u64, + blocks: metadata.blocks(), inodes: 1, inode: Some(file_info), created: birth_u64(&metadata), @@ -188,7 +188,7 @@ fn birth_u64(meta: &Metadata) -> Option { meta.created() .ok() .and_then(|t| t.duration_since(UNIX_EPOCH).ok()) - .map(|e| e.as_secs() as u64) + .map(|e| e.as_secs()) } #[cfg(windows)] @@ -807,7 +807,7 @@ pub fn uu_app() -> Command { // .short('P') // .long("no-dereference") // .help("don't follow any symbolic links (this is the default)") - // .action(ArgAction::SetTrue), + // .action(ArgAction::SetTrue), // ) .arg( Arg::new(options::BLOCK_SIZE_1M) diff --git a/src/uu/factor/build.rs b/src/uu/factor/build.rs index 32640d61a..aad2aac77 100644 --- a/src/uu/factor/build.rs +++ b/src/uu/factor/build.rs @@ -37,7 +37,7 @@ mod sieve; #[cfg_attr(test, allow(dead_code))] fn main() { let out_dir = env::var("OUT_DIR").unwrap(); - let mut file = File::create(&Path::new(&out_dir).join("prime_table.rs")).unwrap(); + let mut file = File::create(Path::new(&out_dir).join("prime_table.rs")).unwrap(); // By default, we print the multiplicative inverses mod 2^64 of the first 1k primes const DEFAULT_SIZE: usize = 320; diff --git a/src/uu/fold/src/fold.rs b/src/uu/fold/src/fold.rs index 6761e4522..77ec359ef 100644 --- a/src/uu/fold/src/fold.rs +++ b/src/uu/fold/src/fold.rs @@ -274,9 +274,7 @@ fn fold_file(mut file: BufReader, spaces: bool, width: usize) -> URe last_space = if spaces { Some(output.len()) } else { None }; } '\x08' => { - if col_count > 0 { - col_count -= 1; - } + col_count = col_count.saturating_sub(1); } _ if spaces && ch.is_whitespace() => { last_space = Some(output.len()); diff --git a/src/uu/ln/src/ln.rs b/src/uu/ln/src/ln.rs index d9d20686e..6ba8a98e8 100644 --- a/src/uu/ln/src/ln.rs +++ b/src/uu/ln/src/ln.rs @@ -438,7 +438,7 @@ fn link(src: &Path, dst: &Path, settings: &Settings) -> UResult<()> { } else { source.to_path_buf() }; - fs::hard_link(&p, dst).map_err_context(|| { + fs::hard_link(p, dst).map_err_context(|| { format!( "failed to create hard link {} => {}", source.quote(), diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 9aa1a01fb..8f6de3ccd 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -2702,7 +2702,14 @@ fn file_is_executable(md: &Metadata) -> bool { // S_IXUSR -> user has execute permission // S_IXGRP -> group has execute permission // S_IXOTH -> other users have execute permission - md.mode() & ((S_IXUSR | S_IXGRP | S_IXOTH) as u32) != 0 + #[cfg(all( + not(target_os = "android"), + not(target_os = "freebsd"), + not(target_vendor = "apple") + ))] + return md.mode() & (S_IXUSR | S_IXGRP | S_IXOTH) != 0; + #[cfg(any(target_os = "android", target_os = "freebsd", target_vendor = "apple"))] + return md.mode() & ((S_IXUSR | S_IXGRP | S_IXOTH) as u32) != 0; } fn classify_file(path: &PathData, out: &mut BufWriter) -> Option { diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 3da9a09ab..d37bc06d5 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -564,7 +564,7 @@ fn rename_symlink_fallback(from: &Path, to: &Path) -> io::Result<()> { let path_symlink_points_to = fs::read_link(from)?; #[cfg(unix)] { - unix::fs::symlink(&path_symlink_points_to, to).and_then(|_| fs::remove_file(from))?; + unix::fs::symlink(path_symlink_points_to, to).and_then(|_| fs::remove_file(from))?; } #[cfg(windows)] { diff --git a/src/uu/pinky/src/pinky.rs b/src/uu/pinky/src/pinky.rs index 2dd6562fb..0647e7d37 100644 --- a/src/uu/pinky/src/pinky.rs +++ b/src/uu/pinky/src/pinky.rs @@ -279,11 +279,15 @@ impl Pinky { let last_change; match pts_path.metadata() { Ok(meta) => { - mesg = if meta.mode() & (S_IWGRP as u32) != 0 { - ' ' - } else { - '*' - }; + #[cfg(all( + not(target_os = "android"), + not(target_os = "freebsd"), + not(target_vendor = "apple") + ))] + let iwgrp = S_IWGRP; + #[cfg(any(target_os = "android", target_os = "freebsd", target_vendor = "apple"))] + let iwgrp = S_IWGRP as u32; + mesg = if meta.mode() & iwgrp != 0 { ' ' } else { '*' }; last_change = meta.atime(); } _ => { diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index 9f0570a28..965b4ba8e 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -439,7 +439,7 @@ fn get_output_chunks( ) -> (String, String, String, String) { // Chunk size logics are mostly copied from the GNU ptx source. // https://github.com/MaiZure/coreutils-8.3/blob/master/src/ptx.c#L1234 - let half_line_size = (config.line_width / 2) as usize; + let half_line_size = config.line_width / 2; let max_before_size = cmp::max(half_line_size as isize - config.gap_size as isize, 0) as usize; let max_after_size = cmp::max( half_line_size as isize @@ -500,7 +500,7 @@ fn get_output_chunks( let (tail_beg, _) = trim_idx(all_after, after_end, all_after.len()); // end = begin + max length - let tail_end = cmp::min(all_after.len(), tail_beg + max_tail_size) as usize; + let tail_end = cmp::min(all_after.len(), tail_beg + max_tail_size); // in case that falls in the middle of a word, trim away the word. let tail_end = trim_broken_word_right(all_after, tail_beg, tail_end); diff --git a/src/uu/pwd/src/pwd.rs b/src/uu/pwd/src/pwd.rs index b1e2b30ff..029ba6625 100644 --- a/src/uu/pwd/src/pwd.rs +++ b/src/uu/pwd/src/pwd.rs @@ -147,7 +147,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .map(Into::into) .unwrap_or(cwd); - println_verbatim(&cwd).map_err_context(|| "failed to print current directory".to_owned())?; + println_verbatim(cwd).map_err_context(|| "failed to print current directory".to_owned())?; Ok(()) } diff --git a/src/uu/realpath/src/realpath.rs b/src/uu/realpath/src/realpath.rs index 855da6698..7b8ac9e38 100644 --- a/src/uu/realpath/src/realpath.rs +++ b/src/uu/realpath/src/realpath.rs @@ -259,7 +259,7 @@ fn resolve_path( let abs = process_relative(abs, relative_base, relative_to); - print_verbatim(&abs)?; + print_verbatim(abs)?; stdout().write_all(&[line_ending])?; Ok(()) } diff --git a/src/uu/rm/src/rm.rs b/src/uu/rm/src/rm.rs index 56da7155c..aeb6794f7 100644 --- a/src/uu/rm/src/rm.rs +++ b/src/uu/rm/src/rm.rs @@ -520,6 +520,13 @@ fn handle_writable_directory(path: &Path, options: &Options, metadata: &Metadata let mode = metadata.permissions().mode(); // Check if directory has user write permissions // Why is S_IWUSR showing up as a u16 on macos? + #[cfg(all( + not(target_os = "android"), + not(target_vendor = "apple"), + not(target_os = "freebsd") + ))] + let user_writable = (mode & libc::S_IWUSR) != 0; + #[cfg(any(target_os = "android", target_os = "freebsd", target_vendor = "apple"))] let user_writable = (mode & (libc::S_IWUSR as u32)) != 0; if !user_writable { prompt_yes!("remove write-protected directory {}?", path.quote()) diff --git a/src/uu/split/src/split.rs b/src/uu/split/src/split.rs index 365dd279b..36200b2bd 100644 --- a/src/uu/split/src/split.rs +++ b/src/uu/split/src/split.rs @@ -1115,7 +1115,7 @@ where // of bytes per chunk. let metadata = metadata(&settings.input).unwrap(); let num_bytes = metadata.len(); - let chunk_size = (num_bytes / (num_chunks as u64)) as usize; + let chunk_size = (num_bytes / num_chunks) as usize; // This object is responsible for creating the filename for each chunk. let mut filename_iterator = FilenameIterator::new( @@ -1188,7 +1188,7 @@ where // of bytes per chunk. let metadata = metadata(&settings.input).unwrap(); let num_bytes = metadata.len(); - let chunk_size = (num_bytes / (num_chunks as u64)) as usize; + let chunk_size = (num_bytes / num_chunks) as usize; // Write to stdout instead of to a file. let stdout = std::io::stdout(); diff --git a/src/uu/sync/src/sync.rs b/src/uu/sync/src/sync.rs index 0fa81218a..d4bc1604d 100644 --- a/src/uu/sync/src/sync.rs +++ b/src/uu/sync/src/sync.rs @@ -52,7 +52,7 @@ mod platform { #[cfg(any(target_os = "linux", target_os = "android"))] pub unsafe fn do_syncfs(files: Vec) -> isize { for path in files { - let f = File::open(&path).unwrap(); + let f = File::open(path).unwrap(); let fd = f.as_raw_fd(); libc::syscall(libc::SYS_syncfs, fd); } @@ -62,7 +62,7 @@ mod platform { #[cfg(any(target_os = "linux", target_os = "android"))] pub unsafe fn do_fdatasync(files: Vec) -> isize { for path in files { - let f = File::open(&path).unwrap(); + let f = File::open(path).unwrap(); let fd = f.as_raw_fd(); libc::syscall(libc::SYS_fdatasync, fd); } diff --git a/src/uu/uptime/src/uptime.rs b/src/uu/uptime/src/uptime.rs index 567761ad9..0751cbe9d 100644 --- a/src/uu/uptime/src/uptime.rs +++ b/src/uu/uptime/src/uptime.rs @@ -160,7 +160,10 @@ fn get_uptime(boot_time: Option) -> i64 { proc_uptime.unwrap_or_else(|| match boot_time { Some(t) => { let now = Local::now().timestamp(); - let boottime = t as i64; + #[cfg(target_pointer_width = "64")] + let boottime: i64 = t; + #[cfg(not(target_pointer_width = "64"))] + let boottime: i64 = t.into(); now - boottime } None => -1, diff --git a/src/uu/who/src/who.rs b/src/uu/who/src/who.rs index 7498ec00c..85ad435e5 100644 --- a/src/uu/who/src/who.rs +++ b/src/uu/who/src/who.rs @@ -474,11 +474,15 @@ impl Who { let last_change; match p.metadata() { Ok(meta) => { - mesg = if meta.mode() & (S_IWGRP as u32) != 0 { - '+' - } else { - '-' - }; + #[cfg(all( + not(target_os = "android"), + not(target_os = "freebsd"), + not(target_vendor = "apple") + ))] + let iwgrp = S_IWGRP; + #[cfg(any(target_os = "android", target_os = "freebsd", target_vendor = "apple"))] + let iwgrp = S_IWGRP as u32; + mesg = if meta.mode() & iwgrp != 0 { '+' } else { '-' }; last_change = meta.atime(); } _ => { diff --git a/src/uu/whoami/src/whoami.rs b/src/uu/whoami/src/whoami.rs index b31b95d00..18c61e28e 100644 --- a/src/uu/whoami/src/whoami.rs +++ b/src/uu/whoami/src/whoami.rs @@ -20,7 +20,7 @@ static ABOUT: &str = "Print the current username."; pub fn uumain(args: impl uucore::Args) -> UResult<()> { uu_app().try_get_matches_from(args)?; let username = platform::get_username().map_err_context(|| "failed to get username".into())?; - println_verbatim(&username).map_err_context(|| "failed to print username".into())?; + println_verbatim(username).map_err_context(|| "failed to print username".into())?; Ok(()) } diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index 24be78c06..d5c7cbac1 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -109,15 +109,36 @@ impl FileInformation { } pub fn number_of_links(&self) -> u64 { - #[cfg(unix)] - return self.0.st_nlink as u64; + #[cfg(all( + unix, + not(target_vendor = "apple"), + not(target_os = "android"), + not(target_os = "freebsd"), + not(target_arch = "aarch64"), + target_pointer_width = "64" + ))] + return self.0.st_nlink; + #[cfg(all( + unix, + any( + target_vendor = "apple", + target_os = "android", + target_os = "freebsd", + target_arch = "aarch64", + not(target_pointer_width = "64") + ) + ))] + return self.0.st_nlink.into(); #[cfg(windows)] - return self.0.number_of_links() as u64; + return self.0.number_of_links(); } #[cfg(unix)] pub fn inode(&self) -> u64 { - self.0.st_ino as u64 + #[cfg(all(not(target_os = "freebsd"), target_pointer_width = "64"))] + return self.0.st_ino; + #[cfg(any(target_os = "freebsd", not(target_pointer_width = "64")))] + return self.0.st_ino.into(); } } diff --git a/src/uucore/src/lib/features/fsext.rs b/src/uucore/src/lib/features/fsext.rs index 61d3f8335..fcace586d 100644 --- a/src/uucore/src/lib/features/fsext.rs +++ b/src/uucore/src/lib/features/fsext.rs @@ -499,15 +499,39 @@ impl FsUsage { #[cfg(unix)] pub fn new(statvfs: StatFs) -> Self { { - Self { + #[cfg(all(not(target_os = "freebsd"), target_pointer_width = "64"))] + return Self { blocksize: statvfs.f_bsize as u64, // or `statvfs.f_frsize` ? - blocks: statvfs.f_blocks as u64, - bfree: statvfs.f_bfree as u64, - bavail: statvfs.f_bavail as u64, + blocks: statvfs.f_blocks, + bfree: statvfs.f_bfree, + bavail: statvfs.f_bavail, + bavail_top_bit_set: ((statvfs.f_bavail) & (1u64.rotate_right(1))) != 0, + files: statvfs.f_files, + ffree: statvfs.f_ffree, + }; + #[cfg(all(not(target_os = "freebsd"), not(target_pointer_width = "64")))] + return Self { + blocksize: statvfs.f_bsize as u64, // or `statvfs.f_frsize` ? + blocks: statvfs.f_blocks.into(), + bfree: statvfs.f_bfree.into(), + bavail: statvfs.f_bavail.into(), bavail_top_bit_set: ((statvfs.f_bavail as u64) & (1u64.rotate_right(1))) != 0, - files: statvfs.f_files as u64, - ffree: statvfs.f_ffree as u64, - } + files: statvfs.f_files.into(), + ffree: statvfs.f_ffree.into(), + }; + #[cfg(target_os = "freebsd")] + return Self { + blocksize: statvfs.f_bsize, // or `statvfs.f_frsize` ? + blocks: statvfs.f_blocks, + bfree: statvfs.f_bfree, + bavail: statvfs.f_bavail.try_into().unwrap(), + bavail_top_bit_set: ((std::convert::TryInto::::try_into(statvfs.f_bavail) + .unwrap()) + & (1u64.rotate_right(1))) + != 0, + files: statvfs.f_files, + ffree: statvfs.f_ffree.try_into().unwrap(), + }; } } #[cfg(not(unix))] @@ -556,7 +580,7 @@ impl FsUsage { let bytes_per_cluster = sectors_per_cluster as u64 * bytes_per_sector as u64; Self { // f_bsize File system block size. - blocksize: bytes_per_cluster as u64, + blocksize: bytes_per_cluster, // f_blocks - Total number of blocks on the file system, in units of f_frsize. // frsize = Fundamental file system block size (fragment size). blocks: total_number_of_clusters as u64, @@ -590,22 +614,60 @@ pub trait FsMeta { #[cfg(unix)] impl FsMeta for StatFs { fn block_size(&self) -> i64 { - self.f_bsize as i64 + #[cfg(all( + not(target_env = "musl"), + not(target_vendor = "apple"), + not(target_os = "android"), + not(target_os = "freebsd"), + target_pointer_width = "64" + ))] + return self.f_bsize; + #[cfg(all( + not(target_env = "musl"), + not(target_os = "freebsd"), + any( + target_vendor = "apple", + target_os = "android", + not(target_pointer_width = "64") + ) + ))] + return self.f_bsize.into(); + #[cfg(any(target_env = "musl", target_os = "freebsd"))] + return self.f_bsize.try_into().unwrap(); } fn total_blocks(&self) -> u64 { - self.f_blocks as u64 + #[cfg(target_pointer_width = "64")] + return self.f_blocks; + #[cfg(not(target_pointer_width = "64"))] + return self.f_blocks.into(); } fn free_blocks(&self) -> u64 { - self.f_bfree as u64 + #[cfg(target_pointer_width = "64")] + return self.f_bfree; + #[cfg(not(target_pointer_width = "64"))] + return self.f_bfree.into(); } fn avail_blocks(&self) -> u64 { - self.f_bavail as u64 + #[cfg(all(not(target_os = "freebsd"), target_pointer_width = "64"))] + return self.f_bavail; + #[cfg(all(not(target_os = "freebsd"), not(target_pointer_width = "64")))] + return self.f_bavail.into(); + #[cfg(target_os = "freebsd")] + return self.f_bavail.try_into().unwrap(); } fn total_file_nodes(&self) -> u64 { - self.f_files as u64 + #[cfg(target_pointer_width = "64")] + return self.f_files; + #[cfg(not(target_pointer_width = "64"))] + return self.f_files.into(); } fn free_file_nodes(&self) -> u64 { - self.f_ffree as u64 + #[cfg(all(not(target_os = "freebsd"), target_pointer_width = "64"))] + return self.f_ffree; + #[cfg(all(not(target_os = "freebsd"), not(target_pointer_width = "64")))] + return self.f_ffree.into(); + #[cfg(target_os = "freebsd")] + return self.f_ffree.try_into().unwrap(); } #[cfg(any( target_os = "linux", @@ -614,7 +676,26 @@ impl FsMeta for StatFs { target_os = "freebsd" ))] fn fs_type(&self) -> i64 { - self.f_type as i64 + #[cfg(all( + not(target_env = "musl"), + not(target_vendor = "apple"), + not(target_os = "android"), + not(target_os = "freebsd"), + target_pointer_width = "64" + ))] + return self.f_type; + #[cfg(all( + not(target_env = "musl"), + any( + target_vendor = "apple", + target_os = "android", + target_os = "freebsd", + not(target_pointer_width = "64") + ) + ))] + return self.f_type.into(); + #[cfg(target_env = "musl")] + return self.f_type.try_into().unwrap(); } #[cfg(not(any( target_os = "linux", @@ -633,7 +714,10 @@ impl FsMeta for StatFs { } #[cfg(any(target_vendor = "apple", target_os = "freebsd", target_os = "netbsd"))] fn io_size(&self) -> u64 { - self.f_iosize as u64 + #[cfg(target_os = "freebsd")] + return self.f_iosize; + #[cfg(not(target_os = "freebsd"))] + return self.f_iosize as u64; } // XXX: dunno if this is right #[cfg(not(any( diff --git a/src/uucore/src/lib/features/mode.rs b/src/uucore/src/lib/features/mode.rs index bf11e481a..c27464363 100644 --- a/src/uucore/src/lib/features/mode.rs +++ b/src/uucore/src/lib/features/mode.rs @@ -51,7 +51,7 @@ pub fn parse_symbolic( mode = &mode[pos..]; let (mut srwx, pos) = parse_change(mode, fperm, considering_dir); if respect_umask { - srwx &= !(umask as u32); + srwx &= !umask; } mode = &mode[pos..]; match op { @@ -132,12 +132,20 @@ fn parse_change(mode: &str, fperm: u32, considering_dir: bool) -> (u32, usize) { } pub fn parse_mode(mode: &str) -> Result { + #[cfg(all( + not(target_os = "freebsd"), + not(target_vendor = "apple"), + not(target_os = "android") + ))] let fperm = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; + #[cfg(any(target_os = "freebsd", target_vendor = "apple", target_os = "android"))] + let fperm = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) as u32; + let arr: &[char] = &['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; let result = if mode.contains(arr) { - parse_numeric(fperm as u32, mode, true) + parse_numeric(fperm, mode, true) } else { - parse_symbolic(fperm as u32, mode, get_umask(), true) + parse_symbolic(fperm, mode, get_umask(), true) }; result.map(|mode| mode as mode_t) } @@ -152,7 +160,14 @@ pub fn get_umask() -> u32 { // possible but it can't violate Rust's guarantees. let mask = unsafe { umask(0) }; unsafe { umask(mask) }; - mask as u32 + #[cfg(all( + not(target_os = "freebsd"), + not(target_vendor = "apple"), + not(target_os = "android") + ))] + return mask; + #[cfg(any(target_os = "freebsd", target_vendor = "apple", target_os = "android"))] + return mask.into(); } // Iterate 'args' and delete the first occurrence diff --git a/src/uucore/src/lib/features/tokenize/num_format/num_format.rs b/src/uucore/src/lib/features/tokenize/num_format/num_format.rs index c8486e792..e313fe19b 100644 --- a/src/uucore/src/lib/features/tokenize/num_format/num_format.rs +++ b/src/uucore/src/lib/features/tokenize/num_format/num_format.rs @@ -61,11 +61,11 @@ fn get_provided(str_in_opt: Option<&String>) -> Option { if !ignored.is_empty() { warn_char_constant_ign(&ignored); } - second_byte as u8 + second_byte } // no byte after quote None => { - let so_far = (ch as u8 as char).to_string(); + let so_far = (ch as char).to_string(); warn_expected_numeric(&so_far); 0_u8 } diff --git a/src/uucore/src/lib/features/tokenize/sub.rs b/src/uucore/src/lib/features/tokenize/sub.rs index eadd5263e..00fd51efd 100644 --- a/src/uucore/src/lib/features/tokenize/sub.rs +++ b/src/uucore/src/lib/features/tokenize/sub.rs @@ -195,7 +195,7 @@ impl SubParser { // into min_width, second_field, field_char for ch in it { self.text_so_far.push(ch); - match ch as char { + match ch { '-' | '*' | '0'..='9' => { if !self.past_decimal { if self.min_width_is_asterisk || self.specifiers_found { @@ -421,7 +421,7 @@ impl Sub { "{}", match field.min_width { Some(min_width) => { - let diff: isize = min_width.abs() as isize - pre_min_width.len() as isize; + let diff: isize = min_width.abs() - pre_min_width.len() as isize; if diff > 0 { let mut final_str = String::new(); // definitely more efficient ways diff --git a/src/uucore/src/lib/features/tokenize/unescaped_text.rs b/src/uucore/src/lib/features/tokenize/unescaped_text.rs index b1ab53fa1..59624f143 100644 --- a/src/uucore/src/lib/features/tokenize/unescaped_text.rs +++ b/src/uucore/src/lib/features/tokenize/unescaped_text.rs @@ -217,7 +217,7 @@ impl UnescapedText { if !addchar { addchar = true; } - match ch as char { + match ch { x if x != '\\' && x != '%' => { // lazy branch eval // remember this fn could be called diff --git a/src/uucore/src/lib/features/utmpx.rs b/src/uucore/src/lib/features/utmpx.rs index 8875e3489..b31aadc25 100644 --- a/src/uucore/src/lib/features/utmpx.rs +++ b/src/uucore/src/lib/features/utmpx.rs @@ -51,6 +51,9 @@ pub use libc::getutxent; pub use libc::setutxent; #[cfg(any(target_vendor = "apple", target_os = "linux", target_os = "netbsd"))] pub use libc::utmpxname; + +/// # Safety +/// Just fixed the clippy warning. Please add description here. #[cfg(target_os = "freebsd")] pub unsafe extern "C" fn utmpxname(_file: *const libc::c_char) -> libc::c_int { 0 @@ -165,11 +168,11 @@ pub struct Utmpx { impl Utmpx { /// A.K.A. ut.ut_type pub fn record_type(&self) -> i16 { - self.inner.ut_type as i16 + self.inner.ut_type } /// A.K.A. ut.ut_pid pub fn pid(&self) -> i32 { - self.inner.ut_pid as i32 + self.inner.ut_pid } /// A.K.A. ut.ut_id pub fn terminal_suffix(&self) -> String { @@ -189,9 +192,14 @@ impl Utmpx { } /// A.K.A. ut.ut_tv pub fn login_time(&self) -> time::OffsetDateTime { + #[cfg(all(not(target_os = "freebsd"), not(target_vendor = "apple")))] let ts_nanos: i128 = (self.inner.ut_tv.tv_sec as i64 * 1_000_000_000_i64 + self.inner.ut_tv.tv_usec as i64 * 1_000_i64) .into(); + #[cfg(any(target_os = "freebsd", target_vendor = "apple"))] + let ts_nanos: i128 = (self.inner.ut_tv.tv_sec * 1_000_000_000_i64 + + self.inner.ut_tv.tv_usec as i64 * 1_000_i64) + .into(); let local_offset = time::OffsetDateTime::now_local().unwrap().offset(); time::OffsetDateTime::from_unix_timestamp_nanos(ts_nanos) .unwrap() diff --git a/src/uucore/src/lib/macros.rs b/src/uucore/src/lib/macros.rs index 612160e19..cc8bdafd8 100644 --- a/src/uucore/src/lib/macros.rs +++ b/src/uucore/src/lib/macros.rs @@ -41,7 +41,7 @@ use std::sync::atomic::AtomicBool; // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -/// Whether we were called as a multicall binary ("coreutils ") +/// Whether we were called as a multicall binary (`coreutils `) pub static UTILITY_IS_SECOND_ARG: AtomicBool = AtomicBool::new(false); //====