diff --git a/bindgen/clang.rs b/bindgen/clang.rs index bca4a80978..830f8a9248 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -1112,10 +1112,8 @@ impl Iterator for ClangTokenIterator<'_> { /// (including '_') and does not start with a digit. pub(crate) fn is_valid_identifier(name: &str) -> bool { let mut chars = name.chars(); - let first_valid = chars - .next() - .map(|c| c.is_alphabetic() || c == '_') - .unwrap_or(false); + let first_valid = + chars.next().is_some_and(|c| c.is_alphabetic() || c == '_'); first_valid && chars.all(|c| c.is_alphanumeric() || c == '_') } diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index c58237c17b..eb73167e06 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -5145,14 +5145,10 @@ pub(crate) mod utils { return Ok(()); } - let path = context - .options() - .wrap_static_fns_path - .as_ref() - .map(PathBuf::from) - .unwrap_or_else(|| { - std::env::temp_dir().join("bindgen").join("extern") - }); + let path = context.options().wrap_static_fns_path.as_ref().map_or_else( + || std::env::temp_dir().join("bindgen").join("extern"), + PathBuf::from, + ); let dir = path.parent().unwrap(); diff --git a/bindgen/codegen/serialize.rs b/bindgen/codegen/serialize.rs index 864d86b452..9a2176c4b0 100644 --- a/bindgen/codegen/serialize.rs +++ b/bindgen/codegen/serialize.rs @@ -14,8 +14,7 @@ use super::{CodegenError, WrapAsVariadic}; fn get_loc(item: &Item) -> String { item.location() - .map(|x| x.to_string()) - .unwrap_or_else(|| "unknown".to_owned()) + .map_or_else(|| "unknown".to_owned(), |x| x.to_string()) } pub(super) trait CSerialize<'a> { diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index ee0fdc525b..6c65fc36ed 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -786,16 +786,14 @@ impl Item { match *self.kind() { ItemKind::Var(ref var) => var.name().to_owned(), - ItemKind::Module(ref module) => { - module.name().map(ToOwned::to_owned).unwrap_or_else(|| { - format!("_bindgen_mod_{}", self.exposed_id(ctx)) - }) - } - ItemKind::Type(ref ty) => { - ty.sanitized_name(ctx).map(Into::into).unwrap_or_else(|| { - format!("_bindgen_ty_{}", self.exposed_id(ctx)) - }) - } + ItemKind::Module(ref module) => module.name().map_or_else( + || format!("_bindgen_mod_{}", self.exposed_id(ctx)), + ToOwned::to_owned, + ), + ItemKind::Type(ref ty) => ty.sanitized_name(ctx).map_or_else( + || format!("_bindgen_ty_{}", self.exposed_id(ctx)), + Into::into, + ), ItemKind::Function(ref fun) => { let mut name = fun.name().to_owned(); @@ -1702,8 +1700,7 @@ impl Item { ty.spelling() ); Item::type_param(Some(id), location, ctx) - .map(Ok) - .unwrap_or(Err(ParseError::Recurse)) + .ok_or(ParseError::Recurse) } else { result } diff --git a/bindgen/options/cli.rs b/bindgen/options/cli.rs index 834c7c7625..dc4267cd69 100644 --- a/bindgen/options/cli.rs +++ b/bindgen/options/cli.rs @@ -703,7 +703,7 @@ where } fn add_derives(&self, info: &DeriveInfo<'_>) -> Vec { - if self.kind.map(|kind| kind == info.kind).unwrap_or(true) && + if self.kind.map_or(true, |kind| kind == info.kind) && self.regex_set.matches(info.name) { return self.derives.clone(); @@ -743,7 +743,7 @@ where } fn add_attributes(&self, info: &AttributeInfo<'_>) -> Vec { - if self.kind.map(|kind| kind == info.kind).unwrap_or(true) && + if self.kind.map_or(true, |kind| kind == info.kind) && self.regex_set.matches(info.name) { return self.attributes.clone();