| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 1 | use std::fmt::{self, Display}; |
| 2 | |
| 3 | #[derive(Copy, Clone)] |
| 4 | pub struct Error { |
| 5 | pub msg: &'static str, |
| 6 | pub label: Option<&'static str>, |
| 7 | pub note: Option<&'static str>, |
| 8 | } |
| 9 | |
| 10 | impl Display for Error { |
| 11 | fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { |
| 12 | self.msg.fmt(formatter) |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | pub static ERRORS: &[Error] = &[ |
| 17 | BOX_CXX_TYPE, |
| 18 | CXXBRIDGE_RESERVED, |
| 19 | CXX_STRING_BY_VALUE, |
| 20 | CXX_TYPE_BY_VALUE, |
| David Tolnay | a3f6407 | 2020-05-05 10:24:24 -0700 | [diff] [blame] | 21 | DISCRIMINANT_OVERFLOW, |
| David Tolnay | 75c2385 | 2020-10-27 21:07:53 -0700 | [diff] [blame] | 22 | DOT_INCLUDE, |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 23 | DOUBLE_UNDERSCORE, |
| 24 | RUST_TYPE_BY_VALUE, |
| David Tolnay | dbc5377 | 2020-10-28 17:28:51 -0700 | [diff] [blame] | 25 | UNSUPPORTED_TYPE, |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 26 | USE_NOT_ALLOWED, |
| 27 | ]; |
| 28 | |
| 29 | pub static BOX_CXX_TYPE: Error = Error { |
| 30 | msg: "Box of a C++ type is not supported yet", |
| 31 | label: None, |
| David Tolnay | b3b24a1 | 2020-12-01 15:27:43 -0800 | [diff] [blame] | 32 | note: Some("hint: use UniquePtr<> or SharedPtr<>"), |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 33 | }; |
| 34 | |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 35 | pub 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 | |
| 41 | pub 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 | |
| 47 | pub static CXX_TYPE_BY_VALUE: Error = Error { |
| 48 | msg: "C++ type by value is not supported", |
| 49 | label: None, |
| David Tolnay | b3b24a1 | 2020-12-01 15:27:43 -0800 | [diff] [blame] | 50 | note: Some("hint: wrap it in a UniquePtr<> or SharedPtr<>"), |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 51 | }; |
| 52 | |
| David Tolnay | a3f6407 | 2020-05-05 10:24:24 -0700 | [diff] [blame] | 53 | pub 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 Tolnay | 75c2385 | 2020-10-27 21:07:53 -0700 | [diff] [blame] | 59 | pub 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 Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 65 | pub 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 | |
| 71 | pub 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 Tolnay | dbc5377 | 2020-10-28 17:28:51 -0700 | [diff] [blame] | 77 | pub static UNSUPPORTED_TYPE: Error = Error { |
| 78 | msg: "unsupported type: ", |
| 79 | label: Some("unsupported type"), |
| 80 | note: None, |
| 81 | }; |
| 82 | |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 83 | pub 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 | }; |