Skip to content

Use fully disambiguated name instead of a number for layout tests (fixes #394) #829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ impl CodeGenerator for TemplateInstantiation {
let size = layout.size;
let align = layout.align;

let name = item.canonical_name(ctx);
let name = item.full_disambiguated_name(ctx);
let mut fn_name = format!("__bindgen_test_layout_{}_instantiation", name);
let times_seen = result.overload_number(&fn_name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you can remove this overload_number stuff and so on?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if times_seen > 0 {
Expand Down
27 changes: 27 additions & 0 deletions src/ir/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,33 @@ 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 = String::new();
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));
if let ItemKind::Type(ref ty) = *self.kind() {
if let TypeKind::TemplateInstantiation(ref inst) = *ty.kind() {
to.push_str(&format!("_open{}_", level));
for arg in inst.template_arguments() {
arg.into_resolver()
.through_type_refs()
.resolve(ctx)
.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() {
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/anon_union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<TErrorResult>() , 24usize , concat ! (
"Size of template specialization: " , stringify ! (
TErrorResult ) ));
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/class_nested.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<A_D<::std::os::raw::c_int>>() , 4usize ,
concat ! (
"Size of template specialization: " , stringify ! (
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/class_with_dtor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<HandleWithDtor<::std::os::raw::c_int>>()
, 8usize , concat ! (
"Size of template specialization: " , stringify ! (
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/tests/crtp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ 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::<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_BaseWithDestructor_instantiation() {
fn __bindgen_test_layout_BaseWithDestructor_open0_DerivedFromBaseWithDestructor_close0_instantiation() {
assert_eq!(::std::mem::size_of::<BaseWithDestructor>() , 1usize , concat !
(
"Size of template specialization: " , stringify ! (
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/default-template-parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl <T, U> Default for Foo<T, U> {
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::<Foo<bool, ::std::os::raw::c_int>>() ,
8usize , concat ! (
"Size of template specialization: " , stringify ! (
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/forward-declaration-autoptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<RefPtr<Foo>>() , 8usize , concat ! (
"Size of template specialization: " , stringify ! ( RefPtr<Foo>
) ));
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/inner_template_self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<LinkedList>() , 16usize , concat ! (
"Size of template specialization: " , stringify ! ( LinkedList
) ));
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/issue-372.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ! (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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::<JS_Base>() , 1usize , concat ! (
"Size of template specialization: " , stringify ! ( JS_Base )
));
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/issue-573-layout-test-failures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Outer>() , 1usize , concat ! (
"Size of template specialization: " , stringify ! ( Outer ) ));
assert_eq!(::std::mem::align_of::<Outer>() , 1usize , concat ! (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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::<a>() , 1usize , concat ! (
"Size of template specialization: " , stringify ! ( a ) ));
assert_eq!(::std::mem::align_of::<a>() , 1usize , concat ! (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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::<f>() , 1usize , concat ! (
"Size of template specialization: " , stringify ! ( f ) ));
assert_eq!(::std::mem::align_of::<f>() , 1usize , concat ! (
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/issue-674-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<root::StaticRefPtr>() , 1usize ,
concat ! (
"Size of template specialization: " , stringify ! (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Set>() , 4usize , concat ! (
"Size of template specialization: " , stringify ! ( Set ) ));
assert_eq!(::std::mem::align_of::<Set>() , 4usize , concat ! (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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::<root::Rooted<::std::os::raw::c_int>>()
, 4usize , concat ! (
"Size of template specialization: " , stringify ! (
Expand All @@ -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::<root::Rooted<::std::os::raw::c_int>>()
, 4usize , concat ! (
"Size of template specialization: " , stringify ! (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Usage {
}
}
#[test]
fn __bindgen_test_layout__bindgen_ty_id_21_instantiation() {
fn __bindgen_test_layout__bindgen_ty_id_21_open0__bindgen_ty_id_19_close0_instantiation() {
assert_eq!(::std::mem::size_of::<[u32; 2usize]>() , 8usize , concat ! (
"Size of template specialization: " , stringify ! (
[u32; 2usize] ) ));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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::<root::Rooted<::std::os::raw::c_int>>()
, 4usize , concat ! (
"Size of template specialization: " , stringify ! (
Expand All @@ -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::<root::Rooted<::std::os::raw::c_int>>()
, 4usize , concat ! (
"Size of template specialization: " , stringify ! (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] ) ));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub mod root {
}
pub type AutoValueVector_Alias = ::std::os::raw::c_int;
#[test]
fn __bindgen_test_layout_Rooted_instantiation() {
fn __bindgen_test_layout_Rooted_open0_int_close0_instantiation() {
assert_eq!(::std::mem::size_of::<root::Rooted<::std::os::raw::c_int>>()
, 4usize , concat ! (
"Size of template specialization: " , stringify ! (
Expand All @@ -30,7 +30,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_AutoValueVector_Alias_close0_instantiation() {
assert_eq!(::std::mem::size_of::<root::Rooted<root::AutoValueVector_Alias>>()
, 4usize , concat ! (
"Size of template specialization: " , stringify ! (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] ) ));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Default for Rooted {
/// <div rustbindgen replaces="MaybeWrapped"></div>
pub type MaybeWrapped<a> = a;
#[test]
fn __bindgen_test_layout_MaybeWrapped_instantiation() {
fn __bindgen_test_layout_MaybeWrapped_open0_int_close0_instantiation() {
assert_eq!(::std::mem::size_of::<MaybeWrapped<::std::os::raw::c_int>>() ,
4usize , concat ! (
"Size of template specialization: " , stringify ! (
Expand Down
6 changes: 3 additions & 3 deletions tests/expectations/tests/non-type-params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] ) ));
Expand All @@ -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] ) ));
Expand All @@ -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] ) ));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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::<root::zoidberg::Template<root::zoidberg::Foo>>()
, 1usize , concat ! (
"Size of template specialization: " , stringify ! (
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/opaque-template-instantiation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Template<::std::os::raw::c_char>>() ,
1usize , concat ! (
"Size of template specialization: " , stringify ! (
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/opaque_pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<u32>() , 4usize , concat ! (
"Size of template specialization: " , stringify ! ( u32 ) ));
assert_eq!(::std::mem::align_of::<u32>() , 4usize , concat ! (
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/replace_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<nsTArray>() , 4usize , concat ! (
"Size of template specialization: " , stringify ! ( nsTArray )
));
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/size_t_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] ) ));
Expand Down
12 changes: 6 additions & 6 deletions tests/expectations/tests/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl <T> Default for ReplacedWithoutDestructorFwd<T> {
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::<Foo<::std::os::raw::c_int>>() , 24usize ,
concat ! (
"Size of template specialization: " , stringify ! (
Expand All @@ -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::<Foo<::std::os::raw::c_int>>() , 24usize ,
concat ! (
"Size of template specialization: " , stringify ! (
Expand All @@ -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::<Rooted<*mut ::std::os::raw::c_void>>() ,
24usize , concat ! (
"Size of template specialization: " , stringify ! (
Expand All @@ -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::<Rooted<*mut ::std::os::raw::c_void>>() ,
24usize , concat ! (
"Size of template specialization: " , stringify ! (
Expand All @@ -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::<WithDtor<::std::os::raw::c_int>>() ,
4usize , concat ! (
"Size of template specialization: " , stringify ! (
Expand All @@ -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::<u32>() , 4usize , concat ! (
"Size of template specialization: " , stringify ! ( u32 ) ));
assert_eq!(::std::mem::align_of::<u32>() , 4usize , concat ! (
Expand Down
Loading