blob: a60b7da51102176aea5995d57480c7eee32daa52 [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 Tolnay7db73692019-10-20 14:51:12 -040022 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
David Tolnay7db73692019-10-20 14:51:12 -040033pub static CXXBRIDGE_RESERVED: Error = Error {
34 msg: "identifiers starting with cxxbridge are reserved",
35 label: Some("reserved identifier"),
36 note: Some("identifiers starting with cxxbridge are reserved"),
37};
38
39pub static CXX_STRING_BY_VALUE: Error = Error {
40 msg: "C++ string by value is not supported",
41 label: None,
42 note: Some("hint: wrap it in a UniquePtr<>"),
43};
44
45pub static CXX_TYPE_BY_VALUE: Error = Error {
46 msg: "C++ type by value is not supported",
47 label: None,
David Tolnayc4ddb4d2020-05-01 10:00:17 -070048 note: Some("hint: wrap it in a UniquePtr<>"),
David Tolnay7db73692019-10-20 14:51:12 -040049};
50
David Tolnaya3f64072020-05-05 10:24:24 -070051pub static DISCRIMINANT_OVERFLOW: Error = Error {
52 msg: "discriminant overflow on value after ",
53 label: Some("discriminant overflow"),
54 note: Some("note: explicitly set `= 0` if that is desired outcome"),
55};
56
David Tolnay7db73692019-10-20 14:51:12 -040057pub 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};