Skip to content

Commit 0ceeaf8

Browse files
committed
codegen: Fix use generation for non-root module.
1 parent dfb25b3 commit 0ceeaf8

File tree

7 files changed

+14
-6
lines changed

7 files changed

+14
-6
lines changed

bindgen-integration/cpp/Test.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ class Test {
88
Test(int foo);
99
Test(double foo);
1010
};
11+
12+
typedef Test TypeAlias;

libbindgen/src/codegen/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,13 @@ impl CodeGenerator for Type {
538538
_ => None,
539539
};
540540

541-
let typedef = if let Some(p) = simple_enum_path {
541+
let typedef = if let Some(mut p) = simple_enum_path {
542+
if p.segments.len() == 1 {
543+
p.segments.insert(0, ast::PathSegment {
544+
identifier: ctx.ext_cx().ident_of("self"),
545+
parameters: None,
546+
});
547+
}
542548
typedef.use_().build(p).as_(rust_name)
543549
} else {
544550
let mut generics = typedef.type_(rust_name).generics();

libbindgen/tests/expectations/tests/anon_enum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ pub const Bar: _bindgen_ty_1 = _bindgen_ty_1::Bar;
2727
#[repr(u32)]
2828
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2929
pub enum _bindgen_ty_1 { Foo = 0, Bar = 1, }
30-
pub use _bindgen_ty_1 as Baz;
30+
pub use self::_bindgen_ty_1 as Baz;

libbindgen/tests/expectations/tests/bitfield_method_mangling.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ impl _bindgen_ty_1 {
4646
((val as u32 as u32) << 24u32) & (4278190080usize as u32);
4747
}
4848
}
49-
pub use _bindgen_ty_1 as mach_msg_type_descriptor_t;
49+
pub use self::_bindgen_ty_1 as mach_msg_type_descriptor_t;

libbindgen/tests/expectations/tests/inherit_typedef.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn bindgen_test_layout_Foo() {
1717
impl Clone for Foo {
1818
fn clone(&self) -> Self { *self }
1919
}
20-
pub use Foo as TypedefedFoo;
20+
pub use self::Foo as TypedefedFoo;
2121
#[repr(C)]
2222
#[derive(Debug, Copy)]
2323
pub struct Bar {

libbindgen/tests/expectations/tests/union_fields.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ fn bindgen_test_layout__bindgen_ty_1() {
4444
impl Clone for _bindgen_ty_1 {
4545
fn clone(&self) -> Self { *self }
4646
}
47-
pub use _bindgen_ty_1 as nsStyleUnion;
47+
pub use self::_bindgen_ty_1 as nsStyleUnion;

libbindgen/tests/expectations/tests/unknown_attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ pub struct _bindgen_ty_1 {
1313
impl Clone for _bindgen_ty_1 {
1414
fn clone(&self) -> Self { *self }
1515
}
16-
pub use _bindgen_ty_1 as max_align_t;
16+
pub use self::_bindgen_ty_1 as max_align_t;

0 commit comments

Comments
 (0)