blob: a672329370cd9ba2a65a13659285c5cb7584d64f [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,
24 RUST_TYPE_BY_VALUE,
David Tolnaydbc53772020-10-28 17:28:51 -070025 UNSUPPORTED_TYPE,
David Tolnay7db73692019-10-20 14:51:12 -040026 USE_NOT_ALLOWED,
27];
28
29pub static BOX_CXX_TYPE: Error = Error {
30 msg: "Box of a C++ type is not supported yet",
31 label: None,
David Tolnayb3b24a12020-12-01 15:27:43 -080032 note: Some("hint: use UniquePtr<> or SharedPtr<>"),
David Tolnay7db73692019-10-20 14:51:12 -040033};
34
David Tolnay7db73692019-10-20 14:51:12 -040035pub static CXXBRIDGE_RESERVED: Error = Error {
36 msg: "identifiers starting with cxxbridge are reserved",
37 label: Some("reserved identifier"),
38 note: Some("identifiers starting with cxxbridge are reserved"),
39};
40
41pub static CXX_STRING_BY_VALUE: Error = Error {
42 msg: "C++ string by value is not supported",
43 label: None,
44 note: Some("hint: wrap it in a UniquePtr<>"),
45};
46
47pub static CXX_TYPE_BY_VALUE: Error = Error {
48 msg: "C++ type by value is not supported",
49 label: None,
David Tolnayb3b24a12020-12-01 15:27:43 -080050 note: Some("hint: wrap it in a UniquePtr<> or SharedPtr<>"),
David Tolnay7db73692019-10-20 14:51:12 -040051};
52
David Tolnaya3f64072020-05-05 10:24:24 -070053pub static DISCRIMINANT_OVERFLOW: Error = Error {
54 msg: "discriminant overflow on value after ",
55 label: Some("discriminant overflow"),
56 note: Some("note: explicitly set `= 0` if that is desired outcome"),
57};
58
David Tolnay75c23852020-10-27 21:07:53 -070059pub static DOT_INCLUDE: Error = Error {
60 msg: "#include relative to `.` or `..` is not supported in Cargo builds",
61 label: Some("#include relative to `.` or `..` is not supported in Cargo builds"),
62 note: Some("note: use a path starting with the crate name"),
63};
64
David Tolnay7db73692019-10-20 14:51:12 -040065pub static DOUBLE_UNDERSCORE: Error = Error {
66 msg: "identifiers containing double underscore are reserved in C++",
67 label: Some("reserved identifier"),
68 note: Some("identifiers containing double underscore are reserved in C++"),
69};
70
71pub static RUST_TYPE_BY_VALUE: Error = Error {
72 msg: "opaque Rust type by value is not supported",
73 label: None,
74 note: Some("hint: wrap it in a Box<>"),
75};
76
David Tolnaydbc53772020-10-28 17:28:51 -070077pub static UNSUPPORTED_TYPE: Error = Error {
78 msg: "unsupported type: ",
79 label: Some("unsupported type"),
80 note: None,
81};
82
David Tolnay7db73692019-10-20 14:51:12 -040083pub static USE_NOT_ALLOWED: Error = Error {
84 msg: "`use` items are not allowed within cxx bridge",
85 label: Some("not allowed"),
86 note: Some(
87 "`use` items are not allowed within cxx bridge; only types defined\n\
88 within your bridge, primitive types, or types exported by the cxx\n\
89 crate may be used",
90 ),
91};