Skip to content

Commit 0173bbd

Browse files
partial rustfmt
1 parent 5813198 commit 0173bbd

File tree

4 files changed

+118
-117
lines changed

4 files changed

+118
-117
lines changed

bindgen/clang.rs

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,10 @@ impl Cursor {
246246
pub(crate) fn is_toplevel(&self) -> bool {
247247
let mut semantic_parent = self.fallible_semantic_parent();
248248

249-
while semantic_parent.is_some() &&
250-
(semantic_parent.unwrap().kind() == CXCursor_Namespace ||
251-
semantic_parent.unwrap().kind() ==
252-
CXCursor_NamespaceAlias ||
253-
semantic_parent.unwrap().kind() == CXCursor_NamespaceRef)
249+
while semantic_parent.is_some()
250+
&& (semantic_parent.unwrap().kind() == CXCursor_Namespace
251+
|| semantic_parent.unwrap().kind() == CXCursor_NamespaceAlias
252+
|| semantic_parent.unwrap().kind() == CXCursor_NamespaceRef)
254253
{
255254
semantic_parent =
256255
semantic_parent.unwrap().fallible_semantic_parent();
@@ -267,9 +266,9 @@ impl Cursor {
267266
pub(crate) fn is_template_like(&self) -> bool {
268267
matches!(
269268
self.kind(),
270-
CXCursor_ClassTemplate |
271-
CXCursor_ClassTemplatePartialSpecialization |
272-
CXCursor_TypeAliasTemplateDecl
269+
CXCursor_ClassTemplate
270+
| CXCursor_ClassTemplatePartialSpecialization
271+
| CXCursor_TypeAliasTemplateDecl
273272
)
274273
}
275274

@@ -296,9 +295,9 @@ impl Cursor {
296295
/// Is the referent a fully specialized template specialization without any
297296
/// remaining free template arguments?
298297
pub(crate) fn is_fully_specialized_template(&self) -> bool {
299-
self.is_template_specialization() &&
300-
self.kind() != CXCursor_ClassTemplatePartialSpecialization &&
301-
self.num_template_args().unwrap_or(0) > 0
298+
self.is_template_specialization()
299+
&& self.kind() != CXCursor_ClassTemplatePartialSpecialization
300+
&& self.num_template_args().unwrap_or(0) > 0
302301
}
303302

304303
/// Is the referent a template specialization that still has remaining free
@@ -324,9 +323,9 @@ impl Cursor {
324323
pub(crate) fn is_template_parameter(&self) -> bool {
325324
matches!(
326325
self.kind(),
327-
CXCursor_TemplateTemplateParameter |
328-
CXCursor_TemplateTypeParameter |
329-
CXCursor_NonTypeTemplateParameter
326+
CXCursor_TemplateTemplateParameter
327+
| CXCursor_TemplateTypeParameter
328+
| CXCursor_NonTypeTemplateParameter
330329
)
331330
}
332331

@@ -664,9 +663,9 @@ impl Cursor {
664663
// inline function without a definition, and it's not a defaulted
665664
// function, we can reasonably safely conclude that it's a deleted
666665
// function.
667-
self.is_inlined_function() &&
668-
self.definition().is_none() &&
669-
!self.is_defaulted_function()
666+
self.is_inlined_function()
667+
&& self.definition().is_none()
668+
&& !self.is_defaulted_function()
670669
}
671670

672671
/// Is the referent a bit field declaration?
@@ -788,11 +787,11 @@ impl Cursor {
788787
let found_attr = &mut found_attrs[idx];
789788
if !*found_attr {
790789
// `attr.name` and` attr.token_kind` are checked against unexposed attributes only.
791-
if attr.kind == Some(kind) ||
792-
(kind == CXCursor_UnexposedAttr &&
793-
cur.tokens().iter().any(|t| {
794-
t.kind == attr.token_kind &&
795-
t.spelling() == attr.name
790+
if attr.kind == Some(kind)
791+
|| (kind == CXCursor_UnexposedAttr
792+
&& cur.tokens().iter().any(|t| {
793+
t.kind == attr.token_kind
794+
&& t.spelling() == attr.name
796795
}))
797796
{
798797
*found_attr = true;
@@ -1408,12 +1407,12 @@ impl Type {
14081407
/// to.
14091408
pub(crate) fn pointee_type(&self) -> Option<Type> {
14101409
match self.kind() {
1411-
CXType_Pointer |
1412-
CXType_RValueReference |
1413-
CXType_LValueReference |
1414-
CXType_MemberPointer |
1415-
CXType_BlockPointer |
1416-
CXType_ObjCObjectPointer => {
1410+
CXType_Pointer
1411+
| CXType_RValueReference
1412+
| CXType_LValueReference
1413+
| CXType_MemberPointer
1414+
| CXType_BlockPointer
1415+
| CXType_ObjCObjectPointer => {
14171416
let ret = Type {
14181417
x: unsafe { clang_getPointeeType(self.x) },
14191418
};
@@ -1516,12 +1515,12 @@ impl Type {
15161515
// Yep, the spelling of this containing type-parameter is extremely
15171516
// nasty... But can happen in <type_traits>. Unfortunately I couldn't
15181517
// reduce it enough :(
1519-
self.template_args().is_some_and(|args| args.len() > 0) &&
1520-
!matches!(
1518+
self.template_args().is_some_and(|args| args.len() > 0)
1519+
&& !matches!(
15211520
self.declaration().kind(),
1522-
CXCursor_ClassTemplatePartialSpecialization |
1523-
CXCursor_TypeAliasTemplateDecl |
1524-
CXCursor_TemplateTemplateParameter
1521+
CXCursor_ClassTemplatePartialSpecialization
1522+
| CXCursor_TypeAliasTemplateDecl
1523+
| CXCursor_TemplateTemplateParameter
15251524
)
15261525
}
15271526

@@ -1546,9 +1545,9 @@ impl Type {
15461545
.is_match(spelling.as_ref())
15471546
}
15481547

1549-
self.kind() == CXType_Unexposed &&
1550-
(hacky_parse_associated_type(self.spelling()) ||
1551-
hacky_parse_associated_type(
1548+
self.kind() == CXType_Unexposed
1549+
&& (hacky_parse_associated_type(self.spelling())
1550+
|| hacky_parse_associated_type(
15521551
self.canonical_type().spelling(),
15531552
))
15541553
}

bindgen/ir/context.rs

Lines changed: 68 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,9 @@ where
252252
T: Copy + Into<ItemId>,
253253
{
254254
fn can_derive_partialord(&self, ctx: &BindgenContext) -> bool {
255-
ctx.options().derive_partialord &&
256-
ctx.lookup_can_derive_partialeq_or_partialord(*self) ==
257-
CanDerive::Yes
255+
ctx.options().derive_partialord
256+
&& ctx.lookup_can_derive_partialeq_or_partialord(*self)
257+
== CanDerive::Yes
258258
}
259259
}
260260

@@ -263,9 +263,9 @@ where
263263
T: Copy + Into<ItemId>,
264264
{
265265
fn can_derive_partialeq(&self, ctx: &BindgenContext) -> bool {
266-
ctx.options().derive_partialeq &&
267-
ctx.lookup_can_derive_partialeq_or_partialord(*self) ==
268-
CanDerive::Yes
266+
ctx.options().derive_partialeq
267+
&& ctx.lookup_can_derive_partialeq_or_partialord(*self)
268+
== CanDerive::Yes
269269
}
270270
}
271271

@@ -274,10 +274,10 @@ where
274274
T: Copy + Into<ItemId>,
275275
{
276276
fn can_derive_eq(&self, ctx: &BindgenContext) -> bool {
277-
ctx.options().derive_eq &&
278-
ctx.lookup_can_derive_partialeq_or_partialord(*self) ==
279-
CanDerive::Yes &&
280-
!ctx.lookup_has_float(*self)
277+
ctx.options().derive_eq
278+
&& ctx.lookup_can_derive_partialeq_or_partialord(*self)
279+
== CanDerive::Yes
280+
&& !ctx.lookup_has_float(*self)
281281
}
282282
}
283283

@@ -286,10 +286,10 @@ where
286286
T: Copy + Into<ItemId>,
287287
{
288288
fn can_derive_ord(&self, ctx: &BindgenContext) -> bool {
289-
ctx.options().derive_ord &&
290-
ctx.lookup_can_derive_partialeq_or_partialord(*self) ==
291-
CanDerive::Yes &&
292-
!ctx.lookup_has_float(*self)
289+
ctx.options().derive_ord
290+
&& ctx.lookup_can_derive_partialeq_or_partialord(*self)
291+
== CanDerive::Yes
292+
&& !ctx.lookup_has_float(*self)
293293
}
294294
}
295295

@@ -353,7 +353,7 @@ pub(crate) struct BindgenContext {
353353
/// hard errors while parsing duplicated macros, as well to allow macro
354354
/// expression parsing.
355355
///
356-
/// This needs to be an `std::HashMap` because the `cexpr` API requires it.
356+
/// This needs to be an `std::HashMap` because the [`cexpr`] API requires it.
357357
parsed_macros: StdHashMap<Vec<u8>, cexpr::expr::EvalResult>,
358358

359359
/// A map with all include locations.
@@ -702,11 +702,11 @@ If you encounter an error missing from this list, please file an issue or a PR!"
702702
) {
703703
debug!("BindgenContext::add_item({item:?}, declaration: {declaration:?}, loc: {location:?}");
704704
debug_assert!(
705-
declaration.is_some() ||
706-
!item.kind().is_type() ||
707-
item.kind().expect_type().is_builtin_or_type_param() ||
708-
item.kind().expect_type().is_opaque(self, &item) ||
709-
item.kind().expect_type().is_unresolved_ref(),
705+
declaration.is_some()
706+
|| !item.kind().is_type()
707+
|| item.kind().expect_type().is_builtin_or_type_param()
708+
|| item.kind().expect_type().is_opaque(self, &item)
709+
|| item.kind().expect_type().is_unresolved_ref(),
710710
"Adding a type without declaration?"
711711
);
712712

@@ -1067,10 +1067,10 @@ If you encounter an error missing from this list, please file an issue or a PR!"
10671067
};
10681068

10691069
match *ty.kind() {
1070-
TypeKind::Comp(..) |
1071-
TypeKind::TemplateAlias(..) |
1072-
TypeKind::Enum(..) |
1073-
TypeKind::Alias(..) => {}
1070+
TypeKind::Comp(..)
1071+
| TypeKind::TemplateAlias(..)
1072+
| TypeKind::Enum(..)
1073+
| TypeKind::Alias(..) => {}
10741074
_ => continue,
10751075
}
10761076

@@ -1665,9 +1665,9 @@ If you encounter an error missing from this list, please file an issue or a PR!"
16651665

16661666
for child in children.iter().rev() {
16671667
match child.kind() {
1668-
clang_sys::CXCursor_TypeRef |
1669-
clang_sys::CXCursor_TypedefDecl |
1670-
clang_sys::CXCursor_TypeAliasDecl => {
1668+
clang_sys::CXCursor_TypeRef
1669+
| clang_sys::CXCursor_TypedefDecl
1670+
| clang_sys::CXCursor_TypeAliasDecl => {
16711671
// The `with_id` ID will potentially end up unused if we give up
16721672
// on this type (for example, because it has const value
16731673
// template args), so if we pass `with_id` as the parent, it is
@@ -1691,8 +1691,8 @@ If you encounter an error missing from this list, please file an issue or a PR!"
16911691
child,
16921692
)?;
16931693

1694-
if num_expected_template_args == 0 ||
1695-
child.has_at_least_num_children(
1694+
if num_expected_template_args == 0
1695+
|| child.has_at_least_num_children(
16961696
num_expected_template_args,
16971697
)
16981698
{
@@ -1864,8 +1864,8 @@ If you encounter an error missing from this list, please file an issue or a PR!"
18641864
// * we have already parsed and resolved this type, and
18651865
// there's nothing left to do.
18661866
if let Some(location) = location {
1867-
if decl.cursor().is_template_like() &&
1868-
*ty != decl.cursor().cur_type()
1867+
if decl.cursor().is_template_like()
1868+
&& *ty != decl.cursor().cur_type()
18691869
{
18701870
// For specialized type aliases, there's no way to get the
18711871
// template parameters as of this writing (for a struct
@@ -1877,10 +1877,10 @@ If you encounter an error missing from this list, please file an issue or a PR!"
18771877
// exposed.
18781878
//
18791879
// This is _tricky_, I know :(
1880-
if decl.cursor().kind() ==
1881-
CXCursor_TypeAliasTemplateDecl &&
1882-
!location.contains_cursor(CXCursor_TypeRef) &&
1883-
ty.canonical_type().is_valid_and_exposed()
1880+
if decl.cursor().kind()
1881+
== CXCursor_TypeAliasTemplateDecl
1882+
&& !location.contains_cursor(CXCursor_TypeRef)
1883+
&& ty.canonical_type().is_valid_and_exposed()
18841884
{
18851885
return None;
18861886
}
@@ -2129,6 +2129,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
21292129
}
21302130

21312131
/// Get the currently parsed macros.
2132+
/// This map only contains macros accepted by [`cexpr`]
21322133
pub(crate) fn parsed_macros(
21332134
&self,
21342135
) -> &StdHashMap<Vec<u8>, cexpr::expr::EvalResult> {
@@ -2376,9 +2377,9 @@ If you encounter an error missing from this list, please file an issue or a PR!"
23762377
/// Is the given type a type from <stdint.h> that corresponds to a Rust primitive type?
23772378
pub(crate) fn is_stdint_type(&self, name: &str) -> bool {
23782379
match name {
2379-
"int8_t" | "uint8_t" | "int16_t" | "uint16_t" | "int32_t" |
2380-
"uint32_t" | "int64_t" | "uint64_t" | "uintptr_t" |
2381-
"intptr_t" | "ptrdiff_t" => true,
2380+
"int8_t" | "uint8_t" | "int16_t" | "uint16_t" | "int32_t"
2381+
| "uint32_t" | "int64_t" | "uint64_t" | "uintptr_t"
2382+
| "intptr_t" | "ptrdiff_t" => true,
23822383
"size_t" | "ssize_t" => self.options.size_t_is_usize,
23832384
_ => false,
23842385
}
@@ -2406,11 +2407,11 @@ If you encounter an error missing from this list, please file an issue or a PR!"
24062407
.filter(|&(_, item)| {
24072408
// If nothing is explicitly allowlisted, then everything is fair
24082409
// game.
2409-
if self.options().allowlisted_types.is_empty() &&
2410-
self.options().allowlisted_functions.is_empty() &&
2411-
self.options().allowlisted_vars.is_empty() &&
2412-
self.options().allowlisted_files.is_empty() &&
2413-
self.options().allowlisted_items.is_empty()
2410+
if self.options().allowlisted_types.is_empty()
2411+
&& self.options().allowlisted_functions.is_empty()
2412+
&& self.options().allowlisted_vars.is_empty()
2413+
&& self.options().allowlisted_files.is_empty()
2414+
&& self.options().allowlisted_items.is_empty()
24142415
{
24152416
return true;
24162417
}
@@ -2463,19 +2464,19 @@ If you encounter an error missing from this list, please file an issue or a PR!"
24632464
// make the #[derive] analysis not be lame.
24642465
if !self.options().allowlist_recursively {
24652466
match *ty.kind() {
2466-
TypeKind::Void |
2467-
TypeKind::NullPtr |
2468-
TypeKind::Int(..) |
2469-
TypeKind::Float(..) |
2470-
TypeKind::Complex(..) |
2471-
TypeKind::Array(..) |
2472-
TypeKind::Vector(..) |
2473-
TypeKind::Pointer(..) |
2474-
TypeKind::Reference(..) |
2475-
TypeKind::Function(..) |
2476-
TypeKind::ResolvedTypeRef(..) |
2477-
TypeKind::Opaque |
2478-
TypeKind::TypeParam => return true,
2467+
TypeKind::Void
2468+
| TypeKind::NullPtr
2469+
| TypeKind::Int(..)
2470+
| TypeKind::Float(..)
2471+
| TypeKind::Complex(..)
2472+
| TypeKind::Array(..)
2473+
| TypeKind::Vector(..)
2474+
| TypeKind::Pointer(..)
2475+
| TypeKind::Reference(..)
2476+
| TypeKind::Function(..)
2477+
| TypeKind::ResolvedTypeRef(..)
2478+
| TypeKind::Opaque
2479+
| TypeKind::TypeParam => return true,
24792480
_ => {}
24802481
}
24812482
if self.is_stdint_type(&name) {
@@ -2793,9 +2794,9 @@ If you encounter an error missing from this list, please file an issue or a PR!"
27932794
fn compute_cannot_derive_partialord_partialeq_or_eq(&mut self) {
27942795
let _t = self.timer("compute_cannot_derive_partialord_partialeq_or_eq");
27952796
assert!(self.cannot_derive_partialeq_or_partialord.is_none());
2796-
if self.options.derive_partialord ||
2797-
self.options.derive_partialeq ||
2798-
self.options.derive_eq
2797+
if self.options.derive_partialord
2798+
|| self.options.derive_partialeq
2799+
|| self.options.derive_eq
27992800
{
28002801
self.cannot_derive_partialeq_or_partialord =
28012802
Some(analyze::<CannotDerive>((
@@ -2842,8 +2843,8 @@ If you encounter an error missing from this list, please file an issue or a PR!"
28422843
// derive `Copy` or not.
28432844
let id = id.into();
28442845

2845-
!self.lookup_has_type_param_in_array(id) &&
2846-
!self.cannot_derive_copy.as_ref().unwrap().contains(&id)
2846+
!self.lookup_has_type_param_in_array(id)
2847+
&& !self.cannot_derive_copy.as_ref().unwrap().contains(&id)
28472848
}
28482849

28492850
/// Compute whether the type has type parameter in array.
@@ -3070,15 +3071,15 @@ impl TemplateParameters for PartialType {
30703071
// Wouldn't it be nice if libclang would reliably give us this
30713072
// information‽
30723073
match self.decl().kind() {
3073-
clang_sys::CXCursor_ClassTemplate |
3074-
clang_sys::CXCursor_FunctionTemplate |
3075-
clang_sys::CXCursor_TypeAliasTemplateDecl => {
3074+
clang_sys::CXCursor_ClassTemplate
3075+
| clang_sys::CXCursor_FunctionTemplate
3076+
| clang_sys::CXCursor_TypeAliasTemplateDecl => {
30763077
let mut num_params = 0;
30773078
self.decl().visit(|c| {
30783079
match c.kind() {
3079-
clang_sys::CXCursor_TemplateTypeParameter |
3080-
clang_sys::CXCursor_TemplateTemplateParameter |
3081-
clang_sys::CXCursor_NonTypeTemplateParameter => {
3080+
clang_sys::CXCursor_TemplateTypeParameter
3081+
| clang_sys::CXCursor_TemplateTemplateParameter
3082+
| clang_sys::CXCursor_NonTypeTemplateParameter => {
30823083
num_params += 1;
30833084
}
30843085
_ => {}

0 commit comments

Comments
 (0)