mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
Merge pull request #4238 from Joining7943/fix-cargo-clippy-doc-warnings
cargo: Fix cargo clippy doc warnings
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
+1
-1
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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::<String>(options::FILE)
|
||||
|
||||
+3
-3
@@ -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<u64> {
|
||||
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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -274,9 +274,7 @@ fn fold_file<T: Read>(mut file: BufReader<T>, 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());
|
||||
|
||||
+1
-1
@@ -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(),
|
||||
|
||||
+2
-1
@@ -2702,7 +2702,8 @@ 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
|
||||
#[allow(clippy::unnecessary_cast)]
|
||||
return md.mode() & ((S_IXUSR | S_IXGRP | S_IXOTH) as u32) != 0;
|
||||
}
|
||||
|
||||
fn classify_file(path: &PathData, out: &mut BufWriter<Stdout>) -> Option<char> {
|
||||
|
||||
+1
-1
@@ -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)]
|
||||
{
|
||||
|
||||
@@ -277,9 +277,11 @@ impl Pinky {
|
||||
|
||||
let mesg;
|
||||
let last_change;
|
||||
|
||||
match pts_path.metadata() {
|
||||
#[allow(clippy::unnecessary_cast)]
|
||||
Ok(meta) => {
|
||||
mesg = if meta.mode() & (S_IWGRP as u32) != 0 {
|
||||
mesg = if meta.mode() & S_IWGRP as u32 != 0 {
|
||||
' '
|
||||
} else {
|
||||
'*'
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
@@ -520,6 +520,7 @@ 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?
|
||||
#[allow(clippy::unnecessary_cast)]
|
||||
let user_writable = (mode & (libc::S_IWUSR as u32)) != 0;
|
||||
if !user_writable {
|
||||
prompt_yes!("remove write-protected directory {}?", path.quote())
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -52,7 +52,7 @@ mod platform {
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
pub unsafe fn do_syncfs(files: Vec<String>) -> 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<String>) -> 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);
|
||||
}
|
||||
|
||||
@@ -160,7 +160,10 @@ fn get_uptime(boot_time: Option<time_t>) -> 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,
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
_ => {
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user