Skip to content

Commit cddf386

Browse files
authored
Merge pull request #615 from dtolnay/vis
Add C++ symbol visibility annotations for Rust functions and impls
2 parents a5b8c38 + b478fcb commit cddf386

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

gen/src/write.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -623,13 +623,17 @@ fn write_opaque_type_layout<'a>(out: &mut OutFile<'a>, ety: &'a ExternType) {
623623
writeln!(out, "}}");
624624
}
625625

626+
fn begin_function_definition(out: &mut OutFile) {
627+
if let Some(annotation) = &out.opt.cxx_impl_annotations {
628+
write!(out, "{} ", annotation);
629+
}
630+
}
631+
626632
fn write_cxx_function_shim<'a>(out: &mut OutFile<'a>, efn: &'a ExternFn) {
627633
out.next_section();
628634
out.set_namespace(&efn.name.namespace);
629635
out.begin_block(Block::ExternC);
630-
if let Some(annotation) = &out.opt.cxx_impl_annotations {
631-
write!(out, "{} ", annotation);
632-
}
636+
begin_function_definition(out);
633637
if efn.throws {
634638
out.builtin.ptr_len = true;
635639
write!(out, "::rust::repr::PtrLen ");
@@ -946,6 +950,9 @@ fn write_rust_function_shim_impl(
946950
// We've already defined this inside the struct.
947951
return;
948952
}
953+
if !out.header {
954+
begin_function_definition(out);
955+
}
949956
write_rust_function_shim_decl(out, local_name, sig, indirect_call);
950957
if out.header {
951958
writeln!(out, ";");
@@ -1483,6 +1490,7 @@ fn write_rust_box_impl(out: &mut OutFile, ident: &Pair) {
14831490
let instance = ident.to_symbol();
14841491

14851492
writeln!(out, "template <>");
1493+
begin_function_definition(out);
14861494
writeln!(
14871495
out,
14881496
"{} *Box<{}>::allocation::alloc() noexcept {{",
@@ -1492,6 +1500,7 @@ fn write_rust_box_impl(out: &mut OutFile, ident: &Pair) {
14921500
writeln!(out, "}}");
14931501

14941502
writeln!(out, "template <>");
1503+
begin_function_definition(out);
14951504
writeln!(
14961505
out,
14971506
"void Box<{}>::allocation::dealloc({} *ptr) noexcept {{",
@@ -1501,6 +1510,7 @@ fn write_rust_box_impl(out: &mut OutFile, ident: &Pair) {
15011510
writeln!(out, "}}");
15021511

15031512
writeln!(out, "template <>");
1513+
begin_function_definition(out);
15041514
writeln!(out, "void Box<{}>::drop() noexcept {{", inner);
15051515
writeln!(out, " cxxbridge1$box${}$drop(this);", instance);
15061516
writeln!(out, "}}");
@@ -1513,16 +1523,19 @@ fn write_rust_vec_impl(out: &mut OutFile, element: &RustName) {
15131523
out.include.cstddef = true;
15141524

15151525
writeln!(out, "template <>");
1526+
begin_function_definition(out);
15161527
writeln!(out, "Vec<{}>::Vec() noexcept {{", inner);
15171528
writeln!(out, " cxxbridge1$rust_vec${}$new(this);", instance);
15181529
writeln!(out, "}}");
15191530

15201531
writeln!(out, "template <>");
1532+
begin_function_definition(out);
15211533
writeln!(out, "void Vec<{}>::drop() noexcept {{", inner);
15221534
writeln!(out, " return cxxbridge1$rust_vec${}$drop(this);", instance);
15231535
writeln!(out, "}}");
15241536

15251537
writeln!(out, "template <>");
1538+
begin_function_definition(out);
15261539
writeln!(
15271540
out,
15281541
"::std::size_t Vec<{}>::size() const noexcept {{",
@@ -1532,6 +1545,7 @@ fn write_rust_vec_impl(out: &mut OutFile, element: &RustName) {
15321545
writeln!(out, "}}");
15331546

15341547
writeln!(out, "template <>");
1548+
begin_function_definition(out);
15351549
writeln!(
15361550
out,
15371551
"::std::size_t Vec<{}>::capacity() const noexcept {{",
@@ -1545,11 +1559,13 @@ fn write_rust_vec_impl(out: &mut OutFile, element: &RustName) {
15451559
writeln!(out, "}}");
15461560

15471561
writeln!(out, "template <>");
1562+
begin_function_definition(out);
15481563
writeln!(out, "const {} *Vec<{0}>::data() const noexcept {{", inner);
15491564
writeln!(out, " return cxxbridge1$rust_vec${}$data(this);", instance);
15501565
writeln!(out, "}}");
15511566

15521567
writeln!(out, "template <>");
1568+
begin_function_definition(out);
15531569
writeln!(
15541570
out,
15551571
"void Vec<{}>::reserve_total(::std::size_t cap) noexcept {{",
@@ -1563,6 +1579,7 @@ fn write_rust_vec_impl(out: &mut OutFile, element: &RustName) {
15631579
writeln!(out, "}}");
15641580

15651581
writeln!(out, "template <>");
1582+
begin_function_definition(out);
15661583
writeln!(
15671584
out,
15681585
"void Vec<{}>::set_len(::std::size_t len) noexcept {{",

0 commit comments

Comments
 (0)