diff options
Diffstat (limited to 'macro/src')
-rw-r--r-- | macro/src/clang.rs | 16 | ||||
-rw-r--r-- | macro/src/derive.rs | 15 | ||||
-rw-r--r-- | macro/src/expand.rs | 175 | ||||
-rw-r--r-- | macro/src/generics.rs | 10 | ||||
-rw-r--r-- | macro/src/lib.rs | 8 | ||||
-rw-r--r-- | macro/src/load.rs | 14 | ||||
-rw-r--r-- | macro/src/tokens.rs | 8 | ||||
-rw-r--r-- | macro/src/type_id.rs | 4 |
8 files changed, 173 insertions, 77 deletions
diff --git a/macro/src/clang.rs b/macro/src/clang.rs index 381e5086..09efc1ec 100644 --- a/macro/src/clang.rs +++ b/macro/src/clang.rs @@ -1,9 +1,9 @@ -use serde::{Deserialize, Serialize}; +use serde_derive::{Deserialize, Serialize}; -pub type Node = clang_ast::Node<Clang>; +pub(crate) type Node = clang_ast::Node<Clang>; #[derive(Deserialize, Serialize)] -pub enum Clang { +pub(crate) enum Clang { NamespaceDecl(NamespaceDecl), EnumDecl(EnumDecl), EnumConstantDecl(EnumConstantDecl), @@ -13,13 +13,13 @@ pub enum Clang { } #[derive(Deserialize, Serialize)] -pub struct NamespaceDecl { +pub(crate) struct NamespaceDecl { #[serde(skip_serializing_if = "Option::is_none")] pub name: Option<Box<str>>, } #[derive(Deserialize, Serialize)] -pub struct EnumDecl { +pub(crate) struct EnumDecl { #[serde(skip_serializing_if = "Option::is_none")] pub name: Option<Box<str>>, #[serde( @@ -30,17 +30,17 @@ pub struct EnumDecl { } #[derive(Deserialize, Serialize)] -pub struct EnumConstantDecl { +pub(crate) struct EnumConstantDecl { pub name: Box<str>, } #[derive(Deserialize, Serialize)] -pub struct ConstantExpr { +pub(crate) struct ConstantExpr { pub value: Box<str>, } #[derive(Deserialize, Serialize)] -pub struct Type { +pub(crate) struct Type { #[serde(rename = "qualType")] pub qual_type: Box<str>, #[serde(rename = "desugaredQualType", skip_serializing_if = "Option::is_none")] diff --git a/macro/src/derive.rs b/macro/src/derive.rs index e1d8d69e..a439bf90 100644 --- a/macro/src/derive.rs +++ b/macro/src/derive.rs @@ -1,10 +1,13 @@ -use crate::syntax::{derive, Enum, Struct, Trait}; +use crate::syntax::{derive, Enum, Struct}; use proc_macro2::{Ident, Span, TokenStream}; use quote::{quote, quote_spanned, ToTokens}; -pub use crate::syntax::derive::*; +pub(crate) use crate::syntax::derive::*; -pub fn expand_struct(strct: &Struct, actual_derives: &mut Option<TokenStream>) -> TokenStream { +pub(crate) fn expand_struct( + strct: &Struct, + actual_derives: &mut Option<TokenStream>, +) -> TokenStream { let mut expanded = TokenStream::new(); let mut traits = Vec::new(); @@ -35,7 +38,7 @@ pub fn expand_struct(strct: &Struct, actual_derives: &mut Option<TokenStream>) - expanded } -pub fn expand_enum(enm: &Enum, actual_derives: &mut Option<TokenStream>) -> TokenStream { +pub(crate) fn expand_enum(enm: &Enum, actual_derives: &mut Option<TokenStream>) -> TokenStream { let mut expanded = TokenStream::new(); let mut traits = Vec::new(); let mut has_copy = false; @@ -212,6 +215,8 @@ fn struct_partial_ord(strct: &Struct, span: Span) -> TokenStream { quote_spanned! {span=> impl #generics ::cxx::core::cmp::PartialOrd for #ident #generics { + #[allow(clippy::non_canonical_partial_ord_impl)] + #[allow(renamed_and_removed_lints, clippy::incorrect_partial_ord_impl_on_ord_type)] // Rust 1.73 and older fn partial_cmp(&self, other: &Self) -> ::cxx::core::option::Option<::cxx::core::cmp::Ordering> { #body } @@ -280,6 +285,8 @@ fn enum_partial_ord(enm: &Enum, span: Span) -> TokenStream { quote_spanned! {span=> impl ::cxx::core::cmp::PartialOrd for #ident { + #[allow(clippy::non_canonical_partial_ord_impl)] + #[allow(renamed_and_removed_lints, clippy::incorrect_partial_ord_impl_on_ord_type)] // Rust 1.73 and older fn partial_cmp(&self, other: &Self) -> ::cxx::core::option::Option<::cxx::core::cmp::Ordering> { ::cxx::core::cmp::PartialOrd::partial_cmp(&self.repr, &other.repr) } diff --git a/macro/src/expand.rs b/macro/src/expand.rs index bd0a2063..8a0db43f 100644 --- a/macro/src/expand.rs +++ b/macro/src/expand.rs @@ -17,7 +17,7 @@ use quote::{format_ident, quote, quote_spanned, ToTokens}; use std::mem; use syn::{parse_quote, punctuated, Generics, Lifetime, Result, Token}; -pub fn bridge(mut ffi: Module) -> Result<TokenStream> { +pub(crate) fn bridge(mut ffi: Module) -> Result<TokenStream> { let ref mut errors = Errors::new(); let mut cfg = CfgExpr::Unconditional; @@ -142,8 +142,12 @@ fn expand(ffi: Module, doc: Doc, attrs: OtherAttrs, apis: &[Api], types: &Types) #[allow( non_camel_case_types, non_snake_case, + unused_unsafe, // FIXME: only needed by rustc 1.64 and older clippy::extra_unused_type_parameters, + clippy::items_after_statements, + clippy::no_effect_underscore_binding, clippy::ptr_as_ptr, + clippy::ref_as_ptr, clippy::upper_case_acronyms, clippy::use_self, )] @@ -717,12 +721,9 @@ fn expand_cxx_function_shim(efn: &ExternFn, types: &Types) -> TokenStream { expr = quote_spanned!(span=> ::cxx::core::result::Result::Ok(#expr)); } }; - let mut dispatch = quote!(#setup #expr); + let dispatch = quote_spanned!(span=> unsafe { #setup #expr }); let visibility = efn.visibility; let unsafety = &efn.sig.unsafety; - if unsafety.is_none() { - dispatch = quote_spanned!(span=> unsafe { #dispatch }); - } let fn_token = efn.sig.fn_token; let ident = &efn.name.rust; let generics = &efn.generics; @@ -984,22 +985,31 @@ fn expand_rust_function_shim_impl( }); let all_args = receiver.into_iter().chain(args); + let mut requires_unsafe = false; let arg_vars = sig.args.iter().map(|arg| { let var = &arg.name.rust; let span = var.span(); match &arg.ty { Type::Ident(i) if i.rust == RustString => { + requires_unsafe = true; quote_spanned!(span=> ::cxx::core::mem::take((*#var).as_mut_string())) } - Type::RustBox(_) => quote_spanned!(span=> ::cxx::alloc::boxed::Box::from_raw(#var)), + Type::RustBox(_) => { + requires_unsafe = true; + quote_spanned!(span=> ::cxx::alloc::boxed::Box::from_raw(#var)) + } Type::RustVec(vec) => { + requires_unsafe = true; if vec.inner == RustString { quote_spanned!(span=> ::cxx::core::mem::take((*#var).as_mut_vec_string())) } else { quote_spanned!(span=> ::cxx::core::mem::take((*#var).as_mut_vec())) } } - Type::UniquePtr(_) => quote_spanned!(span=> ::cxx::UniquePtr::from_raw(#var)), + Type::UniquePtr(_) => { + requires_unsafe = true; + quote_spanned!(span=> ::cxx::UniquePtr::from_raw(#var)) + } Type::Ref(ty) => match &ty.inner { Type::Ident(i) if i.rust == RustString => match ty.mutable { false => quote_spanned!(span=> #var.as_string()), @@ -1015,8 +1025,12 @@ fn expand_rust_function_shim_impl( }, _ => quote!(#var), }, - Type::Str(_) => quote_spanned!(span=> #var.as_str()), + Type::Str(_) => { + requires_unsafe = true; + quote_spanned!(span=> #var.as_str()) + } Type::SliceRef(slice) => { + requires_unsafe = true; let inner = &slice.inner; match slice.mutable { false => quote_spanned!(span=> #var.as_slice::<#inner>()), @@ -1024,6 +1038,7 @@ fn expand_rust_function_shim_impl( } } ty if types.needs_indirect_abi(ty) => { + requires_unsafe = true; quote_spanned!(span=> ::cxx::core::ptr::read(#var)) } _ => quote!(#var), @@ -1041,6 +1056,7 @@ fn expand_rust_function_shim_impl( } None => { requires_closure = true; + requires_unsafe = true; quote!(::cxx::core::mem::transmute::<*const (), #sig>(__extern)) } }; @@ -1108,12 +1124,18 @@ fn expand_rust_function_shim_impl( None => quote_spanned!(span=> &mut ()), }; requires_closure = true; + requires_unsafe = true; expr = quote_spanned!(span=> ::cxx::private::r#try(#out, #expr)); } else if indirect_return { requires_closure = true; + requires_unsafe = true; expr = quote_spanned!(span=> ::cxx::core::ptr::write(__return, #expr)); } + if requires_unsafe { + expr = quote_spanned!(span=> unsafe { #expr }); + } + let closure = if requires_closure { quote_spanned!(span=> move || #expr) } else { @@ -1192,9 +1214,14 @@ fn expand_rust_function_shim_super( } }; + let mut body = quote_spanned!(span=> #call(#(#vars,)*)); + if unsafety.is_some() { + body = quote_spanned!(span=> unsafe { #body }); + } + quote_spanned! {span=> #unsafety fn #local_name #generics(#(#all_args,)*) #ret { - #call(#(#vars,)*) + #body } } } @@ -1285,13 +1312,13 @@ fn expand_rust_box(key: NamedImplKey, types: &Types, explicit_impl: Option<&Impl #[export_name = #link_dealloc] unsafe extern "C" fn #local_dealloc #impl_generics(ptr: *mut ::cxx::core::mem::MaybeUninit<#ident #ty_generics>) { // No prevent_unwind: the global allocator is not allowed to panic. - let _ = ::cxx::alloc::boxed::Box::from_raw(ptr); + let _ = unsafe { ::cxx::alloc::boxed::Box::from_raw(ptr) }; } #[doc(hidden)] #[export_name = #link_drop] unsafe extern "C" fn #local_drop #impl_generics(this: *mut ::cxx::alloc::boxed::Box<#ident #ty_generics>) { let __fn = concat!("<", module_path!(), #prevent_unwind_drop_label); - ::cxx::private::prevent_unwind(__fn, || ::cxx::core::ptr::drop_in_place(this)); + ::cxx::private::prevent_unwind(__fn, || unsafe { ::cxx::core::ptr::drop_in_place(this) }); } } } @@ -1333,49 +1360,61 @@ fn expand_rust_vec(key: NamedImplKey, types: &Types, explicit_impl: Option<&Impl #[export_name = #link_new] unsafe extern "C" fn #local_new #impl_generics(this: *mut ::cxx::private::RustVec<#elem #ty_generics>) { // No prevent_unwind: cannot panic. - ::cxx::core::ptr::write(this, ::cxx::private::RustVec::new()); + unsafe { + ::cxx::core::ptr::write(this, ::cxx::private::RustVec::new()); + } } #[doc(hidden)] #[export_name = #link_drop] unsafe extern "C" fn #local_drop #impl_generics(this: *mut ::cxx::private::RustVec<#elem #ty_generics>) { let __fn = concat!("<", module_path!(), #prevent_unwind_drop_label); - ::cxx::private::prevent_unwind(__fn, || ::cxx::core::ptr::drop_in_place(this)); + ::cxx::private::prevent_unwind( + __fn, + || unsafe { ::cxx::core::ptr::drop_in_place(this) }, + ); } #[doc(hidden)] #[export_name = #link_len] unsafe extern "C" fn #local_len #impl_generics(this: *const ::cxx::private::RustVec<#elem #ty_generics>) -> usize { // No prevent_unwind: cannot panic. - (*this).len() + unsafe { (*this).len() } } #[doc(hidden)] #[export_name = #link_capacity] unsafe extern "C" fn #local_capacity #impl_generics(this: *const ::cxx::private::RustVec<#elem #ty_generics>) -> usize { // No prevent_unwind: cannot panic. - (*this).capacity() + unsafe { (*this).capacity() } } #[doc(hidden)] #[export_name = #link_data] unsafe extern "C" fn #local_data #impl_generics(this: *const ::cxx::private::RustVec<#elem #ty_generics>) -> *const #elem #ty_generics { // No prevent_unwind: cannot panic. - (*this).as_ptr() + unsafe { (*this).as_ptr() } } #[doc(hidden)] #[export_name = #link_reserve_total] unsafe extern "C" fn #local_reserve_total #impl_generics(this: *mut ::cxx::private::RustVec<#elem #ty_generics>, new_cap: usize) { // No prevent_unwind: the global allocator is not allowed to panic. - (*this).reserve_total(new_cap); + unsafe { + (*this).reserve_total(new_cap); + } } #[doc(hidden)] #[export_name = #link_set_len] unsafe extern "C" fn #local_set_len #impl_generics(this: *mut ::cxx::private::RustVec<#elem #ty_generics>, len: usize) { // No prevent_unwind: cannot panic. - (*this).set_len(len); + unsafe { + (*this).set_len(len); + } } #[doc(hidden)] #[export_name = #link_truncate] unsafe extern "C" fn #local_truncate #impl_generics(this: *mut ::cxx::private::RustVec<#elem #ty_generics>, len: usize) { let __fn = concat!("<", module_path!(), #prevent_unwind_drop_label); - ::cxx::private::prevent_unwind(__fn, || (*this).truncate(len)); + ::cxx::private::prevent_unwind( + __fn, + || unsafe { (*this).truncate(len) }, + ); } } } @@ -1407,7 +1446,9 @@ fn expand_unique_ptr( fn __uninit(this: *mut ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void>) -> *mut ::cxx::core::ffi::c_void; } let mut repr = ::cxx::core::mem::MaybeUninit::uninit(); - unsafe { __uninit(&mut repr).cast::<#ident #ty_generics>().write(value) } + unsafe { + __uninit(&mut repr).cast::<#ident #ty_generics>().write(value); + } repr } }) @@ -1430,7 +1471,9 @@ fn expand_unique_ptr( fn __null(this: *mut ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void>); } let mut repr = ::cxx::core::mem::MaybeUninit::uninit(); - unsafe { __null(&mut repr) } + unsafe { + __null(&mut repr); + } repr } #new_method @@ -1440,7 +1483,9 @@ fn expand_unique_ptr( fn __raw(this: *mut ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void>, raw: *mut ::cxx::core::ffi::c_void); } let mut repr = ::cxx::core::mem::MaybeUninit::uninit(); - __raw(&mut repr, raw.cast()); + unsafe { + __raw(&mut repr, raw.cast()); + } repr } unsafe fn __get(repr: ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void>) -> *const Self { @@ -1448,21 +1493,23 @@ fn expand_unique_ptr( #[link_name = #link_get] fn __get(this: *const ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void>) -> *const ::cxx::core::ffi::c_void; } - __get(&repr).cast() + unsafe { __get(&repr).cast() } } unsafe fn __release(mut repr: ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void>) -> *mut Self { extern "C" { #[link_name = #link_release] fn __release(this: *mut ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void>) -> *mut ::cxx::core::ffi::c_void; } - __release(&mut repr).cast() + unsafe { __release(&mut repr).cast() } } unsafe fn __drop(mut repr: ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void>) { extern "C" { #[link_name = #link_drop] fn __drop(this: *mut ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void>); } - __drop(&mut repr); + unsafe { + __drop(&mut repr); + } } } } @@ -1493,7 +1540,9 @@ fn expand_shared_ptr( #[link_name = #link_uninit] fn __uninit(new: *mut ::cxx::core::ffi::c_void) -> *mut ::cxx::core::ffi::c_void; } - __uninit(new).cast::<#ident #ty_generics>().write(value); + unsafe { + __uninit(new).cast::<#ident #ty_generics>().write(value); + } } }) } else { @@ -1514,7 +1563,9 @@ fn expand_shared_ptr( #[link_name = #link_null] fn __null(new: *mut ::cxx::core::ffi::c_void); } - __null(new); + unsafe { + __null(new); + } } #new_method unsafe fn __clone(this: *const ::cxx::core::ffi::c_void, new: *mut ::cxx::core::ffi::c_void) { @@ -1522,21 +1573,25 @@ fn expand_shared_ptr( #[link_name = #link_clone] fn __clone(this: *const ::cxx::core::ffi::c_void, new: *mut ::cxx::core::ffi::c_void); } - __clone(this, new); + unsafe { + __clone(this, new); + } } unsafe fn __get(this: *const ::cxx::core::ffi::c_void) -> *const Self { extern "C" { #[link_name = #link_get] fn __get(this: *const ::cxx::core::ffi::c_void) -> *const ::cxx::core::ffi::c_void; } - __get(this).cast() + unsafe { __get(this).cast() } } unsafe fn __drop(this: *mut ::cxx::core::ffi::c_void) { extern "C" { #[link_name = #link_drop] fn __drop(this: *mut ::cxx::core::ffi::c_void); } - __drop(this); + unsafe { + __drop(this); + } } } } @@ -1569,35 +1624,45 @@ fn expand_weak_ptr(key: NamedImplKey, types: &Types, explicit_impl: Option<&Impl #[link_name = #link_null] fn __null(new: *mut ::cxx::core::ffi::c_void); } - __null(new); + unsafe { + __null(new); + } } unsafe fn __clone(this: *const ::cxx::core::ffi::c_void, new: *mut ::cxx::core::ffi::c_void) { extern "C" { #[link_name = #link_clone] fn __clone(this: *const ::cxx::core::ffi::c_void, new: *mut ::cxx::core::ffi::c_void); } - __clone(this, new); + unsafe { + __clone(this, new); + } } unsafe fn __downgrade(shared: *const ::cxx::core::ffi::c_void, weak: *mut ::cxx::core::ffi::c_void) { extern "C" { #[link_name = #link_downgrade] fn __downgrade(shared: *const ::cxx::core::ffi::c_void, weak: *mut ::cxx::core::ffi::c_void); } - __downgrade(shared, weak); + unsafe { + __downgrade(shared, weak); + } } unsafe fn __upgrade(weak: *const ::cxx::core::ffi::c_void, shared: *mut ::cxx::core::ffi::c_void) { extern "C" { #[link_name = #link_upgrade] fn __upgrade(weak: *const ::cxx::core::ffi::c_void, shared: *mut ::cxx::core::ffi::c_void); } - __upgrade(weak, shared); + unsafe { + __upgrade(weak, shared); + } } unsafe fn __drop(this: *mut ::cxx::core::ffi::c_void) { extern "C" { #[link_name = #link_drop] fn __drop(this: *mut ::cxx::core::ffi::c_void); } - __drop(this); + unsafe { + __drop(this); + } } } } @@ -1612,6 +1677,7 @@ fn expand_cxx_vector( let name = elem.to_string(); let resolve = types.resolve(elem); let prefix = format!("cxxbridge1$std$vector${}$", resolve.name.to_symbol()); + let link_new = format!("{}new", prefix); let link_size = format!("{}size", prefix); let link_get_unchecked = format!("{}get_unchecked", prefix); let link_push_back = format!("{}push_back", prefix); @@ -1646,7 +1712,12 @@ fn expand_cxx_vector( value: *mut ::cxx::core::ffi::c_void, ); } - __push_back(this, value as *mut ::cxx::core::mem::ManuallyDrop<Self> as *mut ::cxx::core::ffi::c_void); + unsafe { + __push_back( + this, + value as *mut ::cxx::core::mem::ManuallyDrop<Self> as *mut ::cxx::core::ffi::c_void, + ); + } } unsafe fn __pop_back( this: ::cxx::core::pin::Pin<&mut ::cxx::CxxVector<Self>>, @@ -1659,7 +1730,12 @@ fn expand_cxx_vector( out: *mut ::cxx::core::ffi::c_void, ); } - __pop_back(this, out as *mut ::cxx::core::mem::MaybeUninit<Self> as *mut ::cxx::core::ffi::c_void); + unsafe { + __pop_back( + this, + out as *mut ::cxx::core::mem::MaybeUninit<Self> as *mut ::cxx::core::ffi::c_void, + ); + } } }) } else { @@ -1671,6 +1747,13 @@ fn expand_cxx_vector( fn __typename(f: &mut ::cxx::core::fmt::Formatter<'_>) -> ::cxx::core::fmt::Result { f.write_str(#name) } + fn __vector_new() -> *mut ::cxx::CxxVector<Self> { + extern "C" { + #[link_name = #link_new] + fn __vector_new #impl_generics() -> *mut ::cxx::CxxVector<#elem #ty_generics>; + } + unsafe { __vector_new() } + } fn __vector_size(v: &::cxx::CxxVector<Self>) -> usize { extern "C" { #[link_name = #link_size] @@ -1686,7 +1769,7 @@ fn expand_cxx_vector( pos: usize, ) -> *mut ::cxx::core::ffi::c_void; } - __get_unchecked(v, pos) as *mut Self + unsafe { __get_unchecked(v, pos) as *mut Self } } #by_value_methods fn __unique_ptr_null() -> ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void> { @@ -1695,7 +1778,9 @@ fn expand_cxx_vector( fn __unique_ptr_null(this: *mut ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void>); } let mut repr = ::cxx::core::mem::MaybeUninit::uninit(); - unsafe { __unique_ptr_null(&mut repr) } + unsafe { + __unique_ptr_null(&mut repr); + } repr } unsafe fn __unique_ptr_raw(raw: *mut ::cxx::CxxVector<Self>) -> ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void> { @@ -1704,7 +1789,9 @@ fn expand_cxx_vector( fn __unique_ptr_raw #impl_generics(this: *mut ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void>, raw: *mut ::cxx::CxxVector<#elem #ty_generics>); } let mut repr = ::cxx::core::mem::MaybeUninit::uninit(); - __unique_ptr_raw(&mut repr, raw); + unsafe { + __unique_ptr_raw(&mut repr, raw); + } repr } unsafe fn __unique_ptr_get(repr: ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void>) -> *const ::cxx::CxxVector<Self> { @@ -1712,21 +1799,23 @@ fn expand_cxx_vector( #[link_name = #link_unique_ptr_get] fn __unique_ptr_get #impl_generics(this: *const ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void>) -> *const ::cxx::CxxVector<#elem #ty_generics>; } - __unique_ptr_get(&repr) + unsafe { __unique_ptr_get(&repr) } } unsafe fn __unique_ptr_release(mut repr: ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void>) -> *mut ::cxx::CxxVector<Self> { extern "C" { #[link_name = #link_unique_ptr_release] fn __unique_ptr_release #impl_generics(this: *mut ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void>) -> *mut ::cxx::CxxVector<#elem #ty_generics>; } - __unique_ptr_release(&mut repr) + unsafe { __unique_ptr_release(&mut repr) } } unsafe fn __unique_ptr_drop(mut repr: ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void>) { extern "C" { #[link_name = #link_unique_ptr_drop] fn __unique_ptr_drop(this: *mut ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void>); } - __unique_ptr_drop(&mut repr); + unsafe { + __unique_ptr_drop(&mut repr); + } } } } diff --git a/macro/src/generics.rs b/macro/src/generics.rs index 7862536d..f501def2 100644 --- a/macro/src/generics.rs +++ b/macro/src/generics.rs @@ -5,18 +5,18 @@ use proc_macro2::TokenStream; use quote::ToTokens; use syn::{Lifetime, Token}; -pub struct ImplGenerics<'a> { +pub(crate) struct ImplGenerics<'a> { explicit_impl: Option<&'a Impl>, resolve: Resolution<'a>, } -pub struct TyGenerics<'a> { +pub(crate) struct TyGenerics<'a> { key: NamedImplKey<'a>, explicit_impl: Option<&'a Impl>, resolve: Resolution<'a>, } -pub fn split_for_impl<'a>( +pub(crate) fn split_for_impl<'a>( key: NamedImplKey<'a>, explicit_impl: Option<&'a Impl>, resolve: Resolution<'a>, @@ -62,12 +62,12 @@ impl<'a> ToTokens for TyGenerics<'a> { } } -pub struct UnderscoreLifetimes<'a> { +pub(crate) struct UnderscoreLifetimes<'a> { generics: &'a Lifetimes, } impl Lifetimes { - pub fn to_underscore_lifetimes(&self) -> UnderscoreLifetimes { + pub(crate) fn to_underscore_lifetimes(&self) -> UnderscoreLifetimes { UnderscoreLifetimes { generics: self } } } diff --git a/macro/src/lib.rs b/macro/src/lib.rs index d0205b32..472dbc4c 100644 --- a/macro/src/lib.rs +++ b/macro/src/lib.rs @@ -6,6 +6,7 @@ clippy::enum_glob_use, clippy::if_same_then_else, clippy::inherent_to_string, + clippy::into_iter_without_iter, clippy::items_after_statements, clippy::large_enum_variant, clippy::match_bool, @@ -14,19 +15,18 @@ clippy::needless_pass_by_value, clippy::new_without_default, clippy::nonminimal_bool, - clippy::option_if_let_else, clippy::or_fun_call, clippy::redundant_else, clippy::shadow_unrelated, clippy::similar_names, clippy::single_match, clippy::single_match_else, + clippy::struct_field_names, clippy::too_many_arguments, clippy::too_many_lines, clippy::toplevel_ref_arg, - clippy::useless_let_if_seq, - // clippy bug: https://github.com/rust-lang/rust-clippy/issues/6983 - clippy::wrong_self_convention + clippy::uninlined_format_args, + clippy::useless_let_if_seq )] mod derive; diff --git a/macro/src/load.rs b/macro/src/load.rs index dccece44..d3148c94 100644 --- a/macro/src/load.rs +++ b/macro/src/load.rs @@ -18,7 +18,7 @@ use syn::{parse_quote, Path}; const CXX_CLANG_AST: &str = "CXX_CLANG_AST"; -pub fn load(cx: &mut Errors, apis: &mut [Api]) { +pub(crate) fn load(cx: &mut Errors, apis: &mut [Api]) { let ref mut variants_from_header = Vec::new(); for api in apis { if let Api::Enum(enm) = api { @@ -36,7 +36,7 @@ pub fn load(cx: &mut Errors, apis: &mut [Api]) { } } - let span = match variants_from_header.get(0) { + let span = match variants_from_header.first() { None => return, Some(enm) => enm.variants_from_header_attr.clone().unwrap(), }; @@ -60,7 +60,7 @@ pub fn load(cx: &mut Errors, apis: &mut [Api]) { if is_gzipped { gunzipped = Vec::new(); let decode_result = GzDecoder::new(&mut gunzipped).write_all(memmap); - decode_result.map(|_| gunzipped.as_slice()) + decode_result.map(|()| gunzipped.as_slice()) } else { Ok(memmap as &[u8]) } @@ -165,7 +165,7 @@ fn traverse<'a>( .variants_from_header_attr .as_ref() .unwrap() - .path + .path() .get_ident() .unwrap() .span(); @@ -259,7 +259,7 @@ fn translate_qual_type(cx: &mut Errors, enm: &Enum, qual_type: &str) -> Path { .variants_from_header_attr .as_ref() .unwrap() - .path + .path() .get_ident() .unwrap() .span(); @@ -277,7 +277,7 @@ enum ParsedDiscriminant { fn discriminant_value(mut clang: &[Node]) -> ParsedDiscriminant { if clang.is_empty() { // No discriminant expression provided; use successor of previous - // descriminant. + // discriminant. return ParsedDiscriminant::Successor; } @@ -301,7 +301,7 @@ fn discriminant_value(mut clang: &[Node]) -> ParsedDiscriminant { fn span_for_enum_error(enm: &Enum) -> TokenStream { let enum_token = enm.enum_token; let mut brace_token = Group::new(Delimiter::Brace, TokenStream::new()); - brace_token.set_span(enm.brace_token.span); + brace_token.set_span(enm.brace_token.span.join()); quote!(#enum_token #brace_token) } diff --git a/macro/src/tokens.rs b/macro/src/tokens.rs index 805af227..f3512a71 100644 --- a/macro/src/tokens.rs +++ b/macro/src/tokens.rs @@ -3,17 +3,17 @@ use proc_macro2::TokenStream; use quote::{quote_spanned, ToTokens}; use syn::Token; -pub struct ReceiverType<'a>(&'a Receiver); -pub struct ReceiverTypeSelf<'a>(&'a Receiver); +pub(crate) struct ReceiverType<'a>(&'a Receiver); +pub(crate) struct ReceiverTypeSelf<'a>(&'a Receiver); impl Receiver { // &TheType - pub fn ty(&self) -> ReceiverType { + pub(crate) fn ty(&self) -> ReceiverType { ReceiverType(self) } // &Self - pub fn ty_self(&self) -> ReceiverTypeSelf { + pub(crate) fn ty_self(&self) -> ReceiverTypeSelf { ReceiverTypeSelf(self) } } diff --git a/macro/src/type_id.rs b/macro/src/type_id.rs index 7bca67b1..31842984 100644 --- a/macro/src/type_id.rs +++ b/macro/src/type_id.rs @@ -3,7 +3,7 @@ use proc_macro2::{TokenStream, TokenTree}; use quote::{format_ident, quote, ToTokens}; use syn::ext::IdentExt; -pub enum Crate { +pub(crate) enum Crate { Cxx, DollarCrate(TokenTree), } @@ -18,7 +18,7 @@ impl ToTokens for Crate { } // "folly::File" => `(f, o, l, l, y, (), F, i, l, e)` -pub fn expand(krate: Crate, arg: QualifiedName) -> TokenStream { +pub(crate) fn expand(krate: Crate, arg: QualifiedName) -> TokenStream { let mut ids = Vec::new(); for word in arg.segments { |