cxxbridge_macro/syntax/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
use std::fmt::{self, Display};

#[derive(Copy, Clone)]
pub(crate) struct Error {
    pub msg: &'static str,
    #[allow(dead_code)] // only used by cxx-build, not cxxbridge-macro
    pub label: Option<&'static str>,
    #[allow(dead_code)] // only used by cxx-build, not cxxbridge-macro
    pub note: Option<&'static str>,
}

impl Display for Error {
    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
        self.msg.fmt(formatter)
    }
}

pub(crate) static ERRORS: &[Error] = &[
    BOX_CXX_TYPE,
    CXXBRIDGE_RESERVED,
    CXX_STRING_BY_VALUE,
    CXX_TYPE_BY_VALUE,
    DISCRIMINANT_OVERFLOW,
    DOT_INCLUDE,
    DOUBLE_UNDERSCORE,
    RESERVED_LIFETIME,
    RUST_TYPE_BY_VALUE,
    UNSUPPORTED_TYPE,
    USE_NOT_ALLOWED,
];

pub(crate) static BOX_CXX_TYPE: Error = Error {
    msg: "Box of a C++ type is not supported yet",
    label: None,
    note: Some("hint: use UniquePtr<> or SharedPtr<>"),
};

pub(crate) static CXXBRIDGE_RESERVED: Error = Error {
    msg: "identifiers starting with cxxbridge are reserved",
    label: Some("reserved identifier"),
    note: Some("identifiers starting with cxxbridge are reserved"),
};

pub(crate) static CXX_STRING_BY_VALUE: Error = Error {
    msg: "C++ string by value is not supported",
    label: None,
    note: Some("hint: wrap it in a UniquePtr<>"),
};

pub(crate) static CXX_TYPE_BY_VALUE: Error = Error {
    msg: "C++ type by value is not supported",
    label: None,
    note: Some("hint: wrap it in a UniquePtr<> or SharedPtr<>"),
};

pub(crate) static DISCRIMINANT_OVERFLOW: Error = Error {
    msg: "discriminant overflow on value after ",
    label: Some("discriminant overflow"),
    note: Some("note: explicitly set `= 0` if that is desired outcome"),
};

pub(crate) static DOT_INCLUDE: Error = Error {
    msg: "#include relative to `.` or `..` is not supported in Cargo builds",
    label: Some("#include relative to `.` or `..` is not supported in Cargo builds"),
    note: Some("note: use a path starting with the crate name"),
};

pub(crate) static DOUBLE_UNDERSCORE: Error = Error {
    msg: "identifiers containing double underscore are reserved in C++",
    label: Some("reserved identifier"),
    note: Some("identifiers containing double underscore are reserved in C++"),
};

pub(crate) static RESERVED_LIFETIME: Error = Error {
    msg: "invalid lifetime parameter name: `'static`",
    label: Some("'static is a reserved lifetime name"),
    note: None,
};

pub(crate) static RUST_TYPE_BY_VALUE: Error = Error {
    msg: "opaque Rust type by value is not supported",
    label: None,
    note: Some("hint: wrap it in a Box<>"),
};

pub(crate) static UNSUPPORTED_TYPE: Error = Error {
    msg: "unsupported type: ",
    label: Some("unsupported type"),
    note: None,
};

pub(crate) static USE_NOT_ALLOWED: Error = Error {
    msg: "`use` items are not allowed within cxx bridge",
    label: Some("not allowed"),
    note: Some(
        "`use` items are not allowed within cxx bridge; only types defined\n\
         within your bridge, primitive types, or types exported by the cxx\n\
         crate may be used",
    ),
};