Implement variants_from_header checking

This commit is contained in:
David Tolnay 2021-04-21 18:23:21 -07:00
parent 15bf509509
commit dd8320320c
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -349,7 +349,7 @@ fn check_api_enum(cx: &mut Check, enm: &Enum) {
check_reserved_name(cx, &enm.name.rust);
check_lifetimes(cx, &enm.generics);
if enm.variants.is_empty() && !enm.explicit_repr {
if enm.variants.is_empty() && !enm.explicit_repr && !enm.variants_from_header {
let span = span_for_enum_error(enm);
cx.error(
span,
@ -357,6 +357,14 @@ fn check_api_enum(cx: &mut Check, enm: &Enum) {
);
}
if enm.variants_from_header && !enm.variants.is_empty() {
let span = span_for_enum_error(enm);
cx.error(
span,
"enum with #![variants_from_header] must be written with no explicit variants",
);
}
for derive in &enm.derives {
if derive.what == Trait::Default || derive.what == Trait::ExternType {
let msg = format!("derive({}) on shared enum is not supported", derive);