blob: 959708954fd51069c43412d43c5237932afd5bde [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,
25 USE_NOT_ALLOWED,
26];
27
28pub static BOX_CXX_TYPE: Error = Error {
29 msg: "Box of a C++ type is not supported yet",
30 label: None,
31 note: Some("hint: use UniquePtr<>"),
32};
33
David Tolnay7db73692019-10-20 14:51:12 -040034pub static CXXBRIDGE_RESERVED: Error = Error {
35 msg: "identifiers starting with cxxbridge are reserved",
36 label: Some("reserved identifier"),
37 note: Some("identifiers starting with cxxbridge are reserved"),
38};
39
40pub static CXX_STRING_BY_VALUE: Error = Error {
41 msg: "C++ string by value is not supported",
42 label: None,
43 note: Some("hint: wrap it in a UniquePtr<>"),
44};
45
46pub static CXX_TYPE_BY_VALUE: Error = Error {
47 msg: "C++ type by value is not supported",
48 label: None,
David Tolnayc4ddb4d2020-05-01 10:00:17 -070049 note: Some("hint: wrap it in a UniquePtr<>"),
David Tolnay7db73692019-10-20 14:51:12 -040050};
51
David Tolnaya3f64072020-05-05 10:24:24 -070052pub static DISCRIMINANT_OVERFLOW: Error = Error {
53 msg: "discriminant overflow on value after ",
54 label: Some("discriminant overflow"),
55 note: Some("note: explicitly set `= 0` if that is desired outcome"),
56};
57
David Tolnay75c23852020-10-27 21:07:53 -070058pub static DOT_INCLUDE: Error = Error {
59 msg: "#include relative to `.` or `..` is not supported in Cargo builds",
60 label: Some("#include relative to `.` or `..` is not supported in Cargo builds"),
61 note: Some("note: use a path starting with the crate name"),
62};
63
David Tolnay7db73692019-10-20 14:51:12 -040064pub static DOUBLE_UNDERSCORE: Error = Error {
65 msg: "identifiers containing double underscore are reserved in C++",
66 label: Some("reserved identifier"),
67 note: Some("identifiers containing double underscore are reserved in C++"),
68};
69
70pub static RUST_TYPE_BY_VALUE: Error = Error {
71 msg: "opaque Rust type by value is not supported",
72 label: None,
73 note: Some("hint: wrap it in a Box<>"),
74};
75
76pub static USE_NOT_ALLOWED: Error = Error {
77 msg: "`use` items are not allowed within cxx bridge",
78 label: Some("not allowed"),
79 note: Some(
80 "`use` items are not allowed within cxx bridge; only types defined\n\
81 within your bridge, primitive types, or types exported by the cxx\n\
82 crate may be used",
83 ),
84};