blob: 103a54f0505e9f053037e31f1b13eaf4ea790eaf [file] [log] [blame]
David Tolnay7db73692019-10-20 14:51:12 -04001use std::fmt::{self, Display};
2
3#[derive(Copy, Clone)]
4pub struct Error {
5 pub msg: &'static str,
6 pub label: Option<&'static str>,
7 pub note: Option<&'static str>,
8}
9
10impl Display for Error {
11 fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
12 self.msg.fmt(formatter)
13 }
14}
15
16pub static ERRORS: &[Error] = &[
17 BOX_CXX_TYPE,
Myron Ahneba35cf2020-02-05 19:41:51 +070018 VEC_CXX_TYPE,
David Tolnay7db73692019-10-20 14:51:12 -040019 CXXBRIDGE_RESERVED,
20 CXX_STRING_BY_VALUE,
21 CXX_TYPE_BY_VALUE,
22 DOUBLE_UNDERSCORE,
23 RUST_TYPE_BY_VALUE,
24 USE_NOT_ALLOWED,
25];
26
27pub static BOX_CXX_TYPE: Error = Error {
28 msg: "Box of a C++ type is not supported yet",
29 label: None,
30 note: Some("hint: use UniquePtr<>"),
31};
32
Myron Ahneba35cf2020-02-05 19:41:51 +070033pub static VEC_CXX_TYPE: Error = Error {
34 msg: "Vec of a C++ type is not supported yet",
35 label: None,
36 note: Some("hint: use UniquePtr<>"),
37};
38
David Tolnay7db73692019-10-20 14:51:12 -040039pub static CXXBRIDGE_RESERVED: Error = Error {
40 msg: "identifiers starting with cxxbridge are reserved",
41 label: Some("reserved identifier"),
42 note: Some("identifiers starting with cxxbridge are reserved"),
43};
44
45pub static CXX_STRING_BY_VALUE: Error = Error {
46 msg: "C++ string by value is not supported",
47 label: None,
48 note: Some("hint: wrap it in a UniquePtr<>"),
49};
50
51pub static CXX_TYPE_BY_VALUE: Error = Error {
52 msg: "C++ type by value is not supported",
53 label: None,
54 note: Some("hint: wrap it in a Box<> or UniquePtr<>"),
55};
56
57pub static DOUBLE_UNDERSCORE: Error = Error {
58 msg: "identifiers containing double underscore are reserved in C++",
59 label: Some("reserved identifier"),
60 note: Some("identifiers containing double underscore are reserved in C++"),
61};
62
63pub static RUST_TYPE_BY_VALUE: Error = Error {
64 msg: "opaque Rust type by value is not supported",
65 label: None,
66 note: Some("hint: wrap it in a Box<>"),
67};
68
69pub static USE_NOT_ALLOWED: Error = Error {
70 msg: "`use` items are not allowed within cxx bridge",
71 label: Some("not allowed"),
72 note: Some(
73 "`use` items are not allowed within cxx bridge; only types defined\n\
74 within your bridge, primitive types, or types exported by the cxx\n\
75 crate may be used",
76 ),
77};