diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 6f2bf96b99..703ad24d90 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -768,13 +768,8 @@ impl CodeGenerator for TemplateInstantiation { let size = layout.size; let align = layout.align; - let name = item.canonical_name(ctx); - let mut fn_name = format!("__bindgen_test_layout_{}_instantiation", name); - let times_seen = result.overload_number(&fn_name); - if times_seen > 0 { - write!(&mut fn_name, "_{}", times_seen).unwrap(); - } - + let name = item.full_disambiguated_name(ctx); + let fn_name = format!("__bindgen_test_layout_{}_instantiation", name); let fn_name = ctx.rust_ident_raw(&fn_name); let prefix = ctx.trait_prefix(); diff --git a/src/ir/item.rs b/src/ir/item.rs index e65b7a99d1..facd81d902 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -681,6 +681,34 @@ impl Item { } } + /// Create a fully disambiguated name for an item, including template + /// parameters if it is a type + pub fn full_disambiguated_name(&self, ctx: &BindgenContext) -> String { + let mut s = "".into(); + let level = 0; + self.push_disambiguated_name(ctx, &mut s, level); + s + } + + /// Helper function for full_disambiguated_name + fn push_disambiguated_name(&self, ctx: &BindgenContext, to: &mut String, level: u8) { + to.push_str(&self.canonical_name(ctx)); + match *self.kind() { + ItemKind::Type(ref ty) => match *ty.kind() { + TypeKind::TemplateInstantiation(ref inst) => { + to.push_str(&format!("_open{}_", level)); + for arg in inst.template_arguments() { + ctx.resolve_item(*arg).push_disambiguated_name(ctx, to, level + 1); + to.push_str("_"); + } + to.push_str(&format!("close{}", level)); + } + _ => () + }, + _ => () + } + } + /// Get this function item's name, or `None` if this item is not a function. fn func_name(&self) -> Option<&str> { match *self.kind() { diff --git a/tests/expectations/tests/anon_union.rs b/tests/expectations/tests/anon_union.rs index 8b102c7979..97cd40f5ad 100644 --- a/tests/expectations/tests/anon_union.rs +++ b/tests/expectations/tests/anon_union.rs @@ -80,7 +80,7 @@ impl Default for ErrorResult { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[test] -fn __bindgen_test_layout_TErrorResult_instantiation() { +fn __bindgen_test_layout_TErrorResult_open0_int_close0_instantiation() { assert_eq!(::std::mem::size_of::() , 24usize , concat ! ( "Size of template specialization: " , stringify ! ( TErrorResult ) )); diff --git a/tests/expectations/tests/class_nested.rs b/tests/expectations/tests/class_nested.rs index d5f4e1a9a8..11e2f9396e 100644 --- a/tests/expectations/tests/class_nested.rs +++ b/tests/expectations/tests/class_nested.rs @@ -78,7 +78,7 @@ extern "C" { pub static mut var: A_B; } #[test] -fn __bindgen_test_layout_A_D_instantiation() { +fn __bindgen_test_layout_A_D_open0_int_close0_instantiation() { assert_eq!(::std::mem::size_of::>() , 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 d291a983d8..cf36f119e7 100644 --- a/tests/expectations/tests/class_with_dtor.rs +++ b/tests/expectations/tests/class_with_dtor.rs @@ -35,7 +35,7 @@ impl Default for WithoutDtor { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[test] -fn __bindgen_test_layout_HandleWithDtor_instantiation() { +fn __bindgen_test_layout_HandleWithDtor_open0_int_close0_instantiation() { assert_eq!(::std::mem::size_of::>() , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( diff --git a/tests/expectations/tests/crtp.rs b/tests/expectations/tests/crtp.rs index f76f78f83e..0b761d52eb 100644 --- a/tests/expectations/tests/crtp.rs +++ b/tests/expectations/tests/crtp.rs @@ -51,7 +51,7 @@ impl Default for DerivedFromBaseWithDestructor { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[test] -fn __bindgen_test_layout_Base_instantiation() { +fn __bindgen_test_layout_Base_open0_Derived_close0_instantiation() { assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( "Size of template specialization: " , stringify ! ( Base ) )); assert_eq!(::std::mem::align_of::() , 1usize , concat ! ( @@ -59,7 +59,7 @@ fn __bindgen_test_layout_Base_instantiation() { )); } #[test] -fn __bindgen_test_layout_BaseWithDestructor_instantiation() { +fn __bindgen_test_layout_BaseWithDestructor_open0_DerivedFromBaseWithDestructor_close0_instantiation() { assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( "Size of template specialization: " , stringify ! ( diff --git a/tests/expectations/tests/default-template-parameter.rs b/tests/expectations/tests/default-template-parameter.rs index e57761ce15..0336f0d873 100644 --- a/tests/expectations/tests/default-template-parameter.rs +++ b/tests/expectations/tests/default-template-parameter.rs @@ -16,7 +16,7 @@ impl Default for Foo { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[test] -fn __bindgen_test_layout_Foo_instantiation() { +fn __bindgen_test_layout_Foo_open0_bool__int_close0_instantiation() { assert_eq!(::std::mem::size_of::>() , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( diff --git a/tests/expectations/tests/forward-declaration-autoptr.rs b/tests/expectations/tests/forward-declaration-autoptr.rs index df519fe907..069728cbd2 100644 --- a/tests/expectations/tests/forward-declaration-autoptr.rs +++ b/tests/expectations/tests/forward-declaration-autoptr.rs @@ -42,7 +42,7 @@ impl Default for Bar { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[test] -fn __bindgen_test_layout_RefPtr_instantiation() { +fn __bindgen_test_layout_RefPtr_open0_Foo_close0_instantiation() { assert_eq!(::std::mem::size_of::>() , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( RefPtr ) )); diff --git a/tests/expectations/tests/inner_template_self.rs b/tests/expectations/tests/inner_template_self.rs index 26b35d8a73..b94ba60f70 100644 --- a/tests/expectations/tests/inner_template_self.rs +++ b/tests/expectations/tests/inner_template_self.rs @@ -37,7 +37,7 @@ impl Default for InstantiateIt { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[test] -fn __bindgen_test_layout_LinkedList_instantiation() { +fn __bindgen_test_layout_LinkedList_open0_int_close0_instantiation() { assert_eq!(::std::mem::size_of::() , 16usize , concat ! ( "Size of template specialization: " , stringify ! ( LinkedList ) )); diff --git a/tests/expectations/tests/issue-372.rs b/tests/expectations/tests/issue-372.rs index 687ae25f75..696c0e9012 100644 --- a/tests/expectations/tests/issue-372.rs +++ b/tests/expectations/tests/issue-372.rs @@ -102,7 +102,7 @@ pub mod root { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[test] - fn __bindgen_test_layout_C_instantiation() { + fn __bindgen_test_layout_C_open0_n_close0_instantiation() { assert_eq!(::std::mem::size_of::<[u64; 33usize]>() , 264usize , concat ! ( "Size of template specialization: " , stringify ! ( diff --git a/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs b/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs index 1a783f7d49..7ad336fb99 100644 --- a/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs +++ b/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs @@ -32,7 +32,7 @@ impl Default for JS_AutoIdVector { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[test] -fn __bindgen_test_layout_JS_Base_instantiation() { +fn __bindgen_test_layout_JS_Base_open0_int_close0_instantiation() { assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( "Size of template specialization: " , stringify ! ( JS_Base ) )); diff --git a/tests/expectations/tests/issue-573-layout-test-failures.rs b/tests/expectations/tests/issue-573-layout-test-failures.rs index 7d87aabec0..eb04ae9f5a 100644 --- a/tests/expectations/tests/issue-573-layout-test-failures.rs +++ b/tests/expectations/tests/issue-573-layout-test-failures.rs @@ -29,7 +29,7 @@ impl Default for AutoIdVector { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[test] -fn __bindgen_test_layout_Outer_instantiation() { +fn __bindgen_test_layout_Outer_open0_int_close0_instantiation() { assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( "Size of template specialization: " , stringify ! ( Outer ) )); assert_eq!(::std::mem::align_of::() , 1usize , concat ! ( diff --git a/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs b/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs index a895434d81..3c8f87c3a6 100644 --- a/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs +++ b/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs @@ -37,7 +37,7 @@ extern "C" { pub static mut AutoIdVector: _bindgen_ty_1; } #[test] -fn __bindgen_test_layout_a_instantiation() { +fn __bindgen_test_layout_a_open0_int_close0_instantiation() { assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( "Size of template specialization: " , stringify ! ( a ) )); assert_eq!(::std::mem::align_of::() , 1usize , concat ! ( diff --git a/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs b/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs index c0933df3e6..5c6d595b46 100644 --- a/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs +++ b/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs @@ -80,7 +80,7 @@ extern "C" { pub fn Servo_Element_GetSnapshot() -> A; } #[test] -fn __bindgen_test_layout_f_instantiation() { +fn __bindgen_test_layout_f_open0_e_open1_int_close1_close0_instantiation() { assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( "Size of template specialization: " , stringify ! ( f ) )); assert_eq!(::std::mem::align_of::() , 1usize , concat ! ( diff --git a/tests/expectations/tests/issue-674-2.rs b/tests/expectations/tests/issue-674-2.rs index da0d82876f..5e9ca485ea 100644 --- a/tests/expectations/tests/issue-674-2.rs +++ b/tests/expectations/tests/issue-674-2.rs @@ -67,7 +67,7 @@ pub mod root { pub _address: u8, } #[test] - fn __bindgen_test_layout_StaticRefPtr_instantiation() { + fn __bindgen_test_layout_StaticRefPtr_open0_B_close0_instantiation() { assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( "Size of template specialization: " , stringify ! ( diff --git a/tests/expectations/tests/issue-691-template-parameter-virtual.rs b/tests/expectations/tests/issue-691-template-parameter-virtual.rs index de43c0363f..09f5ee20ee 100644 --- a/tests/expectations/tests/issue-691-template-parameter-virtual.rs +++ b/tests/expectations/tests/issue-691-template-parameter-virtual.rs @@ -51,7 +51,7 @@ impl Default for ServoElementSnapshotTable { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[test] -fn __bindgen_test_layout_Set_instantiation() { +fn __bindgen_test_layout_Set_open0_VirtualMethods_close0_instantiation() { assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( Set ) )); assert_eq!(::std::mem::align_of::() , 4usize , concat ! ( diff --git a/tests/expectations/tests/libclang-3.9/issue-769-bad-instantiation-test.rs b/tests/expectations/tests/libclang-3.9/issue-769-bad-instantiation-test.rs index 848e649f64..376b43cbe1 100644 --- a/tests/expectations/tests/libclang-3.9/issue-769-bad-instantiation-test.rs +++ b/tests/expectations/tests/libclang-3.9/issue-769-bad-instantiation-test.rs @@ -18,7 +18,7 @@ pub mod root { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[test] - fn __bindgen_test_layout_Rooted_instantiation() { + fn __bindgen_test_layout_Rooted_open0_int_close0_instantiation() { assert_eq!(::std::mem::size_of::>() , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( @@ -29,7 +29,7 @@ pub mod root { root::Rooted<::std::os::raw::c_int> ) )); } #[test] - fn __bindgen_test_layout_Rooted_instantiation_1() { + fn __bindgen_test_layout_Rooted_open0_int_close0_instantiation_1() { assert_eq!(::std::mem::size_of::>() , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( diff --git a/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs b/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs index c025137196..7760f03343 100644 --- a/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs +++ b/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs @@ -34,7 +34,7 @@ impl Clone for Usage { fn clone(&self) -> Self { *self } } #[test] -fn __bindgen_test_layout__bindgen_ty_id_20_instantiation() { +fn __bindgen_test_layout__bindgen_ty_id_20_open0__bindgen_ty_id_18_close0_instantiation() { assert_eq!(::std::mem::size_of::<[u32; 2usize]>() , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( [u32; 2usize] ) )); diff --git a/tests/expectations/tests/non-type-params.rs b/tests/expectations/tests/non-type-params.rs index 34864993ea..cef5a3a0bb 100644 --- a/tests/expectations/tests/non-type-params.rs +++ b/tests/expectations/tests/non-type-params.rs @@ -38,7 +38,7 @@ impl Default for UsesArray { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[test] -fn __bindgen_test_layout_Array_instantiation() { +fn __bindgen_test_layout_Array_open0_int_close0_instantiation() { assert_eq!(::std::mem::size_of::<[u32; 4usize]>() , 16usize , concat ! ( "Size of template specialization: " , stringify ! ( [u32; 4usize] ) )); @@ -47,7 +47,7 @@ fn __bindgen_test_layout_Array_instantiation() { [u32; 4usize] ) )); } #[test] -fn __bindgen_test_layout_Array_instantiation_1() { +fn __bindgen_test_layout_Array_open0_char_close0_instantiation() { assert_eq!(::std::mem::size_of::<[u8; 16usize]>() , 16usize , concat ! ( "Size of template specialization: " , stringify ! ( [u8; 16usize] ) )); @@ -56,7 +56,7 @@ fn __bindgen_test_layout_Array_instantiation_1() { [u8; 16usize] ) )); } #[test] -fn __bindgen_test_layout_Array_instantiation_2() { +fn __bindgen_test_layout_Array_open0_bool__close0_instantiation() { assert_eq!(::std::mem::size_of::<[u8; 8usize]>() , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( [u8; 8usize] ) )); diff --git a/tests/expectations/tests/opaque-template-instantiation-namespaced.rs b/tests/expectations/tests/opaque-template-instantiation-namespaced.rs index 6623dae286..00c5582509 100644 --- a/tests/expectations/tests/opaque-template-instantiation-namespaced.rs +++ b/tests/expectations/tests/opaque-template-instantiation-namespaced.rs @@ -115,7 +115,7 @@ pub mod root { } } #[test] - fn __bindgen_test_layout_Template_instantiation() { + fn __bindgen_test_layout_Template_open0_Foo_close0_instantiation() { assert_eq!(::std::mem::size_of::>() , 1usize , concat ! ( "Size of template specialization: " , stringify ! ( diff --git a/tests/expectations/tests/opaque-template-instantiation.rs b/tests/expectations/tests/opaque-template-instantiation.rs index eb4e92bc38..f3ef2a06da 100644 --- a/tests/expectations/tests/opaque-template-instantiation.rs +++ b/tests/expectations/tests/opaque-template-instantiation.rs @@ -63,7 +63,7 @@ impl Clone for ContainsOpaqueInstantiation { fn clone(&self) -> Self { *self } } #[test] -fn __bindgen_test_layout_Template_instantiation() { +fn __bindgen_test_layout_Template_open0_char_close0_instantiation() { assert_eq!(::std::mem::size_of::>() , 1usize , concat ! ( "Size of template specialization: " , stringify ! ( diff --git a/tests/expectations/tests/opaque_pointer.rs b/tests/expectations/tests/opaque_pointer.rs index 68f8132d89..8465ba6a6c 100644 --- a/tests/expectations/tests/opaque_pointer.rs +++ b/tests/expectations/tests/opaque_pointer.rs @@ -64,7 +64,7 @@ impl Default for WithOpaquePtr { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[test] -fn __bindgen_test_layout_Opaque_instantiation() { +fn __bindgen_test_layout_Opaque_open0_float_close0_instantiation() { assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( u32 ) )); assert_eq!(::std::mem::align_of::() , 4usize , concat ! ( diff --git a/tests/expectations/tests/replace_use.rs b/tests/expectations/tests/replace_use.rs index cbbee381c2..3998d5b38e 100644 --- a/tests/expectations/tests/replace_use.rs +++ b/tests/expectations/tests/replace_use.rs @@ -34,7 +34,7 @@ impl Default for Test { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[test] -fn __bindgen_test_layout_nsTArray_instantiation() { +fn __bindgen_test_layout_nsTArray_open0_long_close0_instantiation() { assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( nsTArray ) )); diff --git a/tests/expectations/tests/size_t_template.rs b/tests/expectations/tests/size_t_template.rs index 47e75edb6e..6d1afce4f5 100644 --- a/tests/expectations/tests/size_t_template.rs +++ b/tests/expectations/tests/size_t_template.rs @@ -24,7 +24,7 @@ impl Default for C { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[test] -fn __bindgen_test_layout_Array_instantiation() { +fn __bindgen_test_layout_Array_open0_int_close0_instantiation() { assert_eq!(::std::mem::size_of::<[u32; 3usize]>() , 12usize , concat ! ( "Size of template specialization: " , stringify ! ( [u32; 3usize] ) )); diff --git a/tests/expectations/tests/template.rs b/tests/expectations/tests/template.rs index 74dcd99cb4..8fe4941ba5 100644 --- a/tests/expectations/tests/template.rs +++ b/tests/expectations/tests/template.rs @@ -234,7 +234,7 @@ impl Default for ReplacedWithoutDestructorFwd { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[test] -fn __bindgen_test_layout_Foo_instantiation() { +fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation() { assert_eq!(::std::mem::size_of::>() , 24usize , concat ! ( "Size of template specialization: " , stringify ! ( @@ -245,7 +245,7 @@ fn __bindgen_test_layout_Foo_instantiation() { Foo<::std::os::raw::c_int> ) )); } #[test] -fn __bindgen_test_layout_Foo_instantiation_1() { +fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation_1() { assert_eq!(::std::mem::size_of::>() , 24usize , concat ! ( "Size of template specialization: " , stringify ! ( @@ -256,7 +256,7 @@ fn __bindgen_test_layout_Foo_instantiation_1() { Foo<::std::os::raw::c_int> ) )); } #[test] -fn __bindgen_test_layout_Rooted_instantiation() { +fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_108_close0_instantiation() { assert_eq!(::std::mem::size_of::>() , 24usize , concat ! ( "Size of template specialization: " , stringify ! ( @@ -267,7 +267,7 @@ fn __bindgen_test_layout_Rooted_instantiation() { Rooted<*mut ::std::os::raw::c_void> ) )); } #[test] -fn __bindgen_test_layout_Rooted_instantiation_1() { +fn __bindgen_test_layout_Rooted_open0__bindgen_ty_id_114_close0_instantiation() { assert_eq!(::std::mem::size_of::>() , 24usize , concat ! ( "Size of template specialization: " , stringify ! ( @@ -278,7 +278,7 @@ fn __bindgen_test_layout_Rooted_instantiation_1() { Rooted<*mut ::std::os::raw::c_void> ) )); } #[test] -fn __bindgen_test_layout_WithDtor_instantiation() { +fn __bindgen_test_layout_WithDtor_open0_int_close0_instantiation() { assert_eq!(::std::mem::size_of::>() , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( @@ -289,7 +289,7 @@ fn __bindgen_test_layout_WithDtor_instantiation() { WithDtor<::std::os::raw::c_int> ) )); } #[test] -fn __bindgen_test_layout_Opaque_instantiation() { +fn __bindgen_test_layout_Opaque_open0_int_close0_instantiation() { assert_eq!(::std::mem::size_of::() , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( u32 ) )); assert_eq!(::std::mem::align_of::() , 4usize , concat ! ( diff --git a/tests/expectations/tests/typeref.rs b/tests/expectations/tests/typeref.rs index b3b7559473..92f40cc864 100644 --- a/tests/expectations/tests/typeref.rs +++ b/tests/expectations/tests/typeref.rs @@ -124,7 +124,7 @@ impl Default for Bar { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[test] -fn __bindgen_test_layout_mozilla_StyleShapeSource_instantiation() { +fn __bindgen_test_layout_mozilla_StyleShapeSource_open0_int_close0_instantiation() { assert_eq!(::std::mem::size_of::() , 8usize , concat ! ( "Size of template specialization: " , stringify ! (