diff options
author | Nick Fitzgerald <fitzgen@gmail.com> | 2017-02-15 14:43:38 -0800 |
---|---|---|
committer | Nick Fitzgerald <fitzgen@gmail.com> | 2017-03-07 11:04:00 -0800 |
commit | 1c4332a1aa3dd299c133f72efb8b28dd5c8aa9d4 (patch) | |
tree | e476309d4730ba1a611acc6db59ab880ab3d8d00 /tests | |
parent | 17275f87004044d8702a80467880f568738357c2 (diff) |
Completely rework templates
* Find each item's used template parameters when we begin the codegen phase
* Add TemplateDeclaration::used_template_params()
This method is available during the codegen phase, and uses the information
gleaned by the `ir::named::UsedTemplateParameters` analysis.
* Remove Item::{applicable_template_args,signature_contains_named_type}
They are replaced by the template parameter usage analysis and
TemplateDeclaration::used_template_params.
* Parse and de-duplicate named template type parameters
* Do not attempt to determine template parameter usage when not recursively whitelisting
* Add a proper TemplateInstantiation type
This makes it so that CompInfo is always either a compound type definition, or a
template compound type definition, never an instantiation of a template. It also
pulls out TypeKind::TemplateInstantiation(<inline stuff>) to a proper
ir::TemplateInstantiation type, and TypeKind::TemplateInstantiation just wraps
ir::TemplateInstantiation into TypeKind.
* Allow template definitions to lack template parameters because of opaque template definitions
* Detect and ignore cycles deriving Copy/Debug and whether a type has a vtable
* Bail out early in the face of partial template specialization
We don't support it, and shouldn't continue trying to parse a type from this
cursor.
* Do not consider inner type's parameter usage as our own parameter usage
* Do not require a parent_id for template instantiations
It is not necessary, and in fact was preventing us from creating template
instantiations in some places, resulting in such nonsense as a generic template
definition as a base for another type.
* Only join if this is NOT a named template type or a template instantiation
Otherwise, we'll always consider all of a template instantiation's arguments as
used, when they should only be considered used if the template definition uses
that template parameter.
* Consider function return and parameter types as used
Although we should not follow class method edges because we cannot create new
monomorphizations of methods, code can create aliases of function pointers whose
return or parameter types are template parameters, and those template parameters
should be considered used.
* Add the AsNamed trait for things which might be a named template type
This sees through ResolvedTypeReferences to get at the final named type and its
canonical item id. By using this in the named template parameter usage analysis,
we ensure we don't have bugs where there are ResolvedTypeReferences in the usage
sets rather than the canonical named item id, which could cause template
parameters to be ignored accidentally.
* Do not consider an inner var's template parameter usage as our own
* Make the expectations' tests less noisy
* Use opaque blobs for unknown template definition types
When we don't know how to generate a Rust type from a template definition (eg
because it uses non-type template parameters), then we should fall back to using
the instantiation's layout to generate the opaque blob.
* Implement CanDeriveDebug for TemplateInstantiation
We need the template instantiation's layout to determine if we can derive debug
for it when the instantiation's template definition has non-type parameters.
* Stop thrashing malloc when unioning ItemSets in UsedTemplateParameters
Previously, we were cloning an ItemSet, which requires a malloc for non-empty
sets, when taking its union with our current id's set. Now, instead of doing
that, we wrap each ItemSet in an Option, and take the set out of the hash map
when modifying it. This allows us to side-step the borrow checker and HashMap's
lack of an analog to `slice::split_at_mut` and mutate what is logically a value
in the hash map while also using immutable references of values that are
physically in the hash map.
* Add some tests explicitly about template parameter usage
* Updated test expectations now that we are inferring template parameter usage
* Reinstate the layout tests for template instantiations
* Generate opaque blobs for uses of partially specialized templates
This adds `TypeKind::Opaque` which signifies that we do not understand anything
about the given type and that we should just generate an opaque blob based on
the type's layout. It explicitly uses the opaque type kind for partially
specialized templates.
* Add note about None vs Some([]) in TemplateDeclaration
* Do not rely on TypeKind implementing PartialEq
* Prefer assert_eq!(lhs, rhs) to assert!(lhs == rhs)
* Expand some comments for ir::named::UsedTemplateParameters
* Expand Item::is_opaque to consider TypeKind::Opaque
* Use opaque types instead of panicking
Use opaque types as our last resort when resolving type references after we have
collected unresolved type references instead of panicking.
* Find template definitions that don't want to be found
* Recognize associated template types and make them opaque
Diffstat (limited to 'tests')
78 files changed, 759 insertions, 393 deletions
diff --git a/tests/expectations/lib.rs b/tests/expectations/lib.rs index e69de29b..562dc554 100644..100755 --- a/tests/expectations/lib.rs +++ b/tests/expectations/lib.rs @@ -0,0 +1,3 @@ +#![allow(dead_code)] +#![allow(non_camel_case_types)] +#![allow(non_upper_case_globals)] diff --git a/tests/expectations/tests/381-decltype-alias.rs b/tests/expectations/tests/381-decltype-alias.rs index 45b0cfdd..632cdd31 100644 --- a/tests/expectations/tests/381-decltype-alias.rs +++ b/tests/expectations/tests/381-decltype-alias.rs @@ -5,11 +5,8 @@ #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct std_allocator_traits<_Alloc> { +#[derive(Debug, Default, Copy, Clone)] +pub struct std_allocator_traits { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<_Alloc>, -} -impl <_Alloc> Default for std_allocator_traits<_Alloc> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } } +pub type std_allocator_traits___size_type<_Alloc> = _Alloc; diff --git a/tests/expectations/tests/anon_enum_trait.rs b/tests/expectations/tests/anon_enum_trait.rs index 31eaca83..92c697a8 100644 --- a/tests/expectations/tests/anon_enum_trait.rs +++ b/tests/expectations/tests/anon_enum_trait.rs @@ -5,10 +5,9 @@ #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct DataType<_Tp> { +#[derive(Debug, Default, Copy, Clone)] +pub struct DataType { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<_Tp>, } pub type DataType_value_type<_Tp> = _Tp; pub type DataType_work_type<_Tp> = DataType_value_type<_Tp>; @@ -27,9 +26,6 @@ pub const DataType_type_: DataType__bindgen_ty_1 = #[repr(i32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum DataType__bindgen_ty_1 { generic_type = 0, } -impl <_Tp> Default for DataType<_Tp> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } -} #[repr(C)] #[derive(Debug, Default, Copy)] pub struct Foo { diff --git a/tests/expectations/tests/anon_union.rs b/tests/expectations/tests/anon_union.rs index 4418bc77..eb600cc7 100644 --- a/tests/expectations/tests/anon_union.rs +++ b/tests/expectations/tests/anon_union.rs @@ -30,12 +30,11 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> { } #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct TErrorResult<T> { +pub struct TErrorResult { pub mResult: ::std::os::raw::c_int, - pub __bindgen_anon_1: TErrorResult__bindgen_ty_1<T>, + pub __bindgen_anon_1: TErrorResult__bindgen_ty_1, pub mMightHaveUnreported: bool, pub mUnionState: TErrorResult_UnionState, - pub _phantom_0: ::std::marker::PhantomData<T>, } pub const TErrorResult_UnionState_HasException: TErrorResult_UnionState = TErrorResult_UnionState::HasMessage; @@ -44,31 +43,28 @@ pub const TErrorResult_UnionState_HasException: TErrorResult_UnionState = pub enum TErrorResult_UnionState { HasMessage = 0, } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] -pub struct TErrorResult_Message<T> { +pub struct TErrorResult_Message { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<T>, } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] -pub struct TErrorResult_DOMExceptionInfo<T> { +pub struct TErrorResult_DOMExceptionInfo { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<T>, } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] -pub struct TErrorResult__bindgen_ty_1<T> { - pub mMessage: __BindgenUnionField<*mut TErrorResult_Message<T>>, - pub mDOMExceptionInfo: __BindgenUnionField<*mut TErrorResult_DOMExceptionInfo<T>>, +pub struct TErrorResult__bindgen_ty_1 { + pub mMessage: __BindgenUnionField<*mut TErrorResult_Message>, + pub mDOMExceptionInfo: __BindgenUnionField<*mut TErrorResult_DOMExceptionInfo>, pub bindgen_union_field: u64, - pub _phantom_0: ::std::marker::PhantomData<T>, } -impl <T> Default for TErrorResult<T> { +impl Default for TErrorResult { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] #[derive(Debug, Copy)] pub struct ErrorResult { - pub _base: TErrorResult<::std::os::raw::c_int>, + pub _base: TErrorResult, } #[test] fn bindgen_test_layout_ErrorResult() { @@ -84,13 +80,11 @@ impl Default for ErrorResult { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[test] -fn __bindgen_test_layout_template_1() { - assert_eq!(::std::mem::size_of::<TErrorResult<::std::os::raw::c_int>>() , - 24usize , concat ! ( +fn __bindgen_test_layout_TErrorResult_instantiation_21() { + assert_eq!(::std::mem::size_of::<TErrorResult>() , 24usize , concat ! ( "Size of template specialization: " , stringify ! ( - TErrorResult<::std::os::raw::c_int> ) )); - assert_eq!(::std::mem::align_of::<TErrorResult<::std::os::raw::c_int>>() , - 8usize , concat ! ( + TErrorResult ) )); + assert_eq!(::std::mem::align_of::<TErrorResult>() , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( - TErrorResult<::std::os::raw::c_int> ) )); + TErrorResult ) )); } diff --git a/tests/expectations/tests/auto.rs b/tests/expectations/tests/auto.rs index 4551f703..7f9bbf44 100644 --- a/tests/expectations/tests/auto.rs +++ b/tests/expectations/tests/auto.rs @@ -21,13 +21,9 @@ impl Clone for Foo { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct Bar<T> { +#[derive(Debug, Default, Copy, Clone)] +pub struct Bar { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<T>, -} -impl <T> Default for Bar<T> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } } extern "C" { #[link_name = "_Z5Test2v"] diff --git a/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs b/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs index b0c91e8c..4074dd02 100644 --- a/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs +++ b/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs @@ -5,13 +5,9 @@ #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct std_char_traits<_CharT> { +#[derive(Debug, Default, Copy, Clone)] +pub struct std_char_traits { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<_CharT>, -} -impl <_CharT> Default for std_char_traits<_CharT> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] #[derive(Debug, Default, Copy)] diff --git a/tests/expectations/tests/class_nested.rs b/tests/expectations/tests/class_nested.rs index 6ddcf91b..b92976f6 100644 --- a/tests/expectations/tests/class_nested.rs +++ b/tests/expectations/tests/class_nested.rs @@ -77,7 +77,7 @@ extern "C" { pub static mut var: A_B; } #[test] -fn __bindgen_test_layout_template_1() { +fn __bindgen_test_layout_A_D_instantiation_16() { assert_eq!(::std::mem::size_of::<A_D<::std::os::raw::c_int>>() , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( diff --git a/tests/expectations/tests/class_with_dtor.rs b/tests/expectations/tests/class_with_dtor.rs index 4c1d2718..495889f2 100644 --- a/tests/expectations/tests/class_with_dtor.rs +++ b/tests/expectations/tests/class_with_dtor.rs @@ -34,7 +34,7 @@ impl Default for WithoutDtor { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[test] -fn __bindgen_test_layout_template_1() { +fn __bindgen_test_layout_HandleWithDtor_instantiation_10() { assert_eq!(::std::mem::size_of::<HandleWithDtor<::std::os::raw::c_int>>() , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( diff --git a/tests/expectations/tests/constant-non-specialized-tp.rs b/tests/expectations/tests/constant-non-specialized-tp.rs index f2aa5a75..a17e261b 100644 --- a/tests/expectations/tests/constant-non-specialized-tp.rs +++ b/tests/expectations/tests/constant-non-specialized-tp.rs @@ -5,26 +5,17 @@ #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct Test<Args> { +#[derive(Debug, Default, Copy, Clone)] +pub struct Test { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<Args>, -} -impl <Args> Default for Test<Args> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct Outer<T> { +#[derive(Debug, Default, Copy, Clone)] +pub struct Outer { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<T>, } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] -pub struct Outer_Inner<T> { +pub struct Outer_Inner { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<T>, -} -impl <T> Default for Outer<T> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } } diff --git a/tests/expectations/tests/constructor-tp.rs b/tests/expectations/tests/constructor-tp.rs index ee04d3c5..6ba52f22 100644 --- a/tests/expectations/tests/constructor-tp.rs +++ b/tests/expectations/tests/constructor-tp.rs @@ -5,13 +5,9 @@ #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct Foo<T> { +#[derive(Debug, Default, Copy, Clone)] +pub struct Foo { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<T>, -} -impl <T> Default for Foo<T> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] #[derive(Debug, Default, Copy)] diff --git a/tests/expectations/tests/crtp.rs b/tests/expectations/tests/crtp.rs index 7143f50e..8a83e198 100644 --- a/tests/expectations/tests/crtp.rs +++ b/tests/expectations/tests/crtp.rs @@ -5,13 +5,9 @@ #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct Base<T> { +#[derive(Debug, Default, Copy, Clone)] +pub struct Base { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<T>, -} -impl <T> Default for Base<T> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] #[derive(Debug, Copy)] @@ -32,13 +28,9 @@ impl Default for Derived { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug)] -pub struct BaseWithDestructor<T> { +#[derive(Debug, Default)] +pub struct BaseWithDestructor { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<T>, -} -impl <T> Default for BaseWithDestructor<T> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] #[derive(Debug)] @@ -59,22 +51,21 @@ impl Default for DerivedFromBaseWithDestructor { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[test] -fn __bindgen_test_layout_template_1() { - assert_eq!(::std::mem::size_of::<Base<Derived>>() , 1usize , concat ! ( - "Size of template specialization: " , stringify ! ( - Base<Derived> ) )); - assert_eq!(::std::mem::align_of::<Base<Derived>>() , 1usize , concat ! ( - "Alignment of template specialization: " , stringify ! ( - Base<Derived> ) )); +fn __bindgen_test_layout_Base_instantiation_9() { + assert_eq!(::std::mem::size_of::<Base>() , 1usize , concat ! ( + "Size of template specialization: " , stringify ! ( Base ) )); + assert_eq!(::std::mem::align_of::<Base>() , 1usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( Base ) + )); } #[test] -fn __bindgen_test_layout_template_2() { - assert_eq!(::std::mem::size_of::<BaseWithDestructor<DerivedFromBaseWithDestructor>>() - , 1usize , concat ! ( +fn __bindgen_test_layout_BaseWithDestructor_instantiation_12() { + assert_eq!(::std::mem::size_of::<BaseWithDestructor>() , 1usize , concat ! + ( "Size of template specialization: " , stringify ! ( - BaseWithDestructor<DerivedFromBaseWithDestructor> ) )); - assert_eq!(::std::mem::align_of::<BaseWithDestructor<DerivedFromBaseWithDestructor>>() - , 1usize , concat ! ( + BaseWithDestructor ) )); + assert_eq!(::std::mem::align_of::<BaseWithDestructor>() , 1usize , concat + ! ( "Alignment of template specialization: " , stringify ! ( - BaseWithDestructor<DerivedFromBaseWithDestructor> ) )); + BaseWithDestructor ) )); } diff --git a/tests/expectations/tests/dash_language.rs b/tests/expectations/tests/dash_language.rs index 24df1014..385c39c6 100644 --- a/tests/expectations/tests/dash_language.rs +++ b/tests/expectations/tests/dash_language.rs @@ -5,11 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct Foo<T> { +#[derive(Debug, Default, Copy, Clone)] +pub struct Foo { pub bar: ::std::os::raw::c_int, - pub _phantom_0: ::std::marker::PhantomData<T>, -} -impl <T> Default for Foo<T> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } } diff --git a/tests/expectations/tests/empty_template_param_name.rs b/tests/expectations/tests/empty_template_param_name.rs index 6ee8fce3..2bd5a570 100644 --- a/tests/expectations/tests/empty_template_param_name.rs +++ b/tests/expectations/tests/empty_template_param_name.rs @@ -6,11 +6,7 @@ pub type __void_t = ::std::os::raw::c_void; #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct __iterator_traits<_Iterator> { +#[derive(Debug, Default, Copy, Clone)] +pub struct __iterator_traits { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<_Iterator>, -} -impl <_Iterator> Default for __iterator_traits<_Iterator> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } } diff --git a/tests/expectations/tests/enum_in_template_with_typedef.rs b/tests/expectations/tests/enum_in_template_with_typedef.rs index e4725b83..2b956963 100644 --- a/tests/expectations/tests/enum_in_template_with_typedef.rs +++ b/tests/expectations/tests/enum_in_template_with_typedef.rs @@ -5,10 +5,9 @@ #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct std_fbstring_core<Char> { +#[derive(Debug, Default, Copy, Clone)] +pub struct std_fbstring_core { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<Char>, } pub type std_fbstring_core_category_type = u8; pub const std_fbstring_core_Category_Bar: std_fbstring_core_Category = @@ -16,6 +15,3 @@ pub const std_fbstring_core_Category_Bar: std_fbstring_core_Category = #[repr(u8)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum std_fbstring_core_Category { Foo = 0, } -impl <Char> Default for std_fbstring_core<Char> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } -} diff --git a/tests/expectations/tests/eval-variadic-template-parameter.rs b/tests/expectations/tests/eval-variadic-template-parameter.rs index acc6f34c..701aab9f 100644 --- a/tests/expectations/tests/eval-variadic-template-parameter.rs +++ b/tests/expectations/tests/eval-variadic-template-parameter.rs @@ -5,11 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct B<T> { +#[derive(Debug, Default, Copy, Clone)] +pub struct B { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<T>, -} -impl <T> Default for B<T> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } } diff --git a/tests/expectations/tests/forward-inherit-struct.rs b/tests/expectations/tests/forward-inherit-struct.rs index 1057e70c..322854dd 100644 --- a/tests/expectations/tests/forward-inherit-struct.rs +++ b/tests/expectations/tests/forward-inherit-struct.rs @@ -6,19 +6,14 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct Rooted<T> { +pub struct Rooted { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<T>, } -impl <T> Default for Rooted<T> { +impl Default for Rooted { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct js_RootedBase<T> { +#[derive(Debug, Default, Copy, Clone)] +pub struct js_RootedBase { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<T>, -} -impl <T> Default for js_RootedBase<T> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } } diff --git a/tests/expectations/tests/in_class_typedef.rs b/tests/expectations/tests/in_class_typedef.rs index 3634a631..613c8cab 100644 --- a/tests/expectations/tests/in_class_typedef.rs +++ b/tests/expectations/tests/in_class_typedef.rs @@ -5,20 +5,15 @@ #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct Foo<T> { +#[derive(Debug, Default, Copy, Clone)] +pub struct Foo { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<T>, } pub type Foo_elem_type<T> = T; pub type Foo_ptr_type<T> = *mut T; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] -pub struct Foo_Bar<T> { +pub struct Foo_Bar { pub x: ::std::os::raw::c_int, pub y: ::std::os::raw::c_int, - pub _phantom_0: ::std::marker::PhantomData<T>, -} -impl <T> Default for Foo<T> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } } diff --git a/tests/expectations/tests/inherit-namespaced.rs b/tests/expectations/tests/inherit-namespaced.rs index e5d5f875..fcd8de97 100644 --- a/tests/expectations/tests/inherit-namespaced.rs +++ b/tests/expectations/tests/inherit-namespaced.rs @@ -5,20 +5,15 @@ #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct js_RootedBase<T> { +#[derive(Debug, Default, Copy, Clone)] +pub struct js_RootedBase { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<T>, -} -impl <T> Default for js_RootedBase<T> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct Rooted<T> { +pub struct Rooted { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<T>, } -impl <T> Default for Rooted<T> { +impl Default for Rooted { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } diff --git a/tests/expectations/tests/inherit_named.rs b/tests/expectations/tests/inherit_named.rs index 31c4bee9..703df9ea 100644 --- a/tests/expectations/tests/inherit_named.rs +++ b/tests/expectations/tests/inherit_named.rs @@ -5,13 +5,9 @@ #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct Wohoo<T> { +#[derive(Debug, Default, Copy, Clone)] +pub struct Wohoo { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<T>, -} -impl <T> Default for Wohoo<T> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/tests/expectations/tests/inner_template_self.rs b/tests/expectations/tests/inner_template_self.rs index 3510fa7c..d75c280d 100644 --- a/tests/expectations/tests/inner_template_self.rs +++ b/tests/expectations/tests/inner_template_self.rs @@ -6,17 +6,17 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct LinkedList<T> { - pub next: *mut LinkedList<T>, - pub prev: *mut LinkedList<T>, +pub struct LinkedList { + pub next: *mut LinkedList, + pub prev: *mut LinkedList, } -impl <T> Default for LinkedList<T> { +impl Default for LinkedList { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] #[derive(Debug, Copy)] pub struct InstantiateIt { - pub m_list: LinkedList<::std::os::raw::c_int>, + pub m_list: LinkedList, } #[test] fn bindgen_test_layout_InstantiateIt() { diff --git a/tests/expectations/tests/issue-358.rs b/tests/expectations/tests/issue-358.rs index d3be3c43..e574bd01 100644 --- a/tests/expectations/tests/issue-358.rs +++ b/tests/expectations/tests/issue-358.rs @@ -6,11 +6,10 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct JS_PersistentRooted<c> { +pub struct JS_PersistentRooted { pub _base: a, - pub _phantom_0: ::std::marker::PhantomData<c>, } -impl <c> Default for JS_PersistentRooted<c> { +impl Default for JS_PersistentRooted { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] diff --git a/tests/expectations/tests/issue-446.rs b/tests/expectations/tests/issue-446.rs index fa736bcc..13204c1a 100644 --- a/tests/expectations/tests/issue-446.rs +++ b/tests/expectations/tests/issue-446.rs @@ -6,17 +6,17 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct List<Elem> { - pub next: *mut List<Elem>, +pub struct List { + pub next: *mut List, } -impl <Elem> Default for List<Elem> { +impl Default for List { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct PersistentRooted<GcThing> { - pub root_list: List<PersistentRooted<GcThing>>, +pub struct PersistentRooted { + pub root_list: List, } -impl <GcThing> Default for PersistentRooted<GcThing> { +impl Default for PersistentRooted { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } diff --git a/tests/expectations/tests/issue-493.rs b/tests/expectations/tests/issue-493.rs index a2246ca6..155834a3 100644 --- a/tests/expectations/tests/issue-493.rs +++ b/tests/expectations/tests/issue-493.rs @@ -29,28 +29,21 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> { } } #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct basic_string<_CharT, _Traits, _Allocator> { +#[derive(Debug, Default, Copy, Clone)] +pub struct basic_string { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<_CharT>, - pub _phantom_1: ::std::marker::PhantomData<_Traits>, - pub _phantom_2: ::std::marker::PhantomData<_Allocator>, } pub type basic_string_size_type = ::std::os::raw::c_ulonglong; pub type basic_string_value_type = ::std::os::raw::c_schar; pub type basic_string_pointer = *mut basic_string_value_type; #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct basic_string___long<_CharT, _Traits, _Allocator> { +pub struct basic_string___long { pub __cap_: basic_string_size_type, pub __size_: basic_string_size_type, pub __data_: basic_string_pointer, - pub _phantom_0: ::std::marker::PhantomData<_CharT>, - pub _phantom_1: ::std::marker::PhantomData<_Traits>, - pub _phantom_2: ::std::marker::PhantomData<_Allocator>, } -impl <_CharT, _Traits, _Allocator> Default for - basic_string___long<_CharT, _Traits, _Allocator> { +impl Default for basic_string___long { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } pub const basic_string___min_cap: basic_string__bindgen_ty_1 = @@ -60,42 +53,28 @@ pub const basic_string___min_cap: basic_string__bindgen_ty_1 = pub enum basic_string__bindgen_ty_1 { __min_cap = 0, } #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct basic_string___short<_CharT, _Traits, _Allocator> { - pub __bindgen_anon_1: basic_string___short__bindgen_ty_1<_CharT, _Traits, - _Allocator>, +pub struct basic_string___short { + pub __bindgen_anon_1: basic_string___short__bindgen_ty_1, pub __data_: *mut basic_string_value_type, - pub _phantom_0: ::std::marker::PhantomData<_CharT>, - pub _phantom_1: ::std::marker::PhantomData<_Traits>, - pub _phantom_2: ::std::marker::PhantomData<_Allocator>, } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] -pub struct basic_string___short__bindgen_ty_1<_CharT, _Traits, _Allocator> { +pub struct basic_string___short__bindgen_ty_1 { pub __size_: __BindgenUnionField<::std::os::raw::c_uchar>, pub __lx: __BindgenUnionField<basic_string_value_type>, pub bindgen_union_field: u8, - pub _phantom_0: ::std::marker::PhantomData<_CharT>, - pub _phantom_1: ::std::marker::PhantomData<_Traits>, - pub _phantom_2: ::std::marker::PhantomData<_Allocator>, } -impl <_CharT, _Traits, _Allocator> Default for - basic_string___short<_CharT, _Traits, _Allocator> { +impl Default for basic_string___short { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] #[derive(Copy, Clone)] -pub struct basic_string___ulx<_CharT, _Traits, _Allocator> { - pub __lx: __BindgenUnionField<basic_string___long<_CharT, _Traits, - _Allocator>>, - pub __lxx: __BindgenUnionField<basic_string___short<_CharT, _Traits, - _Allocator>>, +pub struct basic_string___ulx { + pub __lx: __BindgenUnionField<basic_string___long>, + pub __lxx: __BindgenUnionField<basic_string___short>, pub bindgen_union_field: [u8; 0usize], - pub _phantom_0: ::std::marker::PhantomData<_CharT>, - pub _phantom_1: ::std::marker::PhantomData<_Traits>, - pub _phantom_2: ::std::marker::PhantomData<_Allocator>, } -impl <_CharT, _Traits, _Allocator> Default for - basic_string___ulx<_CharT, _Traits, _Allocator> { +impl Default for basic_string___ulx { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } pub const basic_string___n_words: basic_string__bindgen_ty_2 = @@ -105,48 +84,28 @@ pub const basic_string___n_words: basic_string__bindgen_ty_2 = pub enum basic_string__bindgen_ty_2 { __n_words = 0, } #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct basic_string___raw<_CharT, _Traits, _Allocator> { +pub struct basic_string___raw { pub __words: *mut basic_string_size_type, - pub _phantom_0: ::std::marker::PhantomData<_CharT>, - pub _phantom_1: ::std::marker::PhantomData<_Traits>, - pub _phantom_2: ::std::marker::PhantomData<_Allocator>, } -impl <_CharT, _Traits, _Allocator> Default for - basic_string___raw<_CharT, _Traits, _Allocator> { +impl Default for basic_string___raw { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] #[derive(Copy, Clone)] -pub struct basic_string___rep<_CharT, _Traits, _Allocator> { - pub __bindgen_anon_1: basic_string___rep__bindgen_ty_1<_CharT, _Traits, - _Allocator>, - pub _phantom_0: ::std::marker::PhantomData<_CharT>, - pub _phantom_1: ::std::marker::PhantomData<_Traits>, - pub _phantom_2: ::std::marker::PhantomData<_Allocator>, +pub struct basic_string___rep { + pub __bindgen_anon_1: basic_string___rep__bindgen_ty_1, } #[repr(C)] #[derive(Copy, Clone)] -pub struct basic_string___rep__bindgen_ty_1<_CharT, _Traits, _Allocator> { - pub __l: __BindgenUnionField<basic_string___long<_CharT, _Traits, - _Allocator>>, - pub __s: __BindgenUnionField<basic_string___short<_CharT, _Traits, - _Allocator>>, - pub __r: __BindgenUnionField<basic_string___raw<_CharT, _Traits, - _Allocator>>, +pub struct basic_string___rep__bindgen_ty_1 { + pub __l: __BindgenUnionField<basic_string___long>, + pub __s: __BindgenUnionField<basic_string___short>, + pub __r: __BindgenUnionField<basic_string___raw>, pub bindgen_union_field: [u8; 0usize], - pub _phantom_0: ::std::marker::PhantomData<_CharT>, - pub _phantom_1: ::std::marker::PhantomData<_Traits>, - pub _phantom_2: ::std::marker::PhantomData<_Allocator>, -} -impl <_CharT, _Traits, _Allocator> Default for - basic_string___rep__bindgen_ty_1<_CharT, _Traits, _Allocator> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } } -impl <_CharT, _Traits, _Allocator> Default for - basic_string___rep<_CharT, _Traits, _Allocator> { +impl Default for basic_string___rep__bindgen_ty_1 { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } -impl <_CharT, _Traits, _Allocator> Default for - basic_string<_CharT, _Traits, _Allocator> { +impl Default for basic_string___rep { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } diff --git a/tests/expectations/tests/issue-544-stylo-creduce-2.rs b/tests/expectations/tests/issue-544-stylo-creduce-2.rs new file mode 100644 index 00000000..c0fae845 --- /dev/null +++ b/tests/expectations/tests/issue-544-stylo-creduce-2.rs @@ -0,0 +1,15 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +pub struct Foo { + pub member: Foo_SecondAlias, +} +pub type Foo_FirstAlias = [u8; 0usize]; +pub type Foo_SecondAlias = [u8; 0usize]; +impl Default for Foo { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/issue-544-stylo-creduce.rs b/tests/expectations/tests/issue-544-stylo-creduce.rs new file mode 100644 index 00000000..88cc0d87 --- /dev/null +++ b/tests/expectations/tests/issue-544-stylo-creduce.rs @@ -0,0 +1,14 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Default, Copy)] +pub struct a { + pub _address: u8, +} +impl Clone for a { + fn clone(&self) -> Self { *self } +} diff --git a/tests/expectations/tests/maddness-is-avoidable.rs b/tests/expectations/tests/maddness-is-avoidable.rs index 2fb5e540..09c1c921 100644 --- a/tests/expectations/tests/maddness-is-avoidable.rs +++ b/tests/expectations/tests/maddness-is-avoidable.rs @@ -5,22 +5,12 @@ #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct RefPtr<T> { +#[derive(Debug, Default, Copy, Clone)] +pub struct RefPtr { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<T>, } #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct RefPtr_Proxy<T, R, Args> { +#[derive(Debug, Default, Copy, Clone)] +pub struct RefPtr_Proxy { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<T>, - pub _phantom_1: ::std::marker::PhantomData<R>, - pub _phantom_2: ::std::marker::PhantomData<Args>, -} -impl <T, R, Args> Default for RefPtr_Proxy<T, R, Args> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } -} -impl <T> Default for RefPtr<T> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } } diff --git a/tests/expectations/tests/no_copy.rs b/tests/expectations/tests/no_copy.rs index 3590241f..a75f891c 100644 --- a/tests/expectations/tests/no_copy.rs +++ b/tests/expectations/tests/no_copy.rs @@ -6,11 +6,7 @@ /** <div rustbindgen nocopy></div> */ #[repr(C)] -#[derive(Debug)] -pub struct CopiableButWait<T> { +#[derive(Debug, Default)] +pub struct CopiableButWait { pub whatever: ::std::os::raw::c_int, - pub _phantom_0: ::std::marker::PhantomData<T>, -} -impl <T> Default for CopiableButWait<T> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } } diff --git a/tests/expectations/tests/opaque_pointer.rs b/tests/expectations/tests/opaque_pointer.rs index 15b01db4..2e1890a8 100644 --- a/tests/expectations/tests/opaque_pointer.rs +++ b/tests/expectations/tests/opaque_pointer.rs @@ -27,16 +27,15 @@ impl Clone for OtherOpaque { */ #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct Opaque<T> { - pub _phantom_0: ::std::marker::PhantomData<T>, +pub struct Opaque { } -impl <T> Default for Opaque<T> { +impl Default for Opaque { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] #[derive(Debug, Copy)] pub struct WithOpaquePtr { - pub whatever: *mut Opaque<::std::os::raw::c_int>, + pub whatever: *mut (), pub other: u32, pub t: OtherOpaque, } diff --git a/tests/expectations/tests/opaque_typedef.rs b/tests/expectations/tests/opaque_typedef.rs index d6d5ac5d..51951faf 100644 --- a/tests/expectations/tests/opaque_typedef.rs +++ b/tests/expectations/tests/opaque_typedef.rs @@ -5,14 +5,10 @@ #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct RandomTemplate<T> { +#[derive(Debug, Default, Copy, Clone)] +pub struct RandomTemplate { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<T>, -} -impl <T> Default for RandomTemplate<T> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } } /** <div rustbindgen opaque></div> */ pub type ShouldBeOpaque = [u8; 0usize]; -pub type ShouldNotBeOpaque = RandomTemplate<f32>; +pub type ShouldNotBeOpaque = RandomTemplate; diff --git a/tests/expectations/tests/partial-specialization-and-inheritance.rs b/tests/expectations/tests/partial-specialization-and-inheritance.rs new file mode 100644 index 00000000..24225934 --- /dev/null +++ b/tests/expectations/tests/partial-specialization-and-inheritance.rs @@ -0,0 +1,44 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Base { + pub _address: u8, +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Derived { + pub b: bool, +} +#[test] +fn __bindgen_test_layout__bindgen_ty_id_20_instantiation_14() { + assert_eq!(::std::mem::size_of::<[u32; 2usize]>() , 8usize , concat ! ( + "Size of template specialization: " , stringify ! ( + [u32; 2usize] ) )); + assert_eq!(::std::mem::align_of::<[u32; 2usize]>() , 4usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( + [u32; 2usize] ) )); +} +#[repr(C)] +#[derive(Debug, Default, Copy)] +pub struct Usage { + pub _address: u8, +} +extern "C" { + #[link_name = "_ZN5Usage13static_memberE"] + pub static mut Usage_static_member: [u32; 2usize]; +} +#[test] +fn bindgen_test_layout_Usage() { + assert_eq!(::std::mem::size_of::<Usage>() , 1usize , concat ! ( + "Size of: " , stringify ! ( Usage ) )); + assert_eq! (::std::mem::align_of::<Usage>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Usage ) )); +} +impl Clone for Usage { + fn clone(&self) -> Self { *self } +} diff --git a/tests/expectations/tests/replace_use.rs b/tests/expectations/tests/replace_use.rs index d93121d3..6cdc3263 100644 --- a/tests/expectations/tests/replace_use.rs +++ b/tests/expectations/tests/replace_use.rs @@ -8,18 +8,14 @@ * <div rustbindgen replaces="nsTArray"></div> */ #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct nsTArray<T> { +#[derive(Debug, Default, Copy, Clone)] +pub struct nsTArray { pub y: ::std::os::raw::c_uint, - pub _phantom_0: ::std::marker::PhantomData<T>, -} -impl <T> Default for nsTArray<T> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] #[derive(Debug, Copy)] pub struct Test { - pub a: nsTArray<::std::os::raw::c_long>, + pub a: nsTArray, } #[test] fn bindgen_test_layout_Test() { diff --git a/tests/expectations/tests/size_t_template.rs b/tests/expectations/tests/size_t_template.rs index 4d81651e..b2680869 100644 --- a/tests/expectations/tests/size_t_template.rs +++ b/tests/expectations/tests/size_t_template.rs @@ -5,7 +5,6 @@ #[repr(C)] -#[derive(Debug, Copy)] pub struct C { pub arr: [u32; 3usize], } @@ -21,9 +20,6 @@ fn bindgen_test_layout_C() { "Alignment of field: " , stringify ! ( C ) , "::" , stringify ! ( arr ) )); } -impl Clone for C { - fn clone(&self) -> Self { *self } -} impl Default for C { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } diff --git a/tests/expectations/tests/struct_with_typedef_template_arg.rs b/tests/expectations/tests/struct_with_typedef_template_arg.rs index f882c65d..93620e59 100644 --- a/tests/expectations/tests/struct_with_typedef_template_arg.rs +++ b/tests/expectations/tests/struct_with_typedef_template_arg.rs @@ -5,14 +5,9 @@ #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct Proxy<T, Args> { +#[derive(Debug, Default, Copy, Clone)] +pub struct Proxy { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<T>, - pub _phantom_1: ::std::marker::PhantomData<Args>, } pub type Proxy_foo<T> = ::std::option::Option<unsafe extern "C" fn(bar: *mut T)>; -impl <T, Args> Default for Proxy<T, Args> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } -} diff --git a/tests/expectations/tests/template-fun-ty.rs b/tests/expectations/tests/template-fun-ty.rs index b894920f..05351d7d 100644 --- a/tests/expectations/tests/template-fun-ty.rs +++ b/tests/expectations/tests/template-fun-ty.rs @@ -5,36 +5,22 @@ #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct Foo<T> { +#[derive(Debug, Default, Copy, Clone)] +pub struct Foo { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<T>, } pub type Foo_FunctionPtr<T> = ::std::option::Option<unsafe extern "C" fn() -> T>; -impl <T> Default for Foo<T> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } -} #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct RefPtr<T> { +#[derive(Debug, Default, Copy, Clone)] +pub struct RefPtr { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<T>, } #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct RefPtr_Proxy<T, R, Args> { +#[derive(Debug, Default, Copy, Clone)] +pub struct RefPtr_Proxy { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<T>, - pub _phantom_1: ::std::marker::PhantomData<R>, - pub _phantom_2: ::std::marker::PhantomData<Args>, } pub type RefPtr_Proxy_member_function<R, Args> = ::std::option::Option<unsafe extern "C" fn(arg1: Args) -> R>; -impl <T, R, Args> Default for RefPtr_Proxy<T, R, Args> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } -} -impl <T> Default for RefPtr<T> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } -} pub type Returner<T> = ::std::option::Option<unsafe extern "C" fn() -> T>; diff --git a/tests/expectations/tests/template-param-usage-0.rs b/tests/expectations/tests/template-param-usage-0.rs new file mode 100644 index 00000000..494001f7 --- /dev/null +++ b/tests/expectations/tests/template-param-usage-0.rs @@ -0,0 +1,14 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct UsesTemplateParameter<T> { + pub t: T, +} +impl <T> Default for UsesTemplateParameter<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/template-param-usage-1.rs b/tests/expectations/tests/template-param-usage-1.rs new file mode 100644 index 00000000..0fd8719b --- /dev/null +++ b/tests/expectations/tests/template-param-usage-1.rs @@ -0,0 +1,11 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct DoesNotUseTemplateParameter { + pub x: ::std::os::raw::c_int, +} diff --git a/tests/expectations/tests/template-param-usage-10.rs b/tests/expectations/tests/template-param-usage-10.rs new file mode 100644 index 00000000..95d200b5 --- /dev/null +++ b/tests/expectations/tests/template-param-usage-10.rs @@ -0,0 +1,25 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct DoublyIndirectUsage<T, U> { + pub doubly_indirect: DoublyIndirectUsage_IndirectUsage<T, U>, +} +pub type DoublyIndirectUsage_Aliased<T> = T; +pub type DoublyIndirectUsage_Typedefed<U> = U; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct DoublyIndirectUsage_IndirectUsage<T, U> { + pub member: DoublyIndirectUsage_Aliased<T>, + pub another: DoublyIndirectUsage_Typedefed<U>, +} +impl <T, U> Default for DoublyIndirectUsage_IndirectUsage<T, U> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} +impl <T, U> Default for DoublyIndirectUsage<T, U> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/template-param-usage-11.rs b/tests/expectations/tests/template-param-usage-11.rs new file mode 100644 index 00000000..a8959b99 --- /dev/null +++ b/tests/expectations/tests/template-param-usage-11.rs @@ -0,0 +1,11 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct DoesNotUseT { + pub _address: u8, +} diff --git a/tests/expectations/tests/template-param-usage-12.rs b/tests/expectations/tests/template-param-usage-12.rs new file mode 100644 index 00000000..0c31111e --- /dev/null +++ b/tests/expectations/tests/template-param-usage-12.rs @@ -0,0 +1,23 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct BaseUsesT<T> { + pub t: *mut T, +} +impl <T> Default for BaseUsesT<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CrtpUsesU<U> { + pub _base: BaseUsesT<CrtpUsesU<U>>, + pub usage: U, +} +impl <U> Default for CrtpUsesU<U> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/template-param-usage-13.rs b/tests/expectations/tests/template-param-usage-13.rs new file mode 100644 index 00000000..c77da097 --- /dev/null +++ b/tests/expectations/tests/template-param-usage-13.rs @@ -0,0 +1,20 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct BaseIgnoresT { + pub x: ::std::os::raw::c_int, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CrtpUsesU<U> { + pub _base: BaseIgnoresT, + pub usage: U, +} +impl <U> Default for CrtpUsesU<U> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/template-param-usage-14.rs b/tests/expectations/tests/template-param-usage-14.rs new file mode 100644 index 00000000..fae4afdc --- /dev/null +++ b/tests/expectations/tests/template-param-usage-14.rs @@ -0,0 +1,20 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct BaseIgnoresT { + pub x: ::std::os::raw::c_int, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CrtpIgnoresU { + pub _base: BaseIgnoresT, + pub y: ::std::os::raw::c_int, +} +impl Default for CrtpIgnoresU { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/template-param-usage-15.rs b/tests/expectations/tests/template-param-usage-15.rs new file mode 100644 index 00000000..a653e089 --- /dev/null +++ b/tests/expectations/tests/template-param-usage-15.rs @@ -0,0 +1,23 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct BaseUsesT<T> { + pub usage: *mut T, +} +impl <T> Default for BaseUsesT<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CrtpIgnoresU { + pub _base: BaseUsesT<CrtpIgnoresU>, + pub y: ::std::os::raw::c_int, +} +impl Default for CrtpIgnoresU { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/template-param-usage-2.rs b/tests/expectations/tests/template-param-usage-2.rs new file mode 100644 index 00000000..6dc21b68 --- /dev/null +++ b/tests/expectations/tests/template-param-usage-2.rs @@ -0,0 +1,22 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct UsesTemplateParameter<T> { + pub t: T, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct UsesTemplateParameter_AlsoUsesTemplateParameter<T> { + pub also: T, +} +impl <T> Default for UsesTemplateParameter_AlsoUsesTemplateParameter<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} +impl <T> Default for UsesTemplateParameter<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/template-param-usage-3.rs b/tests/expectations/tests/template-param-usage-3.rs new file mode 100644 index 00000000..a7ff22f9 --- /dev/null +++ b/tests/expectations/tests/template-param-usage-3.rs @@ -0,0 +1,24 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct UsesTemplateParameter<T> { + pub t: T, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct UsesTemplateParameter_AlsoUsesTemplateParameterAndMore<T, U> { + pub also: T, + pub more: U, +} +impl <T, U> Default for + UsesTemplateParameter_AlsoUsesTemplateParameterAndMore<T, U> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} +impl <T> Default for UsesTemplateParameter<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/template-param-usage-4.rs b/tests/expectations/tests/template-param-usage-4.rs new file mode 100644 index 00000000..31f8872d --- /dev/null +++ b/tests/expectations/tests/template-param-usage-4.rs @@ -0,0 +1,19 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct UsesTemplateParameter<T> { + pub t: T, +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct UsesTemplateParameter_DoesNotUseTemplateParameters { + pub x: ::std::os::raw::c_int, +} +impl <T> Default for UsesTemplateParameter<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/template-param-usage-5.rs b/tests/expectations/tests/template-param-usage-5.rs new file mode 100644 index 00000000..5a9caf32 --- /dev/null +++ b/tests/expectations/tests/template-param-usage-5.rs @@ -0,0 +1,15 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct IndirectlyUsesTemplateParameter<T> { + pub aliased: IndirectlyUsesTemplateParameter_Aliased<T>, +} +pub type IndirectlyUsesTemplateParameter_Aliased<T> = T; +impl <T> Default for IndirectlyUsesTemplateParameter<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/template-param-usage-6.rs b/tests/expectations/tests/template-param-usage-6.rs new file mode 100644 index 00000000..37b7fe64 --- /dev/null +++ b/tests/expectations/tests/template-param-usage-6.rs @@ -0,0 +1,12 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct DoesNotUseTemplateParameter { + pub x: ::std::os::raw::c_int, +} +pub type DoesNotUseTemplateParameter_ButAliasDoesUseIt<T> = T; diff --git a/tests/expectations/tests/template-param-usage-7.rs b/tests/expectations/tests/template-param-usage-7.rs new file mode 100644 index 00000000..b0584479 --- /dev/null +++ b/tests/expectations/tests/template-param-usage-7.rs @@ -0,0 +1,16 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct DoesNotUseU<T, V> { + pub t: T, + pub v: V, +} +impl <T, V> Default for DoesNotUseU<T, V> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} +pub type Alias = DoesNotUseU<::std::os::raw::c_int, ::std::os::raw::c_schar>; diff --git a/tests/expectations/tests/template-param-usage-8.rs b/tests/expectations/tests/template-param-usage-8.rs new file mode 100644 index 00000000..b181cc09 --- /dev/null +++ b/tests/expectations/tests/template-param-usage-8.rs @@ -0,0 +1,17 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct IndirectUsage<T, U> { + pub member1: IndirectUsage_Typedefed<T>, + pub member2: IndirectUsage_Aliased<U>, +} +pub type IndirectUsage_Typedefed<T> = T; +pub type IndirectUsage_Aliased<U> = U; +impl <T, U> Default for IndirectUsage<T, U> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/template-param-usage-9.rs b/tests/expectations/tests/template-param-usage-9.rs new file mode 100644 index 00000000..d0a3f29f --- /dev/null +++ b/tests/expectations/tests/template-param-usage-9.rs @@ -0,0 +1,22 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct DoesNotUse { + pub _address: u8, +} +pub type DoesNotUse_Aliased<T> = T; +pub type DoesNotUse_Typedefed<U> = U; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct DoesNotUse_IndirectUsage<T, U> { + pub member: DoesNotUse_Aliased<T>, + pub another: DoesNotUse_Typedefed<U>, +} +impl <T, U> Default for DoesNotUse_IndirectUsage<T, U> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/expectations/tests/template.rs b/tests/expectations/tests/template.rs index 3c829f07..911b0e6a 100644 --- a/tests/expectations/tests/template.rs +++ b/tests/expectations/tests/template.rs @@ -6,37 +6,34 @@ #[repr(C)] #[derive(Debug)] -pub struct Foo<T, U> { +pub struct Foo<T> { pub m_member: T, pub m_member_ptr: *mut T, pub m_member_arr: [T; 1usize], - pub _phantom_1: ::std::marker::PhantomData<U>, } -impl <T, U> Default for Foo<T, U> { +impl <T> Default for Foo<T> { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } extern "C" { #[link_name = "_Z3bar3FooIiiE"] - pub fn bar(foo: Foo<::std::os::raw::c_int, ::std::os::raw::c_int>); + pub fn bar(foo: Foo<::std::os::raw::c_int>); } #[repr(C)] #[derive(Debug)] -pub struct D<T> { +pub struct D { pub m_foo: D_MyFoo, - pub _phantom_0: ::std::marker::PhantomData<T>, } -pub type D_MyFoo = Foo<::std::os::raw::c_int, ::std::os::raw::c_int>; +pub type D_MyFoo = Foo<::std::os::raw::c_int>; #[repr(C)] #[derive(Debug)] -pub struct D_U<T, Z> { +pub struct D_U<Z> { pub m_nested_foo: D_MyFoo, pub m_baz: Z, - pub _phantom_0: ::std::marker::PhantomData<T>, } -impl <T, Z> Default for D_U<T, Z> { +impl <Z> Default for D_U<Z> { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } -impl <T> Default for D<T> { +impl Default for D { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] @@ -104,10 +101,9 @@ impl Default for PODButContainsDtor { /** <div rustbindgen opaque> */ #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct Opaque<T> { - pub _phantom_0: ::std::marker::PhantomData<T>, +pub struct Opaque { } -impl <T> Default for Opaque<T> { +impl Default for Opaque { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] @@ -143,11 +139,10 @@ impl <T> Default for NestedReplaced<T> { } #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct NestedBase<T, U> { +pub struct NestedBase<T> { pub buff: *mut T, - pub _phantom_1: ::std::marker::PhantomData<U>, } -impl <T, U> Default for NestedBase<T, U> { +impl <T> Default for NestedBase<T> { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] @@ -184,13 +179,9 @@ impl Clone for Untemplated { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct Templated<T> { +#[derive(Debug, Default, Copy, Clone)] +pub struct Templated { pub m_untemplated: Untemplated, - pub _phantom_0: ::std::marker::PhantomData<T>, -} -impl <T> Default for Templated<T> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } } /** * If the replacement doesn't happen at the parse level the container would be @@ -237,27 +228,23 @@ impl <T> Default for ReplacedWithoutDestructorFwd<T> { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct TemplateWithVar<T> { +#[derive(Debug, Default, Copy, Clone)] +pub struct TemplateWithVar { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<T>, -} -impl <T> Default for TemplateWithVar<T> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[test] -fn __bindgen_test_layout_template_1() { - assert_eq!(::std::mem::size_of::<Foo<::std::os::raw::c_int, ::std::os::raw::c_int>>() - , 24usize , concat ! ( +fn __bindgen_test_layout_Foo_instantiation_95() { + assert_eq!(::std::mem::size_of::<Foo<::std::os::raw::c_int>>() , 24usize , + concat ! ( "Size of template specialization: " , stringify ! ( - Foo<::std::os::raw::c_int, ::std::os::raw::c_int> ) )); - assert_eq!(::std::mem::align_of::<Foo<::std::os::raw::c_int, ::std::os::raw::c_int>>() - , 8usize , concat ! ( + Foo<::std::os::raw::c_int> ) )); + assert_eq!(::std::mem::align_of::<Foo<::std::os::raw::c_int>>() , 8usize , + concat ! ( "Alignment of template specialization: " , stringify ! ( - Foo<::std::os::raw::c_int, ::std::os::raw::c_int> ) )); + Foo<::std::os::raw::c_int> ) )); } #[test] -fn __bindgen_test_layout_template_2() { +fn __bindgen_test_layout_Rooted_instantiation_106() { assert_eq!(::std::mem::size_of::<Rooted<*mut ::std::os::raw::c_void>>() , 24usize , concat ! ( "Size of template specialization: " , stringify ! ( @@ -268,7 +255,7 @@ fn __bindgen_test_layout_template_2() { Rooted<*mut ::std::os::raw::c_void> ) )); } #[test] -fn __bindgen_test_layout_template_3() { +fn __bindgen_test_layout_WithDtor_instantiation_114() { assert_eq!(::std::mem::size_of::<WithDtor<::std::os::raw::c_int>>() , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( diff --git a/tests/expectations/tests/template_typedef_transitive_param.rs b/tests/expectations/tests/template_typedef_transitive_param.rs index cc801f35..265ab5ce 100644 --- a/tests/expectations/tests/template_typedef_transitive_param.rs +++ b/tests/expectations/tests/template_typedef_transitive_param.rs @@ -5,10 +5,9 @@ #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct Wrapper<T> { +#[derive(Debug, Default, Copy, Clone)] +pub struct Wrapper { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<T>, } #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -19,6 +18,3 @@ impl <T> Default for Wrapper_Wrapped<T> { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } pub type Wrapper_Type<T> = Wrapper_Wrapped<T>; -impl <T> Default for Wrapper<T> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } -} diff --git a/tests/expectations/tests/template_typedefs.rs b/tests/expectations/tests/template_typedefs.rs index 9213c0d2..c987bf8e 100644 --- a/tests/expectations/tests/template_typedefs.rs +++ b/tests/expectations/tests/template_typedefs.rs @@ -7,11 +7,9 @@ pub type foo = ::std::option::Option<unsafe extern "C" fn(arg1: ::std::os::raw::c_int)>; #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct Foo<T, U> { +#[derive(Debug, Default, Copy, Clone)] +pub struct Foo { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<T>, - pub _phantom_1: ::std::marker::PhantomData<U>, } pub type Foo_Char<T> = T; pub type Foo_FooPtrTypedef<T> = *mut Foo_Char<T>; @@ -20,6 +18,3 @@ pub type Foo_nsCOMArrayEnumFunc<T> = aData: *mut ::std::os::raw::c_void) -> bool>; -impl <T, U> Default for Foo<T, U> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } -} diff --git a/tests/expectations/tests/templateref_opaque.rs b/tests/expectations/tests/templateref_opaque.rs index dfe941af..89808f30 100644 --- a/tests/expectations/tests/templateref_opaque.rs +++ b/tests/expectations/tests/templateref_opaque.rs @@ -5,22 +5,14 @@ #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct detail_PointerType<T> { +#[derive(Debug, Default, Copy, Clone)] +pub struct detail_PointerType { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<T>, } pub type detail_PointerType_Type<T> = *mut T; -impl <T> Default for detail_PointerType<T> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } -} #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct UniquePtr<T> { +#[derive(Debug, Default, Copy, Clone)] +pub struct UniquePtr { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<T>, -} -pub type UniquePtr_Pointer<T> = detail_PointerType<T>; -impl <T> Default for UniquePtr<T> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } } +pub type UniquePtr_Pointer = detail_PointerType; diff --git a/tests/expectations/tests/typeref.rs b/tests/expectations/tests/typeref.rs index 47b7a66a..c9982b67 100644 --- a/tests/expectations/tests/typeref.rs +++ b/tests/expectations/tests/typeref.rs @@ -31,7 +31,7 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> { #[repr(C)] #[derive(Debug, Copy)] pub struct nsFoo { - pub mBar: mozilla_StyleShapeSource<::std::os::raw::c_int>, + pub mBar: mozilla_StyleShapeSource, } #[test] fn bindgen_test_layout_nsFoo() { @@ -89,21 +89,16 @@ impl Clone for mozilla_Position { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct mozilla_StyleShapeSource<ReferenceBox> { - pub __bindgen_anon_1: mozilla_StyleShapeSource__bindgen_ty_1<ReferenceBox>, - pub _phantom_0: ::std::marker::PhantomData<ReferenceBox>, +#[derive(Debug, Default, Copy, Clone)] +pub struct mozilla_StyleShapeSource { + pub __bindgen_anon_1: mozilla_StyleShapeSource__bindgen_ty_1, } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] -pub struct mozilla_StyleShapeSource__bindgen_ty_1<ReferenceBox> { +pub struct mozilla_StyleShapeSource__bindgen_ty_1 { pub mPosition: __BindgenUnionField<*mut mozilla_Position>, pub mFragmentOrURL: __BindgenUnionField<*mut mozilla_FragmentOrURL>, pub bindgen_union_field: u64, - pub _phantom_0: ::std::marker::PhantomData<ReferenceBox>, -} -impl <ReferenceBox> Default for mozilla_StyleShapeSource<ReferenceBox> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] #[derive(Debug, Copy)] diff --git a/tests/expectations/tests/union_template.rs b/tests/expectations/tests/union_template.rs index 2eba0f0a..e02f1964 100644 --- a/tests/expectations/tests/union_template.rs +++ b/tests/expectations/tests/union_template.rs @@ -29,37 +29,30 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> { } } #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct NastyStruct<T> { +#[derive(Debug, Default, Copy, Clone)] +pub struct NastyStruct { pub mIsSome: bool, - pub mStorage: NastyStruct__bindgen_ty_1<T>, - pub __bindgen_anon_1: NastyStruct__bindgen_ty_2<T>, - pub _phantom_0: ::std::marker::PhantomData<T>, + pub mStorage: NastyStruct__bindgen_ty_1, + pub __bindgen_anon_1: NastyStruct__bindgen_ty_2, } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] -pub struct NastyStruct__bindgen_ty_1<T> { +pub struct NastyStruct__bindgen_ty_1 { pub mFoo: __BindgenUnionField<*mut ::std::os::raw::c_void>, pub mDummy: __BindgenUnionField<::std::os::raw::c_ulong>, pub bindgen_union_field: u64, - pub _phantom_0: ::std::marker::PhantomData<T>, } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] -pub struct NastyStruct__bindgen_ty_2<T> { +pub struct NastyStruct__bindgen_ty_2 { pub wat: __BindgenUnionField<::std::os::raw::c_short>, pub wut: __BindgenUnionField<*mut ::std::os::raw::c_int>, pub bindgen_union_field: u64, - pub _phantom_0: ::std::marker::PhantomData<T>, -} -impl <T> Default for NastyStruct<T> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] -pub struct Whatever<T> { +pub struct Whatever { pub mTPtr: __BindgenUnionField<*mut ::std::os::raw::c_void>, pub mInt: __BindgenUnionField<::std::os::raw::c_int>, pub bindgen_union_field: u64, - pub _phantom_0: ::std::marker::PhantomData<T>, } diff --git a/tests/expectations/tests/variadic_template_function.rs b/tests/expectations/tests/variadic_template_function.rs index 32be9f68..66fd73ed 100644 --- a/tests/expectations/tests/variadic_template_function.rs +++ b/tests/expectations/tests/variadic_template_function.rs @@ -5,11 +5,7 @@ #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct VariadicFunctionObject<T> { +#[derive(Debug, Default, Copy, Clone)] +pub struct VariadicFunctionObject { pub _address: u8, - pub _phantom_0: ::std::marker::PhantomData<T>, -} -impl <T> Default for VariadicFunctionObject<T> { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } } diff --git a/tests/expectations/tests/what_is_going_on.rs b/tests/expectations/tests/what_is_going_on.rs index 46af0139..e5194c02 100644 --- a/tests/expectations/tests/what_is_going_on.rs +++ b/tests/expectations/tests/what_is_going_on.rs @@ -22,12 +22,11 @@ impl Clone for UnknownUnits { pub type Float = f32; #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct PointTyped<units, F> { +pub struct PointTyped<F> { pub x: F, pub y: F, - pub _phantom_0: ::std::marker::PhantomData<units>, } -impl <units, F> Default for PointTyped<units, F> { +impl <F> Default for PointTyped<F> { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } -pub type IntPoint = PointTyped<UnknownUnits, f32>; +pub type IntPoint = PointTyped<f32>; diff --git a/tests/expectations/tests/whitelist_basic.rs b/tests/expectations/tests/whitelist_basic.rs index d67fb7a3..8af4aba3 100644 --- a/tests/expectations/tests/whitelist_basic.rs +++ b/tests/expectations/tests/whitelist_basic.rs @@ -9,7 +9,6 @@ pub struct WhitelistMe<T> { pub foo: ::std::os::raw::c_int, pub bar: WhitelistMe_Inner<T>, - pub _phantom_0: ::std::marker::PhantomData<T>, } #[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/tests/headers/issue-544-stylo-creduce-2.hpp b/tests/headers/issue-544-stylo-creduce-2.hpp new file mode 100644 index 00000000..f3467f45 --- /dev/null +++ b/tests/headers/issue-544-stylo-creduce-2.hpp @@ -0,0 +1,8 @@ +// bindgen-flags: -- -std=c++14 + +template <typename T> +struct Foo { + template <typename> using FirstAlias = typename T::Associated; + template <typename U> using SecondAlias = Foo<FirstAlias<U>>; + SecondAlias<int> member; +}; diff --git a/tests/headers/issue-544-stylo-creduce.hpp b/tests/headers/issue-544-stylo-creduce.hpp new file mode 100644 index 00000000..ba9f8257 --- /dev/null +++ b/tests/headers/issue-544-stylo-creduce.hpp @@ -0,0 +1,5 @@ +// bindgen-flags: -- -std=c++14 + +template <typename> class a; +template <typename b, typename... c> class a<b(c...)> { a(const a &); }; +template <typename b, typename... c> a<b(c...)>::a(const a &) {} diff --git a/tests/headers/partial-specialization-and-inheritance.hpp b/tests/headers/partial-specialization-and-inheritance.hpp new file mode 100644 index 00000000..4eb8f545 --- /dev/null +++ b/tests/headers/partial-specialization-and-inheritance.hpp @@ -0,0 +1,40 @@ +// bindgen-unstable + +// This was originally a test case generated by creducing errors in SpiderMonkey +// bindings generation. I've tried to make it understandable by giving more +// meaningful names to everything, and a couple comments. +// +// We don't support partial template specialization, but we *should* +// successfully parse this header, and generate bindings for it, but the usage +// of the partial template specialization should result in opaque blobs. + +// A base class providing a method. +template <typename T> +class Base { +public: + void some_method(T, T); +}; + +// A template with a default representation. +template <typename U> +class Derived { + bool b; +}; + +// A partial specialization for pointers. Note that this should have a different +// and larger layout than the template it is specializing. +template <typename U> +class Derived<U*> : public Base<U*> { + int x; + int y; +}; + +// A struct that uses the partial specialization and method from the partial +// specialization's base class. +struct Usage { + Usage() { + static_member.some_method(this, this); + } + + static Derived<Usage*> static_member; +}; diff --git a/tests/headers/template-param-usage-0.hpp b/tests/headers/template-param-usage-0.hpp new file mode 100644 index 00000000..57c11a10 --- /dev/null +++ b/tests/headers/template-param-usage-0.hpp @@ -0,0 +1,6 @@ +// bindgen-flags: -- -std=c++14 + +template <typename T> +class UsesTemplateParameter { + T t; +}; diff --git a/tests/headers/template-param-usage-1.hpp b/tests/headers/template-param-usage-1.hpp new file mode 100644 index 00000000..dba41489 --- /dev/null +++ b/tests/headers/template-param-usage-1.hpp @@ -0,0 +1,6 @@ +// bindgen-flags: -- -std=c++14 + +template <typename T> +class DoesNotUseTemplateParameter { + int x; +}; diff --git a/tests/headers/template-param-usage-10.hpp b/tests/headers/template-param-usage-10.hpp new file mode 100644 index 00000000..a6f3ccd8 --- /dev/null +++ b/tests/headers/template-param-usage-10.hpp @@ -0,0 +1,14 @@ +// bindgen-flags: -- -std=c++14 + +template <typename T, typename U, typename NeverUsed> +class DoublyIndirectUsage { + using Aliased = T; + typedef U Typedefed; + + class IndirectUsage { + Aliased member; + Typedefed another; + }; + + IndirectUsage doubly_indirect; +}; diff --git a/tests/headers/template-param-usage-11.hpp b/tests/headers/template-param-usage-11.hpp new file mode 100644 index 00000000..8780f5d3 --- /dev/null +++ b/tests/headers/template-param-usage-11.hpp @@ -0,0 +1,6 @@ +// bindgen-flags: -- -std=c++14 + +template <typename T> +class DoesNotUseT { + static T but_static_member_does; +}; diff --git a/tests/headers/template-param-usage-12.hpp b/tests/headers/template-param-usage-12.hpp new file mode 100644 index 00000000..9b4cea19 --- /dev/null +++ b/tests/headers/template-param-usage-12.hpp @@ -0,0 +1,11 @@ +// bindgen-flags: -- -std=c++14 + +template <typename T> +class BaseUsesT { + T* t; +}; + +template <typename U> +class CrtpUsesU : public BaseUsesT<CrtpUsesU<U>> { + U usage; +}; diff --git a/tests/headers/template-param-usage-13.hpp b/tests/headers/template-param-usage-13.hpp new file mode 100644 index 00000000..87db1a10 --- /dev/null +++ b/tests/headers/template-param-usage-13.hpp @@ -0,0 +1,11 @@ +// bindgen-flags: -- -std=c++14 + +template <typename T> +class BaseIgnoresT { + int x; +}; + +template <typename U> +class CrtpUsesU : public BaseIgnoresT<CrtpUsesU<U>> { + U usage; +}; diff --git a/tests/headers/template-param-usage-14.hpp b/tests/headers/template-param-usage-14.hpp new file mode 100644 index 00000000..19016296 --- /dev/null +++ b/tests/headers/template-param-usage-14.hpp @@ -0,0 +1,11 @@ +// bindgen-flags: -- -std=c++14 + +template <typename T> +class BaseIgnoresT { + int x; +}; + +template <typename U> +class CrtpIgnoresU : public BaseIgnoresT<CrtpIgnoresU<U>> { + int y; +}; diff --git a/tests/headers/template-param-usage-15.hpp b/tests/headers/template-param-usage-15.hpp new file mode 100644 index 00000000..bac7ada7 --- /dev/null +++ b/tests/headers/template-param-usage-15.hpp @@ -0,0 +1,11 @@ +// bindgen-flags: -- -std=c++14 + +template <typename T> +class BaseUsesT { + T* usage; +}; + +template <typename U> +class CrtpIgnoresU : public BaseUsesT<CrtpIgnoresU<U>> { + int y; +}; diff --git a/tests/headers/template-param-usage-2.hpp b/tests/headers/template-param-usage-2.hpp new file mode 100644 index 00000000..302140ab --- /dev/null +++ b/tests/headers/template-param-usage-2.hpp @@ -0,0 +1,10 @@ +// bindgen-flags: -- -std=c++14 + +template <typename T> +class UsesTemplateParameter { + T t; + + class AlsoUsesTemplateParameter { + T also; + }; +}; diff --git a/tests/headers/template-param-usage-3.hpp b/tests/headers/template-param-usage-3.hpp new file mode 100644 index 00000000..57396a8a --- /dev/null +++ b/tests/headers/template-param-usage-3.hpp @@ -0,0 +1,12 @@ +// bindgen-flags: -- -std=c++14 + +template <typename T> +class UsesTemplateParameter { + T t; + + template <typename U> + class AlsoUsesTemplateParameterAndMore { + T also; + U more; + }; +}; diff --git a/tests/headers/template-param-usage-4.hpp b/tests/headers/template-param-usage-4.hpp new file mode 100644 index 00000000..0415d692 --- /dev/null +++ b/tests/headers/template-param-usage-4.hpp @@ -0,0 +1,11 @@ +// bindgen-flags: -- -std=c++14 + +template <typename T> +class UsesTemplateParameter { + T t; + + template <typename U> + class DoesNotUseTemplateParameters { + int x; + }; +}; diff --git a/tests/headers/template-param-usage-5.hpp b/tests/headers/template-param-usage-5.hpp new file mode 100644 index 00000000..04b9bf80 --- /dev/null +++ b/tests/headers/template-param-usage-5.hpp @@ -0,0 +1,8 @@ +// bindgen-flags: -- -std=c++14 + +template <typename T> +class IndirectlyUsesTemplateParameter { + using Aliased = T; + + Aliased aliased; +}; diff --git a/tests/headers/template-param-usage-6.hpp b/tests/headers/template-param-usage-6.hpp new file mode 100644 index 00000000..ee0519c5 --- /dev/null +++ b/tests/headers/template-param-usage-6.hpp @@ -0,0 +1,8 @@ +// bindgen-flags: -- -std=c++14 + +template <typename T> +class DoesNotUseTemplateParameter { + using ButAliasDoesUseIt = T; + + int x; +}; diff --git a/tests/headers/template-param-usage-7.hpp b/tests/headers/template-param-usage-7.hpp new file mode 100644 index 00000000..99d4cc71 --- /dev/null +++ b/tests/headers/template-param-usage-7.hpp @@ -0,0 +1,10 @@ +// bindgen-flags: -- -std=c++14 + +template <typename T, typename U, typename V> +class DoesNotUseU { + T t; + V v; +}; + +// The bool should go away becuase U is not used. +using Alias = DoesNotUseU<int, bool, char>; diff --git a/tests/headers/template-param-usage-8.hpp b/tests/headers/template-param-usage-8.hpp new file mode 100644 index 00000000..96eabc06 --- /dev/null +++ b/tests/headers/template-param-usage-8.hpp @@ -0,0 +1,10 @@ +// bindgen-flags: -- -std=c++14 + +template <typename T, typename U> +class IndirectUsage { + typedef T Typedefed; + using Aliased = U; + + Typedefed member1; + Aliased member2; +}; diff --git a/tests/headers/template-param-usage-9.hpp b/tests/headers/template-param-usage-9.hpp new file mode 100644 index 00000000..b9bd202c --- /dev/null +++ b/tests/headers/template-param-usage-9.hpp @@ -0,0 +1,12 @@ +// bindgen-flags: -- -std=c++14 + +template <typename T, typename U> +class DoesNotUse { + using Aliased = T; + typedef U Typedefed; + + class IndirectUsage { + Aliased member; + Typedefed another; + }; +}; |