Squashed 'third_party/autocxx/' changes from 629e8fa53..c35090b75

c35090b75 Merge pull request #1131 from google/rev-0.22.3
94f20d716 Revise to 0.22.3.
b4776fdd5 Merge pull request #1070 from google/reference-wrapper
25f08f567 Better encapsulate TypeConversionPolicy. No functional changes.
b389afdeb Add reference wrapper safety policy.
cd169853b Merge pull request #1126 from google/issue-1125
92f48fa30 Merge pull request #1123 from google/segfault-detection
ca60bacca Add comment
724a4971d Add test for issue 1125.
d8a9a8ca7 Detect segfaults in reduction
e147efc7c Merge pull request #1122 from google/rev-0.22.2
dfa9b99a4 Revise to 0.22.2.
4cb1da848 Merge pull request #1120 from chbaker0/main
79afb97d9 Replace lingering tempdir usages with tempfile
f945331a3 Merge pull request #1118 from google/fix-test-fixed-num
5a8b28751 Merge pull request #1117 from google/docs-tweaks
b5486faa1 Merge pull request #1109 from bsilver8192/bindgen-skip-rustfmt
f62c17273 Fix faulty test_fixed_num test.
ad954fa72 Minor doc updates.
eaa1f8737 Leave bindgen enabled when logging is
bdff5db56 Merge pull request #1110 from bsilver8192/subclass-std
922f98be4 Merge pull request #1111 from bsilver8192/subclass-unsafe
bfbcc6b94 Merge pull request #1114 from google/rev-0.22.1
4f68a2e59 Merge pull request #1112 from bsilver8192/subclass-upcast-uniqueptr
993c5705b Revise to 0.22.1.
7bf667bbf Add a function to upcast UniquePtr
733d751a2 Fix clippy and docs
8023cee43 Fix and test subclass without `safety!(unsafe)`
4ae4d47e4 Fix and test subclasses with C++ std in scope
c50b1ee7e Tell bindgen to skip rustfmt
f9b24b90e Merge pull request #1107 from google/reject-anon-namespace-typedefs
070c9755d Merge pull request #1093 from google/always-output-rs
8eb71c5e7 Merge pull request #1095 from google/issue-1094
c86f1ce7e Reject forward declared nested types.
c118dba64 Merge branch 'main' into reject-anon-namespace-typedefs
243079997 Merge pull request #1108 from google/reject-type-param-typedefs
f803c3ba5 Reject type params - fixes #1098
f3381ba52 Reject typedefs to anon namespaces.
669d932a7 Merge pull request #1106 from google/lotsa-failing-tests
f0e8487fe Marking tests as ignored.
524c2bbfc Add tests for multiple issues.
67e16ac2a Merge branch 'main' of github.com:google/autocxx into always-output-rs
5f62daf3f Merge pull request #1104 from google/roll-cxx
43ee55ca2 Further upgrade from 1.0.67 to 1.0.68
e29e3c899 Merge pull request #1100 from bsilver8192/extern_cpp_type-namespace
d2c8edef4 Merge pull request #1101 from google/fix-1081
094dbd957 Roll cxx minimal version.
94c39f35b Merge pull request #1102 from google/fix-book-build
8764f1218 Alter mdbook-mermaid installation.
85543656f Test for issue 1081
b170df056 Fix and test extern_cpp_type with type in a C++ namespace
e4b56dd49 Fix gen tests.
5457e615d Fix #1092.

git-subtree-dir: third_party/autocxx
git-subtree-split: c35090b754619531b4eebdf4d8b583db72349943
Signed-off-by: Brian Silverman <bsilver16384@gmail.com>
Change-Id: Ia34285bc1c30f7e3c71fa9e7b677a58902648843
diff --git a/gen/build/Cargo.toml b/gen/build/Cargo.toml
index 2895526..678a844 100644
--- a/gen/build/Cargo.toml
+++ b/gen/build/Cargo.toml
@@ -8,7 +8,7 @@
 
 [package]
 name = "autocxx-build"
-version = "0.22.0"
+version = "0.22.3"
 authors = ["Adrian Taylor <adetaylor@chromium.org>"]
 edition = "2021"
 license = "MIT OR Apache-2.0"
@@ -22,7 +22,7 @@
 static = [ "autocxx-engine/static" ]
 
 [dependencies]
-autocxx-engine = { version="=0.22.0", path="../../engine", features = ["build"] }
+autocxx-engine = { version="=0.22.3", path="../../engine", features = ["build"] }
 env_logger = "0.9.0"
 indexmap = "1.8"
 
diff --git a/gen/cmd/Cargo.toml b/gen/cmd/Cargo.toml
index 744d29a..51eb56c 100644
--- a/gen/cmd/Cargo.toml
+++ b/gen/cmd/Cargo.toml
@@ -8,7 +8,7 @@
 
 [package]
 name = "autocxx-gen"
-version = "0.22.0"
+version = "0.22.3"
 authors = ["Adrian Taylor <adetaylor@chromium.org>"]
 edition = "2021"
 license = "MIT OR Apache-2.0"
@@ -22,7 +22,7 @@
 static = [ "autocxx-engine/static" ]
 
 [dependencies]
-autocxx-engine = { version="=0.22.0", path="../../engine" }
+autocxx-engine = { version="=0.22.3", path="../../engine" }
 clap = { version = "3.1.2", features = ["cargo"] }
 proc-macro2 = "1.0"
 env_logger = "0.9.0"
@@ -32,10 +32,10 @@
 
 [dev-dependencies]
 assert_cmd = "1.0.3"
-tempdir = "0.3.7"
-autocxx-integration-tests = { path = "../../integration-tests", version="=0.22.0" }
+tempfile = "3.1"
+autocxx-integration-tests = { path = "../../integration-tests", version="=0.22.3" }
 # This is necessary for building the projects created
 # by the trybuild test system...
 autocxx = { path="../.." }
-cxx = "1.0.54"
+cxx = "1.0.68"
 itertools = "0.10.3"
\ No newline at end of file
diff --git a/gen/cmd/src/depfile.rs b/gen/cmd/src/depfile.rs
index 5bb7a66..d8d3626 100644
--- a/gen/cmd/src/depfile.rs
+++ b/gen/cmd/src/depfile.rs
@@ -63,13 +63,13 @@
 mod tests {
     use std::{fs::File, io::Read};
 
-    use tempdir::TempDir;
+    use tempfile::tempdir;
 
     use super::Depfile;
 
     #[test]
     fn test_simple_depfile() {
-        let tmp_dir = TempDir::new("depfile-test").unwrap();
+        let tmp_dir = tempdir().unwrap();
         let f = tmp_dir.path().join("depfile.d");
         let mut df = Depfile::new(&f).unwrap();
         df.add_output(&tmp_dir.path().join("a/b"));
@@ -85,7 +85,7 @@
 
     #[test]
     fn test_multiple_outputs() {
-        let tmp_dir = TempDir::new("depfile-test").unwrap();
+        let tmp_dir = tempdir().unwrap();
         let f = tmp_dir.path().join("depfile.d");
         let mut df = Depfile::new(&f).unwrap();
         df.add_output(&tmp_dir.path().join("a/b"));
diff --git a/gen/cmd/src/main.rs b/gen/cmd/src/main.rs
index 20f278b..8b109c3 100644
--- a/gen/cmd/src/main.rs
+++ b/gen/cmd/src/main.rs
@@ -316,27 +316,33 @@
             name_autocxxgen_h,
         )?;
     }
-    //writer.write_placeholders(header_counter.into_inner(), desired_number, "h")?;
     if matches.is_present("gen-rs-include") {
+        if !matches.is_present("fix-rs-include-name") && desired_number.is_some() {
+            return Err(miette::Report::msg(
+                "gen-rs-include and generate-exact requires fix-rs-include-name.",
+            ));
+        }
+        let mut counter = 0usize;
         let rust_buildables = parsed_files
             .iter()
             .flat_map(|parsed_file| parsed_file.get_rs_outputs());
-        for (counter, include_cxx) in rust_buildables.enumerate() {
+        for include_cxx in rust_buildables {
             let rs_code = generate_rs_single(include_cxx);
             let fname = if matches.is_present("fix-rs-include-name") {
-                format!("gen{}.include.rs", counter)
+                name_include_rs(counter)
             } else {
                 rs_code.filename
             };
             writer.write_to_file(fname, rs_code.code.as_bytes())?;
+            counter += 1;
         }
+        writer.write_placeholders(counter, desired_number, name_include_rs)?;
     }
     if matches.is_present("gen-rs-archive") {
         let rust_buildables = parsed_files
             .iter()
             .flat_map(|parsed_file| parsed_file.get_rs_outputs());
         let json = generate_rs_archive(rust_buildables);
-        eprintln!("Writing to gen.rs.json in {:?}", outdir);
         writer.write_to_file("gen.rs.json".into(), json.as_bytes())?;
     }
     if let Some(depfile) = depfile {
@@ -353,6 +359,10 @@
     format!("gen{}.h", counter)
 }
 
+fn name_include_rs(counter: usize) -> String {
+    format!("gen{}.include.rs", counter)
+}
+
 fn get_dependency_recorder(depfile: Rc<RefCell<Depfile>>) -> Box<dyn RebuildDependencyRecorder> {
     Box::new(RecordIntoDepfile(depfile))
 }
diff --git a/gen/cmd/tests/cmd_test.rs b/gen/cmd/tests/cmd_test.rs
index d0e671e..7e455a2 100644
--- a/gen/cmd/tests/cmd_test.rs
+++ b/gen/cmd/tests/cmd_test.rs
@@ -13,7 +13,7 @@
 use assert_cmd::Command;
 use autocxx_integration_tests::{build_from_folder, RsFindMode};
 use itertools::Itertools;
-use tempdir::TempDir;
+use tempfile::{tempdir, TempDir};
 
 static MAIN_RS: &str = concat!(
     include_str!("../../../demo/src/main.rs"),
@@ -31,7 +31,7 @@
 static INPUT2_H: &str = include_str!("data/input2.h");
 static INPUT3_H: &str = include_str!("data/input3.h");
 
-const KEEP_TEMPDIRS: bool = false;
+const KEEP_TEMPDIRS: bool = true;
 
 #[test]
 fn test_help() -> Result<(), Box<dyn std::error::Error>> {
@@ -107,7 +107,7 @@
 
 #[test]
 fn test_gen() -> Result<(), Box<dyn std::error::Error>> {
-    let tmp_dir = TempDir::new("example")?;
+    let tmp_dir = tempdir()?;
     base_test(&tmp_dir, RsGenMode::Single, |_| {})?;
     File::create(tmp_dir.path().join("cxx.h"))
         .and_then(|mut cxx_h| cxx_h.write_all(autocxx_engine::HEADER.as_bytes()))?;
@@ -128,7 +128,7 @@
 
 #[test]
 fn test_gen_archive() -> Result<(), Box<dyn std::error::Error>> {
-    let tmp_dir = TempDir::new("example")?;
+    let tmp_dir = tempdir()?;
     base_test(&tmp_dir, RsGenMode::Archive, |_| {})?;
     File::create(tmp_dir.path().join("cxx.h"))
         .and_then(|mut cxx_h| cxx_h.write_all(autocxx_engine::HEADER.as_bytes()))?;
@@ -148,7 +148,7 @@
 
 #[test]
 fn test_gen_multiple_in_archive() -> Result<(), Box<dyn std::error::Error>> {
-    let tmp_dir = TempDir::new("example")?;
+    let tmp_dir = tempdir()?;
 
     let mut files = HashMap::new();
     files.insert("input2.h", INPUT2_H.as_bytes());
@@ -186,14 +186,15 @@
 
 #[test]
 fn test_include_prefixes() -> Result<(), Box<dyn std::error::Error>> {
-    let tmp_dir = TempDir::new("example")?;
+    let tmp_dir = tempdir()?;
     base_test(&tmp_dir, RsGenMode::Single, |cmd| {
         cmd.arg("--cxx-h-path")
             .arg("foo/")
             .arg("--cxxgen-h-path")
             .arg("bar/")
             .arg("--generate-exact")
-            .arg("3");
+            .arg("3")
+            .arg("--fix-rs-include-name");
     })?;
     assert_contains(&tmp_dir, "autocxxgen0.h", "foo/cxx.h");
     // Currently we don't test cxxgen-h-path because we build the demo code
@@ -203,11 +204,12 @@
 
 #[test]
 fn test_gen_fixed_num() -> Result<(), Box<dyn std::error::Error>> {
-    let tmp_dir = TempDir::new("example")?;
+    let tmp_dir = tempdir()?;
     let depfile = tmp_dir.path().join("test.d");
     base_test(&tmp_dir, RsGenMode::Single, |cmd| {
         cmd.arg("--generate-exact")
             .arg("2")
+            .arg("--fix-rs-include-name")
             .arg("--depfile")
             .arg(depfile);
     })?;
@@ -217,16 +219,16 @@
     assert_contentful(&tmp_dir, "autocxxgen0.h");
     assert_not_contentful(&tmp_dir, "gen1.h");
     assert_not_contentful(&tmp_dir, "autocxxgen1.h");
-    assert_contentful(&tmp_dir, "autocxx-ffi-default-gen.rs");
+    assert_contentful(&tmp_dir, "gen0.include.rs");
     assert_contentful(&tmp_dir, "test.d");
     File::create(tmp_dir.path().join("cxx.h"))
         .and_then(|mut cxx_h| cxx_h.write_all(autocxx_engine::HEADER.as_bytes()))?;
     let r = build_from_folder(
         tmp_dir.path(),
         &tmp_dir.path().join("demo/main.rs"),
-        vec![tmp_dir.path().join("autocxx-ffi-default-gen.rs")],
+        vec![tmp_dir.path().join("gen0.include.rs")],
         &["gen0.cc"],
-        RsFindMode::AutocxxRs,
+        RsFindMode::AutocxxRsFile,
     );
     if KEEP_TEMPDIRS {
         println!("Tempdir: {:?}", tmp_dir.into_path().to_str());
@@ -237,7 +239,7 @@
 
 #[test]
 fn test_gen_preprocess() -> Result<(), Box<dyn std::error::Error>> {
-    let tmp_dir = TempDir::new("example")?;
+    let tmp_dir = tempdir()?;
     let prepro_path = tmp_dir.path().join("preprocessed.h");
     base_test(&tmp_dir, RsGenMode::Single, |cmd| {
         cmd.env("AUTOCXX_PREPROCESS", prepro_path.to_str().unwrap());
@@ -251,7 +253,7 @@
 
 #[test]
 fn test_gen_repro() -> Result<(), Box<dyn std::error::Error>> {
-    let tmp_dir = TempDir::new("example")?;
+    let tmp_dir = tempdir()?;
     let repro_path = tmp_dir.path().join("repro.json");
     base_test(&tmp_dir, RsGenMode::Single, |cmd| {
         cmd.env("AUTOCXX_REPRO_CASE", repro_path.to_str().unwrap());