blob: f40c4a8e9b9ebbc5851aa05741da0e671e85c515 [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,
18 CXXBRIDGE_RESERVED,
19 CXX_STRING_BY_VALUE,
20 CXX_TYPE_BY_VALUE,
David Tolnaya3f64072020-05-05 10:24:24 -070021 DISCRIMINANT_OVERFLOW,
David Tolnay75c23852020-10-27 21:07:53 -070022 DOT_INCLUDE,
David Tolnay7db73692019-10-20 14:51:12 -040023 DOUBLE_UNDERSCORE,
David Tolnayef1b70d2021-04-08 18:20:29 -070024 RESERVED_LIFETIME,
David Tolnay7db73692019-10-20 14:51:12 -040025 RUST_TYPE_BY_VALUE,
David Tolnaydbc53772020-10-28 17:28:51 -070026 UNSUPPORTED_TYPE,
David Tolnay7db73692019-10-20 14:51:12 -040027 USE_NOT_ALLOWED,
28];
29
30pub static BOX_CXX_TYPE: Error = Error {
31 msg: "Box of a C++ type is not supported yet",
32 label: None,
David Tolnayb3b24a12020-12-01 15:27:43 -080033 note: Some("hint: use UniquePtr<> or SharedPtr<>"),
David Tolnay7db73692019-10-20 14:51:12 -040034};
35
David Tolnay7db73692019-10-20 14:51:12 -040036pub static CXXBRIDGE_RESERVED: Error = Error {
37 msg: "identifiers starting with cxxbridge are reserved",
38 label: Some("reserved identifier"),
39 note: Some("identifiers starting with cxxbridge are reserved"),
40};
41
42pub static CXX_STRING_BY_VALUE: Error = Error {
43 msg: "C++ string by value is not supported",
44 label: None,
45 note: Some("hint: wrap it in a UniquePtr<>"),
46};
47
48pub static CXX_TYPE_BY_VALUE: Error = Error {
49 msg: "C++ type by value is not supported",
50 label: None,
David Tolnayb3b24a12020-12-01 15:27:43 -080051 note: Some("hint: wrap it in a UniquePtr<> or SharedPtr<>"),
David Tolnay7db73692019-10-20 14:51:12 -040052};
53
David Tolnaya3f64072020-05-05 10:24:24 -070054pub static DISCRIMINANT_OVERFLOW: Error = Error {
55 msg: "discriminant overflow on value after ",
56 label: Some("discriminant overflow"),
57 note: Some("note: explicitly set `= 0` if that is desired outcome"),
58};
59
David Tolnay75c23852020-10-27 21:07:53 -070060pub static DOT_INCLUDE: Error = Error {
61 msg: "#include relative to `.` or `..` is not supported in Cargo builds",
62 label: Some("#include relative to `.` or `..` is not supported in Cargo builds"),
63 note: Some("note: use a path starting with the crate name"),
64};
65
David Tolnay7db73692019-10-20 14:51:12 -040066pub static DOUBLE_UNDERSCORE: Error = Error {
67 msg: "identifiers containing double underscore are reserved in C++",
68 label: Some("reserved identifier"),
69 note: Some("identifiers containing double underscore are reserved in C++"),
70};
71
David Tolnayef1b70d2021-04-08 18:20:29 -070072pub static RESERVED_LIFETIME: Error = Error {
73 msg: "invalid lifetime parameter name: `'static`",
74 label: Some("'static is a reserved lifetime name"),
75 note: None,
76};
77
David Tolnay7db73692019-10-20 14:51:12 -040078pub static RUST_TYPE_BY_VALUE: Error = Error {
79 msg: "opaque Rust type by value is not supported",
80 label: None,
81 note: Some("hint: wrap it in a Box<>"),
82};
83
David Tolnaydbc53772020-10-28 17:28:51 -070084pub static UNSUPPORTED_TYPE: Error = Error {
85 msg: "unsupported type: ",
86 label: Some("unsupported type"),
87 note: None,
88};
89
David Tolnay7db73692019-10-20 14:51:12 -040090pub static USE_NOT_ALLOWED: Error = Error {
91 msg: "`use` items are not allowed within cxx bridge",
92 label: Some("not allowed"),
93 note: Some(
94 "`use` items are not allowed within cxx bridge; only types defined\n\
95 within your bridge, primitive types, or types exported by the cxx\n\
96 crate may be used",
97 ),
98};