clippy: fix map_unwrap_or lint (#9678)
Some checks are pending
CICD / Style/cargo-deny (push) Waiting to run
CICD / Style/deps (push) Waiting to run
CICD / Test all features separately (push) Blocked by required conditions
CICD / Build/nightly (push) Blocked by required conditions
CICD / Binary sizes (push) Blocked by required conditions
CICD / Build (push) Blocked by required conditions
CICD / Separate Builds (push) Waiting to run
CICD / Build/stable (push) Blocked by required conditions
CICD / Documentation/warnings (push) Waiting to run
CICD / MinRustV (push) Waiting to run
CICD / Dependencies (push) Waiting to run
CICD / Build/Makefile (push) Blocked by required conditions
CICD / Tests/BusyBox test suite (push) Blocked by required conditions
CICD / Tests/Toybox test suite (push) Blocked by required conditions
CICD / Code Coverage (push) Waiting to run
CICD / Build/SELinux (push) Blocked by required conditions
CICD / Build/SELinux-Stubs (Non-Linux) (push) Blocked by required conditions
CICD / Safe Traversal Security Check (push) Blocked by required conditions
GnuTests / Run GNU tests (native) (push) Waiting to run
GnuTests / Run GNU tests (SELinux) (push) Waiting to run
GnuTests / Aggregate GNU test results (push) Blocked by required conditions
Android / Test builds (push) Waiting to run
Benchmarks / Run benchmarks (CodSpeed) (push) Waiting to run
Code Quality / Style/format (push) Waiting to run
Code Quality / Style/lint (push) Waiting to run
Code Quality / Style/spelling (push) Waiting to run
Code Quality / Style/toml (push) Waiting to run
Code Quality / Style/Python (push) Waiting to run
Code Quality / Pre-commit hooks (push) Waiting to run
Devcontainer / Verify devcontainer (push) Waiting to run
Check uudoc Documentation Generation / Verify uudoc generates correct documentation (push) Waiting to run
FreeBSD / Style and Lint (push) Waiting to run
FreeBSD / Tests (push) Waiting to run
OpenBSD / Style and Lint (push) Waiting to run
OpenBSD / Tests (push) Waiting to run
WSL2 / Test (push) Waiting to run

https://rust-lang.github.io/rust-clippy/master/index.html#map_unwrap_or
This commit is contained in:
xtqqczze 2025-12-17 07:24:04 +00:00 committed by GitHub
parent a33c9445f9
commit 2000af835a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 6 additions and 12 deletions

View file

@ -666,7 +666,6 @@ should_panic_without_expect = "allow" # 2
doc_markdown = "allow"
unused_self = "allow"
map_unwrap_or = "allow"
enum_glob_use = "allow"
ptr_cast_constness = "allow"
borrow_as_ptr = "allow"

View file

@ -2319,8 +2319,7 @@ fn copy_file(
let initial_dest_metadata = dest.symlink_metadata().ok();
let dest_is_symlink = initial_dest_metadata
.as_ref()
.map(|md| md.file_type().is_symlink())
.unwrap_or(false);
.is_some_and(|md| md.file_type().is_symlink());
let dest_target_exists = dest.try_exists().unwrap_or(false);
// Fail if dest is a dangling symlink or a symlink this program created previously
if dest_is_symlink {

View file

@ -443,7 +443,7 @@ fn process_utf8_line<W: Write>(line: &str, ctx: &mut FoldContext<'_, W>) -> URes
}
}
let next_idx = iter.peek().map(|(idx, _)| *idx).unwrap_or(line_bytes.len());
let next_idx = iter.peek().map_or(line_bytes.len(), |(idx, _)| *idx);
if ch == '\n' {
*ctx.last_space = None;

View file

@ -479,8 +479,7 @@ fn extract_sort(options: &clap::ArgMatches) -> Sort {
let sort_index = options
.get_one::<String>(options::SORT)
.and_then(|_| options.indices_of(options::SORT))
.map(|mut indices| indices.next_back().unwrap_or(0))
.unwrap_or(0);
.map_or(0, |mut indices| indices.next_back().unwrap_or(0));
let time_index = get_last_index(options::sort::TIME);
let size_index = get_last_index(options::sort::SIZE);
let none_index = get_last_index(options::sort::NONE);
@ -599,8 +598,7 @@ fn extract_color(options: &clap::ArgMatches) -> bool {
let color_index = options
.get_one::<String>(options::COLOR)
.and_then(|_| options.indices_of(options::COLOR))
.map(|mut indices| indices.next_back().unwrap_or(0))
.unwrap_or(0);
.map_or(0, |mut indices| indices.next_back().unwrap_or(0));
let unsorted_all_index = get_last_index(options::files::UNSORTED_ALL);
let color_enabled = match options.get_one::<String>(options::COLOR) {

View file

@ -240,8 +240,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
use std::os::unix::process::ExitStatusExt;
let signal_msg = status
.signal()
.map(|s| s.to_string())
.unwrap_or_else(|| "unknown".to_string());
.map_or_else(|| "unknown".to_string(), |s| s.to_string());
Err(USimpleError::new(
1,
translate!("stdbuf-error-killed-by-signal", "signal" => signal_msg),

View file

@ -264,8 +264,7 @@ fn create_english_bundle_from_embedded(
fn get_message_internal(id: &str, args: Option<FluentArgs>) -> String {
LOCALIZER.with(|lock| {
lock.get()
.map(|loc| loc.format(id, args.as_ref()))
.unwrap_or_else(|| id.to_string()) // Return the key ID if localizer not initialized
.map_or_else(|| id.to_string(), |loc| loc.format(id, args.as_ref())) // Return the key ID if localizer not initialized
})
}