Repository: dtolnay/cxx (language: rust)

Issue:
Warning on unused variable on use of String or Vec outside of extern "C++" argument position
Compiling the following simple bridge causes a warning to be emitted. There is no warning as long as String or Vec is also used as an `extern "C++"` function argument.

```rust
#[cxx::bridge]
mod ffi {
    struct Struct {
        vec: Vec<u8>,
    }
}
```

```console
$ cargo check
   Compiling repro v0.0.0
warning: repro/target/debug/build/example-eef0763dc2614d88/out/cxxbridge/sources/example/src/main.rs.cc:325:28: warning: unused variable 'unsafe_bitcopy' [-Wunused-const-variable]
warning: constexpr unsafe_bitcopy_t unsafe_bitcopy{};
warning:                            ^
warning: 1 warning generated.
    Finished dev [unoptimized + debuginfo] target(s) in 0.11s
```


Discussion / hints:

Fix patch:
diff --git a/gen/src/builtin.rs b/gen/src/builtin.rs
index adcd04887..36e51d58b 100644
--- a/gen/src/builtin.rs
+++ b/gen/src/builtin.rs
@@ -15,6 +15,7 @@ pub struct Builtins<'a> {
     pub opaque: bool,
     pub layout: bool,
     pub unsafe_bitcopy: bool,
+    pub unsafe_bitcopy_t: bool,
     pub rust_error: bool,
     pub manually_drop: bool,
     pub maybe_uninit: bool,
@@ -74,7 +75,7 @@ pub(super) fn write(out: &mut OutFile) {
         include.utility = true;
         builtin.panic = true;
         builtin.rust_slice = true;
-        builtin.unsafe_bitcopy = true;
+        builtin.unsafe_bitcopy_t = true;
     }
 
     if builtin.rust_slice {
@@ -124,6 +125,10 @@ pub(super) fn write(out: &mut OutFile) {
         include.type_traits = true;
     }
 
+    if builtin.unsafe_bitcopy {
+        builtin.unsafe_bitcopy_t = true;
+    }
+
     out.begin_block(Block::Namespace("rust"));
     out.begin_block(Block::InlineNamespace("cxxbridge1"));
 
@@ -165,6 +170,7 @@ pub(super) fn write(out: &mut OutFile) {
         ifndef::write(out, builtin.rust_str, "CXXBRIDGE1_RUST_STR");
         ifndef::write(out, builtin.rust_slice, "CXXBRIDGE1_RUST_SLICE");
         ifndef::write(out, builtin.rust_box, "CXXBRIDGE1_RUST_BOX");
+        ifndef::write(out, builtin.unsafe_bitcopy_t, "CXXBRIDGE1_RUST_BITCOPY_T");
         ifndef::write(out, builtin.unsafe_bitcopy, "CXXBRIDGE1_RUST_BITCOPY");
         ifndef::write(out, builtin.rust_vec, "CXXBRIDGE1_RUST_VEC");
         ifndef::write(out, builtin.rust_fn, "CXXBRIDGE1_RUST_FN");
diff --git a/include/cxx.h b/include/cxx.h
index 7ee7db7e5..45ec64b9c 100644
--- a/include/cxx.h
+++ b/include/cxx.h
@@ -484,12 +484,15 @@ Fn<Ret(Args...)> Fn<Ret(Args...)>::operator*() const noexcept {
 }
 #endif // CXXBRIDGE1_RUST_FN
 
-#ifndef CXXBRIDGE1_RUST_BITCOPY
-#define CXXBRIDGE1_RUST_BITCOPY
+#ifndef CXXBRIDGE1_RUST_BITCOPY_T
+#define CXXBRIDGE1_RUST_BITCOPY_T
 struct unsafe_bitcopy_t final {
   explicit unsafe_bitcopy_t() = default;
 };
+#endif // CXXBRIDGE1_RUST_BITCOPY_T
 
+#ifndef CXXBRIDGE1_RUST_BITCOPY
+#define CXXBRIDGE1_RUST_BITCOPY
 constexpr unsafe_bitcopy_t unsafe_bitcopy{};
 #endif // CXXBRIDGE1_RUST_BITCOPY
 


Test patch: