Skip to content

Commit bb1aa1b

Browse files
committed
Named struct without body is enough
1 parent 69be664 commit bb1aa1b

7 files changed

Lines changed: 10 additions & 22 deletions

File tree

cpp2rust/converter/converter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ use std::rc::Rc;
5353
)");
5454
}
5555

56-
std::string Converter::EmitOpaqueRecordMarkers() {
56+
std::string Converter::EmitOpaqueRecords() {
5757
std::string out;
5858
record_decls_.ForEachUndefined([&](const std::string &name) {
59-
out += "#[repr(C)] pub struct ";
59+
out += "pub struct ";
6060
out += name;
61-
out += " { _opaque: [u8; 0] }\n";
61+
out += ";\n";
6262
});
6363
return out;
6464
}

cpp2rust/converter/converter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
5151

5252
virtual void EmitFilePreamble();
5353

54-
static std::string EmitOpaqueRecordMarkers();
54+
static std::string EmitOpaqueRecords();
5555

5656
virtual bool VisitBuiltinType(clang::BuiltinType *type);
5757

cpp2rust/cpp2rust_lib.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ std::string TranspileSrc(std::string_view cc_code, Model model,
3030
rules_dir),
3131
cc_code, tool_args, std::filesystem::path(filename).filename().string(),
3232
filename.ends_with(".c") ? CLANG_C_COMPILER : CLANG_CXX_COMPILER);
33-
rs_code += Converter::EmitOpaqueRecordMarkers();
33+
rs_code += Converter::EmitOpaqueRecords();
3434
return rs_code;
3535
}
3636

@@ -70,7 +70,7 @@ std::string TranspileDir(std::string_view build_dir, Model model,
7070
std::string rs_code;
7171
FrontendActionFactory factory(rs_code, model, rules_dir);
7272
Tool.run(&factory);
73-
rs_code += Converter::EmitOpaqueRecordMarkers();
73+
rs_code += Converter::EmitOpaqueRecords();
7474
return rs_code;
7575
}
7676
} // namespace cpp2rust

tests/multi-file/opaque_forward_decl/out/refcount/opaque_forward_decl.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,4 @@ pub fn touch_0(c: Ptr<container>) {
3232
let c: Value<Ptr<container>> = Rc::new(RefCell::new(c));
3333
(*(*(*c.borrow()).upgrade().deref()).p.borrow()).clone();
3434
}
35-
#[repr(C)]
36-
pub struct opaque {
37-
_opaque: [u8; 0],
38-
}
35+
pub struct opaque;

tests/multi-file/opaque_forward_decl/out/unsafe/opaque_forward_decl.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,4 @@ unsafe fn main_0() -> i32 {
3333
pub unsafe fn touch_0(mut c: *mut container) {
3434
&((*c).p);
3535
}
36-
#[repr(C)]
37-
pub struct opaque {
38-
_opaque: [u8; 0],
39-
}
36+
pub struct opaque;

tests/unit/out/refcount/opaque_forward_decl.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,4 @@ fn main_0() -> i32 {
2323
(*(*c.borrow()).p.borrow()).clone();
2424
return ((*(*c.borrow()).x.borrow()) - 42);
2525
}
26-
#[repr(C)]
27-
pub struct opaque {
28-
_opaque: [u8; 0],
29-
}
26+
pub struct opaque;

tests/unit/out/unsafe/opaque_forward_decl.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,4 @@ unsafe fn main_0() -> i32 {
2525
&(c.p);
2626
return ((c.x) - (42));
2727
}
28-
#[repr(C)]
29-
pub struct opaque {
30-
_opaque: [u8; 0],
31-
}
28+
pub struct opaque;

0 commit comments

Comments
 (0)