Skip to content

Commit 8a5d54f

Browse files
committed
Rework autocxx extensions based on clippy
1 parent d4ae2ad commit 8a5d54f

File tree

2 files changed

+76
-38
lines changed

2 files changed

+76
-38
lines changed

bindgen/codegen/mod.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ impl CodeGenerator for Type {
924924
// on our layout if converting the inner item fails.
925925
let (mut inner_ty, _) = inner_item
926926
.try_to_rust_ty_or_opaque(ctx, &())
927-
.map(|ty| ty.to_outer_type())
927+
.map(|ty| ty.into_outer_type())
928928
.unwrap_or_else(|_| {
929929
(self.to_opaque(ctx, item), RustTyAnnotation::None)
930930
});
@@ -1435,7 +1435,7 @@ impl<'a> FieldCodegen<'a> for FieldData {
14351435
self.ty().into_resolver().through_type_refs().resolve(ctx);
14361436
let field_ty = field_item.expect_type();
14371437
let ty = self.ty().to_rust_ty_or_opaque(ctx, &());
1438-
let (mut ty, ty_annotations) = ty.to_outer_type();
1438+
let (mut ty, ty_annotations) = ty.into_outer_type();
14391439
ty.append_implicit_template_params(ctx, field_item);
14401440

14411441
// NB: If supported, we use proper `union` types.
@@ -3983,11 +3983,11 @@ impl RustTy {
39833983

39843984
// Use when this is an inner type and will become part of an outer type.
39853985
// Pass the annotation into [wraps]
3986-
fn to_outer_type(self) -> (proc_macro2::TokenStream, RustTyAnnotation) {
3986+
fn into_outer_type(self) -> (proc_macro2::TokenStream, RustTyAnnotation) {
39873987
(self.ts, self.annotation)
39883988
}
39893989

3990-
fn to_unannotated_ts(self) -> error::Result<proc_macro2::TokenStream> {
3990+
fn into_unannotated_ts(self) -> error::Result<proc_macro2::TokenStream> {
39913991
if matches!(self.annotation, RustTyAnnotation::None) {
39923992
Ok(self.ts)
39933993
} else {
@@ -4095,7 +4095,7 @@ impl TryToRustTy for Type {
40954095
// sizeof(NonZero<_>) optimization with opaque blobs (because
40964096
// they aren't NonZero), so don't *ever* use an or_opaque
40974097
// variant here.
4098-
let ty = fs.try_to_rust_ty(ctx, &())?.to_unannotated_ts()?;
4098+
let ty = fs.try_to_rust_ty(ctx, &())?.into_unannotated_ts()?;
40994099

41004100
let prefix = ctx.trait_prefix();
41014101
Ok(quote! {
@@ -4104,7 +4104,8 @@ impl TryToRustTy for Type {
41044104
.into())
41054105
}
41064106
TypeKind::Array(item, len) | TypeKind::Vector(item, len) => {
4107-
let ty = item.try_to_rust_ty(ctx, &())?.to_unannotated_ts()?;
4107+
let ty =
4108+
item.try_to_rust_ty(ctx, &())?.into_unannotated_ts()?;
41084109
Ok(quote! {
41094110
[ #ty ; #len ]
41104111
}
@@ -4148,7 +4149,7 @@ impl TryToRustTy for Type {
41484149
if info.has_non_type_template_params() ||
41494150
(item.is_opaque(ctx, &()) && !template_params.is_empty())
41504151
{
4151-
return Ok(self.try_to_opaque(ctx, item)?);
4152+
return self.try_to_opaque(ctx, item);
41524153
}
41534154

41544155
Ok(utils::build_path(item, ctx)?.into())
@@ -4172,7 +4173,7 @@ impl TryToRustTy for Type {
41724173
// should always generate a proper pointer here, so use
41734174
// infallible conversion of the inner type.
41744175
let (mut ty, inner_annotations) =
4175-
inner.to_rust_ty_or_opaque(ctx, &()).to_outer_type();
4176+
inner.to_rust_ty_or_opaque(ctx, &()).into_outer_type();
41764177
ty.append_implicit_template_params(ctx, inner);
41774178

41784179
// Avoid the first function pointer level, since it's already
@@ -4287,7 +4288,7 @@ impl TryToRustTy for TemplateInstantiation {
42874288
.map(|(arg, _)| {
42884289
let arg = arg.into_resolver().through_type_refs().resolve(ctx);
42894290
let mut ty =
4290-
arg.try_to_rust_ty(ctx, &())?.to_unannotated_ts()?;
4291+
arg.try_to_rust_ty(ctx, &())?.into_unannotated_ts()?;
42914292
ty.append_implicit_template_params(ctx, arg);
42924293
Ok(ty)
42934294
})
@@ -5492,7 +5493,7 @@ pub(crate) mod utils {
54925493
} else {
54935494
t.to_rust_ty_or_opaque(ctx, &())
54945495
};
5495-
let (inner_ty, annotations) = rust_ty.to_outer_type();
5496+
let (inner_ty, annotations) = rust_ty.into_outer_type();
54965497
RustTy::wraps(
54975498
inner_ty.to_ptr(ctx.resolve_type(t).is_const()),
54985499
annotations,

bindgen/ir/function.rs

Lines changed: 65 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,55 @@ impl From<CX_CXXAccessSpecifier> for Visibility {
9292
}
9393
}
9494

95+
/// Autocxx specialized function information
96+
#[derive(Debug)]
97+
pub(crate) struct AutocxxFuncInfo {
98+
/// C++ Special member kind, if applicable
99+
special_member: Option<SpecialMemberKind>,
100+
/// Whether it is private
101+
visibility: Visibility,
102+
/// =delete
103+
is_deleted: bool,
104+
/// =default
105+
is_defaulted: bool,
106+
}
107+
108+
impl AutocxxFuncInfo {
109+
fn new(
110+
special_member: Option<SpecialMemberKind>,
111+
visibility: Visibility,
112+
is_deleted: bool,
113+
is_defaulted: bool,
114+
) -> Self {
115+
Self {
116+
special_member,
117+
visibility,
118+
is_deleted,
119+
is_defaulted,
120+
}
121+
}
122+
123+
/// Get this function's C++ special member kind.
124+
pub fn special_member(&self) -> Option<SpecialMemberKind> {
125+
self.special_member
126+
}
127+
128+
/// Whether it is private
129+
pub fn visibility(&self) -> Visibility {
130+
self.visibility
131+
}
132+
133+
/// Whether this is a function that's been deleted (=delete)
134+
pub fn deleted_fn(&self) -> bool {
135+
self.is_deleted
136+
}
137+
138+
/// Whether this is a function that's been deleted (=default)
139+
pub fn defaulted_fn(&self) -> bool {
140+
self.is_defaulted
141+
}
142+
}
143+
95144
/// A function declaration, with a signature, arguments, and argument names.
96145
///
97146
/// The argument names vector must be the same length as the ones in the
@@ -116,17 +165,8 @@ pub(crate) struct Function {
116165
/// The linkage of the function.
117166
linkage: Linkage,
118167

119-
/// C++ special member kind, if any.
120-
special_member: Option<SpecialMemberKind>,
121-
122-
/// C++ visibility
123-
visibility: Visibility,
124-
125-
/// Whether it's deleted (=delete)
126-
is_deleted: bool,
127-
128-
/// Whether it's explicitly defaulted (=default)
129-
is_defaulted: bool,
168+
/// Autocxx extension information
169+
autocxx: AutocxxFuncInfo,
130170
}
131171

132172
impl Function {
@@ -138,10 +178,7 @@ impl Function {
138178
signature: TypeId,
139179
kind: FunctionKind,
140180
linkage: Linkage,
141-
special_member: Option<SpecialMemberKind>,
142-
visibility: Visibility,
143-
is_deleted: bool,
144-
is_defaulted: bool,
181+
autocxx: AutocxxFuncInfo,
145182
) -> Self {
146183
Function {
147184
name,
@@ -150,10 +187,7 @@ impl Function {
150187
signature,
151188
kind,
152189
linkage,
153-
special_member,
154-
visibility,
155-
is_deleted,
156-
is_defaulted,
190+
autocxx,
157191
}
158192
}
159193

@@ -189,22 +223,22 @@ impl Function {
189223

190224
/// Get this function's C++ special member kind.
191225
pub fn special_member(&self) -> Option<SpecialMemberKind> {
192-
self.special_member
226+
self.autocxx.special_member()
193227
}
194228

195229
/// Whether it is private
196230
pub fn visibility(&self) -> Visibility {
197-
self.visibility
231+
self.autocxx.visibility()
198232
}
199233

200234
/// Whether this is a function that's been deleted (=delete)
201235
pub fn deleted_fn(&self) -> bool {
202-
self.is_deleted
236+
self.autocxx.deleted_fn()
203237
}
204238

205-
/// Whether this is a function that's been deleted (=delete)
239+
/// Whether this is a function that's been deleted (=default)
206240
pub fn defaulted_fn(&self) -> bool {
207-
self.is_defaulted
241+
self.autocxx.defaulted_fn()
208242
}
209243
}
210244

@@ -840,17 +874,20 @@ impl ClangSubItemParser for Function {
840874
}
841875
});
842876

877+
let autocxx_info = AutocxxFuncInfo::new(
878+
special_member,
879+
visibility,
880+
cursor.is_deleted_function(),
881+
cursor.is_defaulted_function(),
882+
);
843883
let function = Self::new(
844884
name,
845885
mangled_name,
846886
link_name,
847887
sig,
848888
kind,
849889
linkage,
850-
special_member,
851-
visibility,
852-
cursor.is_deleted_function(),
853-
cursor.is_defaulted_function(),
890+
autocxx_info,
854891
);
855892

856893
Ok(ParseResult::New(function, Some(cursor)))

0 commit comments

Comments
 (0)