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
29 changes: 20 additions & 9 deletions Cargo.lock
Comment thread
emilio marked this conversation as resolved.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ quote = "1"
heck = "0.5"

[dependencies.syn]
version = "2.0.85"
version = "3.0"
default-features = false
features = ["clone-impls", "extra-traits", "fold", "full", "parsing", "printing"]

Expand Down
21 changes: 13 additions & 8 deletions src/bindgen/ir/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,21 @@ trait SynFnArgHelpers {
fn gen_self_type(receiver: &syn::Receiver) -> Result<Type, String> {
let mut self_ty = Type::Path(GenericPath::self_path());

// Custom self type
if receiver.colon_token.is_some() {
self_ty = Type::load(receiver.ty.as_ref())?.unwrap_or(self_ty);
}
let is_const = match &receiver.kind {
syn::ReceiverKind::Reference(_, _, mut_token) => mut_token.is_none(),
// Custom self type
syn::ReceiverKind::Typed(_, ty) => {
self_ty = Type::load(ty)?.unwrap_or(self_ty);

if receiver.reference.is_none() {
return Ok(self_ty);
}
match &**ty {
syn::Type::Reference(ref_ty) => ref_ty.mutability.is_none(),
_ => return Ok(self_ty),
Comment thread
emilio marked this conversation as resolved.
}
}
syn::ReceiverKind::Value => return Ok(self_ty),
_ => return Err(String::from("Receiver is of an unsupported kind")),
};

let is_const = receiver.mutability.is_none();
Ok(Type::Ptr {
ty: Box::new(self_ty),
is_const,
Expand Down
4 changes: 2 additions & 2 deletions src/bindgen/ir/generic_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl GenericParam {
ref default,
..
}) => {
let default = match default.as_ref().map(Type::load).transpose()? {
let default = match default.as_ref().map(|(_, ty)| Type::load(ty)).transpose()? {
None => None,
Some(None) => Some(GenericArgument::Type(Type::Primitive(PrimitiveType::Void))),
Some(Some(ty)) => Some(GenericArgument::Type(ty)),
Expand Down Expand Up @@ -69,7 +69,7 @@ impl GenericParam {
ty: GenericParamType::Const(ty),
default: default
.as_ref()
.map(ConstExpr::load)
.map(|(_, ty)| ConstExpr::load(ty))
.transpose()?
.map(GenericArgument::Const),
})),
Expand Down
4 changes: 2 additions & 2 deletions src/bindgen/ir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ impl Type {
None => Type::Primitive(PrimitiveType::Void),
};

let is_const = pointer.mutability.is_none();
let is_const = matches!(pointer.mutability, syn::PointerMutability::Const(_));
Type::Ptr {
ty: Box::new(converted),
is_const,
Expand Down Expand Up @@ -412,7 +412,7 @@ impl Type {
let len = ConstExpr::load(len)?;
Type::Array(Box::new(converted), len)
}
syn::Type::BareFn(ref function) => {
syn::Type::FnPtr(ref function) => {
let mut wildcard_counter = 0;
let mut args = function.inputs.iter().try_skip_map(|x| {
Type::load(&x.ty).map(|opt_ty| {
Expand Down
Loading