mirror of
https://gitee.com/openharmony/third_party_rust_cxx
synced 2024-11-23 15:19:44 +00:00
Move empty enum check to before filling in variants
This commit is contained in:
parent
e2250bca87
commit
3b58d1c799
@ -2,8 +2,8 @@ use crate::syntax::attrs::OtherAttrs;
|
||||
use crate::syntax::namespace::Namespace;
|
||||
use crate::syntax::report::Errors;
|
||||
use crate::syntax::{Api, Discriminant, Doc, Enum, ForeignName, Pair, Variant};
|
||||
use proc_macro2::Ident;
|
||||
use quote::format_ident;
|
||||
use proc_macro2::{Delimiter, Group, Ident, TokenStream};
|
||||
use quote::{format_ident, quote};
|
||||
use serde::Deserialize;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
@ -49,7 +49,15 @@ pub fn load(cx: &mut Errors, apis: &mut [Api]) {
|
||||
for api in apis {
|
||||
if let Api::Enum(enm) = api {
|
||||
if enm.variants_from_header {
|
||||
variants_from_header.push(enm);
|
||||
if enm.variants.is_empty() {
|
||||
variants_from_header.push(enm);
|
||||
} else {
|
||||
let span = span_for_enum_error(enm);
|
||||
cx.error(
|
||||
span,
|
||||
"enum with #![variants_from_header] must be written with no explicit variants",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -237,3 +245,10 @@ fn discriminant_value(mut clang: &[Node]) -> ParsedDiscriminant {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn span_for_enum_error(enm: &Enum) -> TokenStream {
|
||||
let enum_token = enm.enum_token;
|
||||
let mut brace_token = Group::new(Delimiter::Brace, TokenStream::new());
|
||||
brace_token.set_span(enm.brace_token.span);
|
||||
quote!(#enum_token #brace_token)
|
||||
}
|
||||
|
@ -357,14 +357,6 @@ 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);
|
||||
|
Loading…
Reference in New Issue
Block a user