Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions bindgen/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 == '_')
}
Expand Down
12 changes: 4 additions & 8 deletions bindgen/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
3 changes: 1 addition & 2 deletions bindgen/codegen/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
21 changes: 9 additions & 12 deletions bindgen/ir/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions bindgen/options/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ where
}

fn add_derives(&self, info: &DeriveInfo<'_>) -> Vec<String> {
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();
Expand Down Expand Up @@ -743,7 +743,7 @@ where
}

fn add_attributes(&self, info: &AttributeInfo<'_>) -> Vec<String> {
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();
Expand Down
Loading