Skip to content

Commit

Permalink
D: fix generics opaque structs
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Oct 4, 2024
1 parent f36981c commit 65df2ad
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 17 deletions.
12 changes: 10 additions & 2 deletions src/bindgen/language_backend/clike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,9 @@ impl LanguageBackend for CLikeLanguageBackend<'_> {

self.write_documentation(out, &o.documentation);

o.generic_params.write_with_default(self, self.config, out);
if self.config.language != Language::D {
o.generic_params.write_with_default(self, self.config, out);
}

if self.generate_typedef() {
write!(
Expand All @@ -774,7 +776,13 @@ impl LanguageBackend for CLikeLanguageBackend<'_> {
o.export_name()
);
} else {
write!(out, "struct {};", o.export_name());
if self.config.language == Language::D {
write!(out, "struct {}", o.export_name());
o.generic_params.write_with_default(self, self.config, out);
out.write(";");
} else {
write!(out, "struct {};", o.export_name());
}
}

condition.write_after(self.config, out);
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/box.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module cbindgen;

@nogc nothrow @safe:

(T = void)struct NotReprC;
struct NotReprC(T = void);

alias Foo = NotReprC!(int*);

Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/cell.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ module cbindgen;

@nogc nothrow @safe:

(T = void)struct NotReprC;
struct NotReprC(T = void);

(T = void)struct RefCell;
struct RefCell(T = void);

alias Foo = NotReprC!(RefCell!(int));

Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/exclude_generic_monomorph.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module cbindgen;

@nogc nothrow @safe:

(T = void)struct Option;
struct Option(T = void);

alias Foo = ulong;

Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/manuallydrop.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module cbindgen;

@nogc nothrow @safe:

(T = void)struct NotReprC;
struct NotReprC(T = void);

struct Point {
@disable this();
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/maybeuninit.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module cbindgen;

@nogc nothrow @safe:

(T = void)struct NotReprC;
struct NotReprC(T = void);

alias Foo = NotReprC!(const int*);

Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/monomorph_1.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module cbindgen;

@nogc nothrow @safe:

(T = void)struct Bar;
struct Bar(T = void);

struct Foo(T) {
@disable this();
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/monomorph_3.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module cbindgen;

@nogc nothrow @safe:

(T = void)struct Bar;
struct Bar(T = void);

union Foo(T) {
const T *data;
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/nonzero.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module cbindgen;

@nogc nothrow @safe:

(T = void)struct Option;
struct Option(T = void);

struct NonZeroAliases {
@disable this();
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/opaque.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ module cbindgen;

@nogc nothrow @safe:

(K = void, V = void, Hasher = void)struct HashMap;
struct HashMap(K = void, V = void, Hasher = void);

(T = void, E = void)struct Result;
struct Result(T = void, E = void);

/// Fast hash map used internally.
alias FastHashMap(K, V) = HashMap!(K, V, BuildHasherDefault!(DefaultHasher));
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/simplify_option_ptr.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module cbindgen;

struct Opaque;

(T = void)struct Option;
struct Option(T = void);

struct Foo {
@disable this();
Expand Down
6 changes: 3 additions & 3 deletions tests/expectations/std_lib.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ module cbindgen;

@nogc nothrow @safe:

(T = void)struct Option;
struct Option(T = void);

(T = void, E = void)struct Result;
struct Result(T = void, E = void);

struct String;

(T = void)struct Vec;
struct Vec(T = void);

extern(C) {

Expand Down

0 comments on commit 65df2ad

Please sign in to comment.