Expand discriminant overflow error message
Renders as:
error[cxxbridge]: discriminant overflow on value after 4294967295
┌─ src/main.rs:11:9
│
11 │ B,
│ ^ discriminant overflow
│
= note: explicitly set `= 0` if that is desired outcome
This more closely matches rustc's error message, which is:
error[E0370]: enum discriminant overflowed
--> src/lib.rs:4:5
|
4 | B,
| ^ overflowed on value after 255
|
= note: explicitly set `B = 0` if that is desired outcome
diff --git a/syntax/error.rs b/syntax/error.rs
index f2cb8d1..a60b7da 100644
--- a/syntax/error.rs
+++ b/syntax/error.rs
@@ -18,6 +18,7 @@
CXXBRIDGE_RESERVED,
CXX_STRING_BY_VALUE,
CXX_TYPE_BY_VALUE,
+ DISCRIMINANT_OVERFLOW,
DOUBLE_UNDERSCORE,
RUST_TYPE_BY_VALUE,
USE_NOT_ALLOWED,
@@ -47,6 +48,12 @@
note: Some("hint: wrap it in a UniquePtr<>"),
};
+pub 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 static DOUBLE_UNDERSCORE: Error = Error {
msg: "identifiers containing double underscore are reserved in C++",
label: Some("reserved identifier"),
diff --git a/syntax/parse.rs b/syntax/parse.rs
index 1f6cbac..7e4422d 100644
--- a/syntax/parse.rs
+++ b/syntax/parse.rs
@@ -112,7 +112,8 @@
}
}
if variant.discriminant.is_none() && prev_discriminant.unwrap_or(0) == u32::MAX {
- return Err(Error::new_spanned(variant, "overflowed on value"));
+ let msg = format!("discriminant overflow on value after {}", u32::MAX);
+ return Err(Error::new_spanned(variant, msg));
}
let discriminant =
parse_discriminant(&variant)?.unwrap_or_else(|| prev_discriminant.map_or(0, |n| n + 1));