Skip to content

Commit cbbe118

Browse files
committed
Use fully disambiguated name instead of a number for layout tests (fixes #394)
1 parent 6053d99 commit cbbe118

30 files changed

+66
-39
lines changed

src/codegen/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ impl CodeGenerator for TemplateInstantiation {
768768
let size = layout.size;
769769
let align = layout.align;
770770

771-
let name = item.canonical_name(ctx);
771+
let name = item.full_disambiguated_name(ctx);
772772
let mut fn_name = format!("__bindgen_test_layout_{}_instantiation", name);
773773
let times_seen = result.overload_number(&fn_name);
774774
if times_seen > 0 {

src/ir/item.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,33 @@ impl Item {
681681
}
682682
}
683683

684+
/// Create a fully disambiguated name for an item, including template
685+
/// parameters if it is a type
686+
pub fn full_disambiguated_name(&self, ctx: &BindgenContext) -> String {
687+
let mut s = String::new();
688+
let level = 0;
689+
self.push_disambiguated_name(ctx, &mut s, level);
690+
s
691+
}
692+
693+
/// Helper function for full_disambiguated_name
694+
fn push_disambiguated_name(&self, ctx: &BindgenContext, to: &mut String, level: u8) {
695+
to.push_str(&self.canonical_name(ctx));
696+
if let ItemKind::Type(ref ty) = *self.kind() {
697+
if let TypeKind::TemplateInstantiation(ref inst) = *ty.kind() {
698+
to.push_str(&format!("_open{}_", level));
699+
for arg in inst.template_arguments() {
700+
arg.into_resolver()
701+
.through_type_refs()
702+
.resolve(ctx)
703+
.push_disambiguated_name(ctx, to, level + 1);
704+
to.push_str("_");
705+
}
706+
to.push_str(&format!("close{}", level));
707+
}
708+
}
709+
}
710+
684711
/// Get this function item's name, or `None` if this item is not a function.
685712
fn func_name(&self) -> Option<&str> {
686713
match *self.kind() {

tests/expectations/tests/anon_union.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl Default for ErrorResult {
8080
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
8181
}
8282
#[test]
83-
fn __bindgen_test_layout_TErrorResult_instantiation() {
83+
fn __bindgen_test_layout_TErrorResult_open0_int_close0_instantiation() {
8484
assert_eq!(::std::mem::size_of::<TErrorResult>() , 24usize , concat ! (
8585
"Size of template specialization: " , stringify ! (
8686
TErrorResult ) ));

tests/expectations/tests/class_nested.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ extern "C" {
7878
pub static mut var: A_B;
7979
}
8080
#[test]
81-
fn __bindgen_test_layout_A_D_instantiation() {
81+
fn __bindgen_test_layout_A_D_open0_int_close0_instantiation() {
8282
assert_eq!(::std::mem::size_of::<A_D<::std::os::raw::c_int>>() , 4usize ,
8383
concat ! (
8484
"Size of template specialization: " , stringify ! (

tests/expectations/tests/class_with_dtor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl Default for WithoutDtor {
3535
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
3636
}
3737
#[test]
38-
fn __bindgen_test_layout_HandleWithDtor_instantiation() {
38+
fn __bindgen_test_layout_HandleWithDtor_open0_int_close0_instantiation() {
3939
assert_eq!(::std::mem::size_of::<HandleWithDtor<::std::os::raw::c_int>>()
4040
, 8usize , concat ! (
4141
"Size of template specialization: " , stringify ! (

tests/expectations/tests/crtp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ impl Default for DerivedFromBaseWithDestructor {
5151
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
5252
}
5353
#[test]
54-
fn __bindgen_test_layout_Base_instantiation() {
54+
fn __bindgen_test_layout_Base_open0_Derived_close0_instantiation() {
5555
assert_eq!(::std::mem::size_of::<Base>() , 1usize , concat ! (
5656
"Size of template specialization: " , stringify ! ( Base ) ));
5757
assert_eq!(::std::mem::align_of::<Base>() , 1usize , concat ! (
5858
"Alignment of template specialization: " , stringify ! ( Base )
5959
));
6060
}
6161
#[test]
62-
fn __bindgen_test_layout_BaseWithDestructor_instantiation() {
62+
fn __bindgen_test_layout_BaseWithDestructor_open0_DerivedFromBaseWithDestructor_close0_instantiation() {
6363
assert_eq!(::std::mem::size_of::<BaseWithDestructor>() , 1usize , concat !
6464
(
6565
"Size of template specialization: " , stringify ! (

tests/expectations/tests/default-template-parameter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl <T, U> Default for Foo<T, U> {
1616
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
1717
}
1818
#[test]
19-
fn __bindgen_test_layout_Foo_instantiation() {
19+
fn __bindgen_test_layout_Foo_open0_bool__int_close0_instantiation() {
2020
assert_eq!(::std::mem::size_of::<Foo<bool, ::std::os::raw::c_int>>() ,
2121
8usize , concat ! (
2222
"Size of template specialization: " , stringify ! (

tests/expectations/tests/forward-declaration-autoptr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl Default for Bar {
4242
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
4343
}
4444
#[test]
45-
fn __bindgen_test_layout_RefPtr_instantiation() {
45+
fn __bindgen_test_layout_RefPtr_open0_Foo_close0_instantiation() {
4646
assert_eq!(::std::mem::size_of::<RefPtr<Foo>>() , 8usize , concat ! (
4747
"Size of template specialization: " , stringify ! ( RefPtr<Foo>
4848
) ));

tests/expectations/tests/inner_template_self.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl Default for InstantiateIt {
3737
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
3838
}
3939
#[test]
40-
fn __bindgen_test_layout_LinkedList_instantiation() {
40+
fn __bindgen_test_layout_LinkedList_open0_int_close0_instantiation() {
4141
assert_eq!(::std::mem::size_of::<LinkedList>() , 16usize , concat ! (
4242
"Size of template specialization: " , stringify ! ( LinkedList
4343
) ));

tests/expectations/tests/issue-372.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub mod root {
102102
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
103103
}
104104
#[test]
105-
fn __bindgen_test_layout_C_instantiation() {
105+
fn __bindgen_test_layout_C_open0_n_close0_instantiation() {
106106
assert_eq!(::std::mem::size_of::<[u64; 33usize]>() , 264usize , concat
107107
! (
108108
"Size of template specialization: " , stringify ! (

0 commit comments

Comments
 (0)