Squashed 'third_party/autocxx/' changes from c35090b75..fdfb26e26
fdfb26e26 Merge pull request #1315 from google/update-for-proc-macro-prob
ed6ab7560 cargo update
bfca1e046 Merge pull request #1310 from google/remove-errant-line
b06647b89 Remove commented Cargo line
dfb63e2fa Merge pull request #1309 from google/syn-newtype-wrapper-3
c3cdbcbe3 Newtype wrapper for more concise syn debug output.
2743df8f7 Merge pull request #1306 from google/more-cpp-version-notes-tests
1b68eb0b9 Further documentation on C++ versions.
907b2eff3 Merge pull request #1305 from google/cpp-version-notes
90a17d9c2 Documentation about C++ versions.
60230d257 Merge pull request #1299 from google/rev-0.26
10346e838 Revise to 0.26.
5492cb25f Merge pull request #1297 from google/dyn-trait-test
ad8fd562f Merge pull request #1298 from google/fix-moveit-unsoundness
3ff66d1c2 Use new trait in tests.
2f8fb49f9 Fix subclass Emplace trait name.
e420eb7b4 Merge commit '93ed457' into fix-moveit-unsoundness
5e863df88 Roll to moveit 0.6.
0386ad9c8 Testing and documenting dynamic dispatch for CppRef.
ad9377beb Merge pull request #1274 from google/test-for-1265
84281f824 Merge pull request #1296 from google/fix-mutable-refs-part-two
21d72ad05 Fix mutable ref returns, part two.
cfbe62b08 Merge pull request #1295 from google/fix-1294
a67fbe6a6 Fix reference wrappers + mutable refs problem.
366d1a32b Merge pull request #1293 from google/roll-bindgen-2
8cacf99c2 Ignore new test so it can be merged in.
b9a56c697 Absorb published autocxx-bindgen 0.65.1.
1bfbf9dcc Merge pull request #1292 from google/reference-wrapper-changes
7000c91e6 Upgrade to bindgen 0.65.1.
d35bdbd59 Fix doc problem.
43d94cf1f Remove unused features.
ebf858266 Improve reference wrapper example.
e0dfbf958 Allow unsized types in C++ references.
004ef5ab9 Add comments to C++ reference
7c8b8c0f6 Add comment on potential lurking bug.
902077adc Switch reference wrappers' Deref
6ee12660a Merge pull request #1286 from maurer/syn-2
2633a9aaf Update to syn-2
6cb6d5879 Merge pull request #1291 from badicsalex/main
718c50d30 Crude workaround for nested anonymous enums bug
b1ee9dae5 Add test for nested anonymous enums
cf123189e Merge pull request #1290 from google/adetaylor-patch-2
0c27dcb18 Update bug_report.md
73cf4798b Update issue templates
cce6f6c5d Merge pull request #1288 from google/clippy-1.70
b43a16e59 Clippy fix.
93ed45714 Simplify generics
7e6fc4982 Remove `moveit::EmplaceUnpinned`
2113daf76 Make `as_mov` take `ptr: impl AsMove<P>` and relax bound to `P: Deref`
2e442110d Patch moveit dependency
ad69a8417 Merge pull request #1284 from google/cargo-update-2
776bc8162 Merge pull request #1283 from google/subclass-diagnostics
70f9f0f7e cargo update to remove vulnerable version of time.
25c0ded71 Further book fixes.
f8749c71c Book fixes.
fee4442cf Fix diagnostics for in-line subclass macro.
ae4a4eeeb Merge pull request #1277 from gen-xu/main
02ba1a54e fix: feature flag for runtime
e397e2e71 Merge branch 'main' into test-for-1265
bec2301b5 Merge pull request #1264 from google/reject-unions
b0275ff0f Merge pull request #1275 from google/typo3
370e81d87 Fix typo.
f050f5ae7 Add test for unsoundness.
a44f39806 Format
deba33de8 Further tweaks
994a0b164 Merge pull request #1273 from google/rvalueparamhandler-comment
7b8b14507 More using nuance.
e9a62b429 Merge pull request #1272 from google/1270
98fcc88a8 Add comment explaining RValueParamHandler.
d93a1fd1c Attempts at fixing 1270.
6594410d4 Use a more sophisticated 'using' statement.
abb59541f Merge pull request #1263 from google/va-list
1f9a1d258 Attempt to fix namespaced anon struct case.
d4ad6fecc Add test for funsigned-char
f27bf7856 Add va_list test.
7f38ae7c9 Shorten excessively long name.
f4e57eaed Fix namespaced destructors.
ada12160e Merge pull request #1259 from google/fix-remove-dir-all
edabf36f1 Merge pull request #1258 from google/rev-0.25
8c7452b68 Roll tempfile.
22515641f Revise to 0.25.0.
9f5c550c5 Merge pull request #1257 from htynkn/patch-1
7c724ba32 Update examples.md
97c103aaa Update examples.md
a9edb13c5 fix 404 in examples document
c3771d02d Merge pull request #1253 from nak3/add-cxx.h
b429077f8 Merge pull request #1249 from google/reduction-tweaks
143b2944f Merge pull request #1254 from google/issue-1238
94f0cd51b Reject fns returning mut refs but no mut ref param
e7640d2dd Add failing test case for issue 1238.
0f1a28a28 Tweaks to reduction
252608fb4 Add an option to autocxx_gen to create cxx.h
79c72939e Merge pull request #1250 from google/tests-forcing-wrappers
2121c1a30 Disable the two tests which fail when wrappers are forced.
52028c9a2 Add to book about this.
4359edcf3 Clippy fix.
c34ae5e6d Add github workflow.
dca93fa74 Add to test suite
e20192af4 Add option to force wrapper generation.
5540b8618 Merge pull request #1206 from russelltg/construct_concrete_class
1783da369 Merge pull request #1248 from nak3/llvm-example
a1468090a Merge pull request #1247 from nak3/fix-log
9154d3187 Merge pull request #1245 from nak3/use-subclass
d24515a90 Enable llvm example for CI
36f7a3570 Print the number of files generated in the error of `--generate-exact`
faf3d8202 Do not use deprecated annotation is_subclass in examples
a303a9a72 fmt
e47ff2eff Merge pull request #1241 from google/reproduce-1237
8db3a4241 Fix problem with nested extern types.
20345ebbb Merge pull request #1242 from google/remove-no-mod-found-error
83cec3c50 Clippy fix.
d0e1b23e3 Merge pull request #1240 from google/fix-1229
88e702523 Support extern_rust_type without include_cpp!
6a429bd62 Add test for autodiscover without include_cpp
3bd7dba80 Fix use of extern_rust_type in Box<T> in wrappers.
68c236afb Rename a test to avoid ambiguity.
93e4c9629 Remove warning from test case.
68d2323c5 Fix for Box being passed without std::move.
ba81127ca Add reproduction test for #1237
ca436170e Experimental fix for #1229
59eaac153 Merge pull request #1224 from kitlith/no_std
05c0071a0 Move duplicate Pin definition into "non_cannonical_name"
14eeb91db Merge pull request #1232 from nak3/fix-comment
047943e22 Merge pull request #1234 from nak3/fix-help
31ccc891e Merge branch 'google:main' into test
cb16073c3 Add test for issue #1229
c7b6af021 Make help message of gen-rs-include accurate
9c359b4cc Fix comment about AUTOCXX_RS_JSON_ARCHIVE
8a5e11574 Merge remote-tracking branch 'origin/main' into construct_concrete_class
0b46f92ce go through APIs one final time to go through methods before classes
dcb4de8ba Merge pull request #1225 from EmbarkStudios/main
74a78bd16 FIXUP! cargo fmt
b579e7cde Merge pull request #1227 from google/linking-docs
29c267f4f Add some generic advice about linking.
6e1200d3a Merge pull request #1226 from google/remove-publish-delay
70b2d2b43 Cargo publish now waits automatically.
21a007020 Merge pull request #1223 from google/test-for-1214
a6ffcc103 Merge branch 'main' of github.com:google/autocxx into test-for-1214
788816f30 Format.
8935e64bd Revise to fixed autocxx-bindgen version.
e0da33972 Furthger enhance test.
88641ff57 Slightly bolstering an existing test.
2e4318803 Automatically create outdir if it doesn't exist
ad89df311 when adding a lifetime to pinned reference, allow from core as well.
6a09a1d1c Replace std with core (where possible) in integration tests.
abed8eabe s/::std/::core/, where possible
a3ab76cd7 Merge pull request #1222 from google/rev-0.24
21995a555 Add test for #1214.
1100f09f4 Format.
6c252fad2 More clippy changes.
6c3d25c09 Revise to 0.24.0
9e69fae2d Merge pull request #1193 from google/test-1192
4400acf2a Merge pull request #1221 from google/document-expectations
4d6f80303 Add comments towards #1192.
bde880b67 Merge pull request #1220 from google/repro-1197
aef43a1b8 Merge pull request #1217 from google/add_doc_cfg
c1102a73b Merge pull request #1218 from google/improve-diagnostic
0e8dd146b Merge pull request #1219 from google/no-rewrite
8cd277b4b Make cxxgen.h names predictable in autocxx-build.
e5898442c Fix doc build issue.
7433ac6a5 Improve diagnostics for wrong filename. Fixes #1200.
ae9181f43 Avoid unnecessary rebuilds.
b3748f736 Merge pull request #1216 from google/clippy-new
6a9d9227b Format.
c90cd896e address some comments
ef6dfd9ac Latest clippy fixes.
e28826e00 Clippy
103ce3f9e Merge pull request #1203 from aaronrsiphone/patch-1
2db6e7341 Merge pull request #1210 from nak3/remove-memory
eb486273a Merge pull request #1208 from nak3/fix-cpp_calling_rust
4d831b6a5 Merge pull request #1209 from nak3/fix-typo
316e63643 Merge pull request #1213 from nak3/bump-llvm
495e90916 Bump autocxx version in examples/llvm
49ba02805 Remove unnecessary memory include
fd728b20f Fix typo
acc14b9b6 Add test in github action
5def9b050 Bump miette to 5.x
8d4d785f4 clippy
e1d172f4a fmt
38f26efcc add missing trait
12bf667d1 listen to clippy
f6829c226 fix up overload resolution
d2aa27715 some more work
910e7b5f6 get started
b7a23c5d0 Merge pull request #1202 from google/reference-tweak
eb4b28d5b Update building.md
a476df3e5 Add a note about unsafety of reference wrappers.
34a143f12 Merge pull request #1199 from google/clippy-fixes
4b6020f7c Fix new cargo doc error.
c132a0180 Clippy fixes.
bd0efed70 Fix issue 1192.
81a3d9686 Log some more details of some APIs.
a7c4d35dd Fix the test
16c8a7059 Add test for issue 1192.
f6427a110 Merge pull request #1188 from google/rev-0.23.1
f5ea8a674 Revise to 0.23.1
1c11f4b78 Merge pull request #1187 from google/recursive-struct-fields
f68e08d21 Denote only dependencies of real field types.
a009d0f86 Add tests for circular dependencies.
034e10432 Merge pull request #1185 from google/rev-0.23
05a5c4243 Revise to 0.23.0.
0885061f4 Merge pull request #1180 from google/fix-815
1ee6da4c2 Merge branch 'main' of github.com:google/autocxx into fix-815
b00c5cd17 Merge pull request #1184 from google/nightly-clippies
74dadfb26 Further clippy fixes.
f81c4db3c Further clippy fixes.
d0c5616a2 Shrink error types to keep clippy happy.
5cae78b3d Merge branch 'main' of github.com:google/autocxx into fix-815
68d280b3c Merge pull request #1183 from google/merge-bindgen-upstream-0.62
8aed5e309 Update to released autocxx-bindgen.
59da591a0 Merge pull request #1179 from google/failing-1170-test
65dd0e218 Format.
775317a85 Cargo lock
f052bbdd7 Test against upstream bindgen 0.62.
a19307aa8 Depend on custom bindgen branch
162ec7df8 Remove bogus bits of test
29296ee9c Consider that enums are always movable/destroyable.
4eab29a29 Properly propagate deps for non-POD structs
04eab3251 Simpler test for #1170.
66ca18c78 Record defaulted attributes - no intentional changes yet
3ad39ce5c Failing test for derived class.
f3a803040 Test for explicitly defaulted constructors.
782d1365f Adding failing test for #1170.
6cca9b29c Merge pull request #1172 from google/reduce-with-rustc
9d021f66f Typo.
ee2bdf87f Merge pull request #1176 from google/rustversion-swap
3b28ff920 Fix nightly check error.
1cdbcc964 Clippy complaint.
bc5f4ff05 Compile generated rust code during reduction.
5ef057dce Merge pull request #1173 from google/up-of-vecs
9577311aa Update integration-tests/tests/cpprefs_test.rs
1cb8338a1 Eliminate further use of rustc_version.
e78b73b1c Remove dependency on rustc_version.
1b949ad9c Fix test.
20c8d6ba7 Merge pull request #1175 from google/1152-upmerge
8f2dbaef0 Fix compatibility with clap 3.2.
dda51d028 Merge branch 'main' of github.com:google/autocxx into 1152-upmerge
3086a9023 Merge pull request #1168 from google/extern_rust_fun_type_checking
14f224fde Merge pull request #1171 from google/reduce-quicker
fbeb0f3d6 Adding a test.
ea57ea7d7 Slight reduction speedup.
26f9cf4a2 extern_rust_function types: diagnostics
1196c39b1 Rename: ConvertError -> ConvertErrorFromCpp
759970ae6 Merge pull request #1164 from google/cppref-changes
cb9c680b2 Adding diagnostics for use on non-nightly.
93657b848 Add failing test for extern_rust_function
075bd8e79 Switch from receiver feature to arbitrary_self_types
8c576081d Fix tests for nightly.
51e4c271c Doc fixes.
1204dc7fa Rewrite reference_wrapper.rs to be structs.
c2846add0 Merge pull request #1163 from google/rev-cxx-1.0.72
4d939f0d5 Merge pull request #1162 from google/fix-1161
3d2767958 Revise cxx to 1.0.78.
cf96537ca Clippy fix.
458384470 Add Box test.
23cff78ca Fix GC problem with extern_rust_type.
b24563627 Merge pull request #1158 from google/issue-1097-partial-fix
1ce2ee335 Merge pull request #1160 from google/clippy-1.64-fix
3d376da55 Rust 1.64 clippy lint.
d01bcece0 Merge pull request #1157 from google/adetaylor-patch-1
bce713bfa Partial fix for issue 1097.
7460bfacb Remove extra logging
2d86cdb4a Merge pull request #1156 from google/fix-1143
e7ca09610 Clippy fix.
4fdb3ca22 Enable test.
40d70634e Fix #1143.
f785a168d Merge pull request #1150 from bsilver8192/extern_cpp_type-different-name
79b6b91df Update deps, format TOML
8d2e1dffb Merge pull request #1154 from google/rev-0.22.4
6555d8212 Revise to 0.22.4.
4b44f7f20 Merge pull request #1153 from google/autocxx-bindgen-0.60.3
05dcbf555 Update autocxx-bindgen and bump version to 0.22.4
2388f2d50 Support `extern_cpp_type!` with a different name
7cfa5ea58 Merge pull request #1149 from google/rev-autocxx-bindgen-0.60.1
dadb77ac5 Use official release version.
25cc290a9 Use specific branch and merge fixes
9d2487fab Revise to autocxx-bindgen 0.60.1.
8a9f5fd6d Merge pull request #1145 from boydjohnson/test-case
9d7d2cbdd Merge pull request #1147 from bsilver8192/multiple-json-archive-paths
948e49c4f Merge pull request #1148 from bsilver8192/1.63.0-warning-fixes
c3c020459 Support multiple AUTOCXX_RS_JSON_ARCHIVE entries
37353fabd Fix new clippy and doc warnings in 1.63.0
1e1d16d73 Add failing test case
d0bc76eb5 Merge pull request #1137 from bsilver8192/impl-abstract-type
ec7a4541a Generate `impl UniquePtr` for abstract types too
b830b9da6 Merge pull request #1139 from bsilver8192/bump-mdbook
da8dbd829 Bump mdbook to fix build on nightly
cdebaee64 Merge pull request #1136 from google/disable-windows-gnu-2
5fcc700c7 Disable windows-gnu tests.
0f8cf6309 Fix a comment.
b60c4d032 Merge pull request #1127 from dtolnay-contrib/prettyplease
8b766bd46 Pretty print using prettyplease instead of rustfmt
Change-Id: I0529fc0c35c16160944f5b3a5326c2d53fbe904b
git-subtree-dir: third_party/autocxx
git-subtree-split: fdfb26e26602e24466dfc506782567deb72c9a29
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/engine/src/conversion/convert_error.rs b/engine/src/conversion/convert_error.rs
index ba8344d..855b235 100644
--- a/engine/src/conversion/convert_error.rs
+++ b/engine/src/conversion/convert_error.rs
@@ -8,19 +8,35 @@
use indexmap::set::IndexSet as HashSet;
+use crate::minisyn::Ident;
use itertools::Itertools;
-use syn::Ident;
+use miette::{Diagnostic, SourceSpan};
+use proc_macro2::Span;
use thiserror::Error;
use crate::{
- known_types,
- types::{make_ident, Namespace, QualifiedName},
+ known_types, proc_macro_span_to_miette_span,
+ types::{make_ident, InvalidIdentError, Namespace, QualifiedName},
};
-#[derive(Debug, Clone, Error)]
+/// Errors which can occur during conversion
+#[derive(Debug, Clone, Error, Diagnostic)]
pub enum ConvertError {
#[error("The initial run of 'bindgen' did not generate any content. This might be because none of the requested items for generation could be converted.")]
NoContent,
+ #[error(transparent)]
+ Cpp(ConvertErrorFromCpp),
+ #[error(transparent)]
+ #[diagnostic(transparent)]
+ Rust(LocatedConvertErrorFromRust),
+}
+
+/// Errors that can occur during conversion which are detected from some C++
+/// source code. Currently, we do not gain span information from bindgen
+/// so these errors are presented without useful source code snippets.
+/// We hope to change this in future.
+#[derive(Debug, Clone, Error)]
+pub enum ConvertErrorFromCpp {
#[error("An item was requested using 'generate_pod' which was not safe to hold by value in Rust. {0}")]
UnsafePodType(String),
#[error("Bindgen generated some unexpected code in a foreign mod section. You may have specified something in a 'generate' directive which is not currently compatible with autocxx.")]
@@ -39,8 +55,14 @@
ConflictingTemplatedArgsWithTypedef(QualifiedName),
#[error("Function {0} has a parameter or return type which is either on the blocklist or a forward declaration")]
UnacceptableParam(String),
- #[error("Function {0} has a return reference parameter, but 0 or >1 input reference parameters, so the lifetime of the output reference cannot be deduced.")]
- NotOneInputReference(String),
+ #[error("Function {0} has a reference return value, but no reference parameters, so the lifetime of the output reference cannot be deduced.")]
+ NoInputReference(String),
+ #[error("Function {0} has a reference return value, but >1 input reference parameters, so the lifetime of the output reference cannot be deduced.")]
+ MultipleInputReferences(String),
+ #[error("Function {0} has a mutable reference return value, but no mutable reference parameters, so the lifetime of the output reference cannot be deduced.")]
+ NoMutableInputReference(String),
+ #[error("Function {0} has a mutable reference return value, but >1 input mutable reference parameters, so the lifetime of the output reference cannot be deduced.")]
+ MultipleMutableInputReferences(String),
#[error("Encountered type not yet supported by autocxx: {0}")]
UnsupportedType(String),
#[error("Encountered type not yet known by autocxx: {0}")]
@@ -53,8 +75,12 @@
UnexpectedUseStatement(Option<String>),
#[error("Type {} was parameterized over something complex which we don't yet support", .0.to_cpp_name())]
TemplatedTypeContainingNonPathArg(QualifiedName),
- #[error("Pointer pointed to something unsupported")]
- InvalidPointee,
+ #[error("Pointer pointed to an array, which is not yet supported")]
+ InvalidArrayPointee,
+ #[error("Pointer pointed to another pointer, which is not yet supported")]
+ InvalidPointerPointee,
+ #[error("Pointer pointed to something unsupported (autocxx only supports pointers to named types): {0}")]
+ InvalidPointee(String),
#[error("The 'generate' or 'generate_pod' directive for '{0}' did not result in any code being generated. Perhaps this was mis-spelled or you didn't qualify the name with any namespaces? Otherwise please report a bug.")]
DidNotGenerateAnything(String),
#[error("Found an attempt at using a forward declaration ({}) inside a templated cxx type such as UniquePtr or CxxVector. If the forward declaration is a typedef, perhaps autocxx wasn't sure whether or not it involved a forward declaration. If you're sure it didn't, then you may be able to solve this by using instantiable!.", .0.to_cpp_name())]
@@ -63,14 +89,12 @@
Blocked(QualifiedName),
#[error("This function or method uses a type where one of the template parameters was incomprehensible to bindgen/autocxx - probably because it uses template specialization.")]
UnusedTemplateParam,
- #[error("Names containing __ are reserved by C++ so not acceptable to cxx")]
- TooManyUnderscores,
#[error("This item relies on a type not known to autocxx ({})", .0.to_cpp_name())]
UnknownDependentType(QualifiedName),
#[error("This item depends on some other type(s) which autocxx could not generate, some of them are: {}", .0.iter().join(", "))]
IgnoredDependent(HashSet<QualifiedName>),
- #[error("The item name '{0}' is a reserved word in Rust.")]
- ReservedName(String),
+ #[error(transparent)]
+ InvalidIdent(InvalidIdentError),
#[error("This item name is used in multiple namespaces. At present, autocxx and cxx allow only one type of a given name. This limitation will be fixed in future. (Items found with this name: {})", .0.iter().join(", "))]
DuplicateCxxBridgeName(Vec<String>),
#[error("This is a method on a type which can't be used as the receiver in Rust (i.e. self/this). This is probably because some type involves template specialization.")]
@@ -123,29 +147,71 @@
MethodInAnonymousNamespace,
#[error("We're unable to make a concrete version of this template, because we found an error handling the template.")]
ConcreteVersionOfIgnoredTemplate,
- #[error("bindgen decided to call this type _bindgen_ty_N because it couldn't deduce the correct name for it. That means we can't generate C++ bindings to it.")]
- BindgenTy,
#[error("This is a typedef to a type in an anonymous namespace, not currently supported.")]
TypedefToTypeInAnonymousNamespace,
#[error("This type refers to a generic type parameter of an outer type, which is not yet supported.")]
ReferringToGenericTypeParam,
#[error("This forward declaration was nested within another struct/class. autocxx is unable to represent inner types if they are forward declarations.")]
ForwardDeclaredNestedType,
+ #[error("Problem handling function argument {arg}: {err}")]
+ Argument {
+ arg: String,
+ #[source]
+ err: Box<ConvertErrorFromCpp>,
+ },
+}
+
+/// Error types derived from Rust code. This is separate from [`ConvertError`] because these
+/// may have spans attached for better diagnostics.
+#[derive(Debug, Clone, Error)]
+pub enum ConvertErrorFromRust {
+ #[error("extern_rust_function only supports limited parameter and return types. This is not such a supported type")]
+ UnsupportedTypeForExternFun,
+ #[error("extern_rust_function requires a fully qualified receiver, that is: fn a(self: &SomeType) as opposed to fn a(&self)")]
+ ExternRustFunRequiresFullyQualifiedReceiver,
+ #[error("extern_rust_function cannot support &mut T references; instead use Pin<&mut T> (see cxx documentation for more details")]
+ PinnedReferencesRequiredForExternFun,
+ #[error("extern_rust_function cannot currently support qualified type paths (that is, foo::bar::Baz). All type paths must be within the current module, imported using 'use'. This restriction may be lifted in future.")]
+ NamespacesNotSupportedForExternFun,
+ #[error("extern_rust_function signatures must never reference Self: instead, spell out the type explicitly.")]
+ ExplicitSelf,
+}
+
+/// A [`ConvertErrorFromRust`] which also implements [`miette::Diagnostic`] so can be pretty-printed
+/// to show the affected span of code.
+#[derive(Error, Debug, Diagnostic, Clone)]
+#[error("{err}")]
+pub struct LocatedConvertErrorFromRust {
+ err: ConvertErrorFromRust,
+ #[source_code]
+ file: String,
+ #[label("error here")]
+ span: SourceSpan,
+}
+
+impl LocatedConvertErrorFromRust {
+ pub(crate) fn new(err: ConvertErrorFromRust, span: &Span, file: &str) -> Self {
+ Self {
+ err,
+ span: proc_macro_span_to_miette_span(span),
+ file: file.to_string(),
+ }
+ }
}
/// Ensures that error contexts are always created using the constructors in this
/// mod, therefore undergoing identifier sanitation.
-#[derive(Clone)]
+#[derive(Clone, Debug)]
struct PhantomSanitized;
/// The context of an error, e.g. whether it applies to a function or a method.
/// This is used to generate suitable rustdoc in the output codegen so that
/// the errors can be revealed in rust-analyzer-based IDEs, etc.
-#[derive(Clone)]
-pub(crate) struct ErrorContext(ErrorContextType, PhantomSanitized);
+#[derive(Clone, Debug)]
+pub(crate) struct ErrorContext(Box<ErrorContextType>, PhantomSanitized);
/// All idents in this structure are guaranteed to be something we can safely codegen for.
-#[derive(Clone)]
+#[derive(Clone, Debug)]
pub(crate) enum ErrorContextType {
Item(Ident),
SanitizedItem(Ident),
@@ -155,8 +221,11 @@
impl ErrorContext {
pub(crate) fn new_for_item(id: Ident) -> Self {
match Self::sanitize_error_ident(&id) {
- None => Self(ErrorContextType::Item(id), PhantomSanitized),
- Some(sanitized) => Self(ErrorContextType::SanitizedItem(sanitized), PhantomSanitized),
+ None => Self(Box::new(ErrorContextType::Item(id)), PhantomSanitized),
+ Some(sanitized) => Self(
+ Box::new(ErrorContextType::SanitizedItem(sanitized)),
+ PhantomSanitized,
+ ),
}
}
@@ -166,14 +235,16 @@
// an impl block.
match Self::sanitize_error_ident(&self_ty) {
None => Self(
- ErrorContextType::Method {
+ Box::new(ErrorContextType::Method {
self_ty,
method: Self::sanitize_error_ident(&method).unwrap_or(method),
- },
+ }),
PhantomSanitized,
),
Some(_) => Self(
- ErrorContextType::SanitizedItem(make_ident(format!("{}_{}", self_ty, method))),
+ Box::new(ErrorContextType::SanitizedItem(make_ident(format!(
+ "{self_ty}_{method}"
+ )))),
PhantomSanitized,
),
}
@@ -195,21 +266,24 @@
}
pub(crate) fn into_type(self) -> ErrorContextType {
- self.0
+ *self.0
}
}
impl std::fmt::Display for ErrorContext {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- match &self.0 {
- ErrorContextType::Item(id) | ErrorContextType::SanitizedItem(id) => write!(f, "{}", id),
- ErrorContextType::Method { self_ty, method } => write!(f, "{}::{}", self_ty, method),
+ match &*self.0 {
+ ErrorContextType::Item(id) | ErrorContextType::SanitizedItem(id) => write!(f, "{id}"),
+ ErrorContextType::Method { self_ty, method } => write!(f, "{self_ty}::{method}"),
}
}
}
#[derive(Clone)]
-pub(crate) struct ConvertErrorWithContext(pub(crate) ConvertError, pub(crate) Option<ErrorContext>);
+pub(crate) struct ConvertErrorWithContext(
+ pub(crate) ConvertErrorFromCpp,
+ pub(crate) Option<ErrorContext>,
+);
impl std::fmt::Debug for ConvertErrorWithContext {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {