Skip to content

Commit ca4d656

Browse files
committed
all: Use let-chains in Windows/Mac-specific code
1 parent 1c713f6 commit ca4d656

3 files changed

Lines changed: 24 additions & 25 deletions

File tree

src/uu/ls/src/ls.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3398,11 +3398,11 @@ fn calculate_padding_collection(
33983398
};
33993399

34003400
for item in items {
3401-
if config.alloc_size {
3402-
if let Some(md) = item.get_metadata(&mut state.out) {
3403-
let block_size_len = display_size(get_block_size(md, config), config).len();
3404-
padding_collections.block_size = block_size_len.max(padding_collections.block_size);
3405-
}
3401+
if config.alloc_size
3402+
&& let Some(md) = item.get_metadata(&mut state.out)
3403+
{
3404+
let block_size_len = display_size(get_block_size(md, config), config).len();
3405+
padding_collections.block_size = block_size_len.max(padding_collections.block_size);
34063406
}
34073407

34083408
let context_len = item.security_context.len();

src/uu/tail/src/tail.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,16 @@ fn tail_stdin(
213213
// on macOS and Linux.
214214
#[cfg(target_os = "macos")]
215215
{
216-
if let Ok(mut stdin_handle) = Handle::stdin() {
217-
if let Ok(meta) = stdin_handle.as_file_mut().metadata() {
218-
if meta.file_type().is_dir() {
219-
set_exit_code(1);
220-
show_error!(
221-
"{}",
222-
translate!("tail-error-cannot-open-no-such-file", "file" => input.display_name.clone(), "error" => translate!("tail-no-such-file-or-directory"))
223-
);
224-
return Ok(());
225-
}
226-
}
216+
if let Ok(mut stdin_handle) = Handle::stdin()
217+
&& let Ok(meta) = stdin_handle.as_file_mut().metadata()
218+
&& meta.file_type().is_dir()
219+
{
220+
set_exit_code(1);
221+
show_error!(
222+
"{}",
223+
translate!("tail-error-cannot-open-no-such-file", "file" => input.display_name.clone(), "error" => translate!("tail-no-such-file-or-directory"))
224+
);
225+
return Ok(());
227226
}
228227
}
229228

src/uu/wc/src/count_fast.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,15 @@ pub(crate) fn count_bytes_fast<T: WordCountable>(handle: &mut T) -> (usize, Opti
171171

172172
#[cfg(windows)]
173173
{
174-
if let Some(file) = handle.inner_file() {
175-
if let Ok(metadata) = file.metadata() {
176-
let attributes = metadata.file_attributes();
177-
178-
if (attributes & FILE_ATTRIBUTE_ARCHIVE) != 0
179-
|| (attributes & FILE_ATTRIBUTE_NORMAL) != 0
180-
{
181-
return (metadata.file_size() as usize, None);
182-
}
174+
if let Some(file) = handle.inner_file()
175+
&& let Ok(metadata) = file.metadata()
176+
{
177+
let attributes = metadata.file_attributes();
178+
179+
if (attributes & FILE_ATTRIBUTE_ARCHIVE) != 0
180+
|| (attributes & FILE_ATTRIBUTE_NORMAL) != 0
181+
{
182+
return (metadata.file_size() as usize, None);
183183
}
184184
}
185185
}

0 commit comments

Comments
 (0)