mirror of
https://gitee.com/openharmony/third_party_rust_cxx
synced 2025-02-17 06:57:37 +00:00
Begin development on async fn support
This commit is contained in:
parent
97d7d53c44
commit
e41be2f96b
@ -14,6 +14,8 @@ categories = ["development-tools::ffi"]
|
||||
|
||||
[features]
|
||||
parallel = ["cc/parallel"]
|
||||
# incomplete features that are not covered by a compatibility guarantee:
|
||||
experimental-async-fn = []
|
||||
|
||||
[dependencies]
|
||||
cc = "1.0.49"
|
||||
|
@ -16,6 +16,10 @@ categories = ["development-tools::ffi"]
|
||||
name = "cxxbridge"
|
||||
path = "src/main.rs"
|
||||
|
||||
[features]
|
||||
# incomplete features that are not covered by a compatibility guarantee:
|
||||
experimental-async-fn = []
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "3.0", default-features = false, features = ["std", "suggestions"] }
|
||||
codespan-reporting = "0.11"
|
||||
|
@ -16,6 +16,8 @@ categories = ["development-tools::ffi"]
|
||||
proc-macro = true
|
||||
|
||||
[features]
|
||||
# incomplete features that are not covered by a compatibility guarantee:
|
||||
experimental-async-fn = []
|
||||
experimental-enum-variants-from-header = ["clang-ast", "flate2", "memmap", "serde", "serde_json"]
|
||||
|
||||
[dependencies]
|
||||
@ -23,7 +25,7 @@ proc-macro2 = "1.0"
|
||||
quote = "1.0.4"
|
||||
syn = { version = "1.0.70", features = ["full"] }
|
||||
|
||||
# optional dependencies
|
||||
# optional dependencies:
|
||||
clang-ast = { version = "0.1", optional = true }
|
||||
flate2 = { version = "1.0", optional = true }
|
||||
memmap = { version = "0.7", optional = true }
|
||||
|
@ -309,6 +309,7 @@ impl Eq for Signature {}
|
||||
impl PartialEq for Signature {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
let Signature {
|
||||
asyncness,
|
||||
unsafety,
|
||||
fn_token: _,
|
||||
generics: _,
|
||||
@ -320,6 +321,7 @@ impl PartialEq for Signature {
|
||||
throws_tokens: _,
|
||||
} = self;
|
||||
let Signature {
|
||||
asyncness: asyncness2,
|
||||
unsafety: unsafety2,
|
||||
fn_token: _,
|
||||
generics: _,
|
||||
@ -330,7 +332,8 @@ impl PartialEq for Signature {
|
||||
paren_token: _,
|
||||
throws_tokens: _,
|
||||
} = other;
|
||||
unsafety.is_some() == unsafety2.is_some()
|
||||
asyncness.is_some() == asyncness2.is_some()
|
||||
&& unsafety.is_some() == unsafety2.is_some()
|
||||
&& receiver == receiver2
|
||||
&& ret == ret2
|
||||
&& throws == throws2
|
||||
@ -362,6 +365,7 @@ impl PartialEq for Signature {
|
||||
impl Hash for Signature {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
let Signature {
|
||||
asyncness,
|
||||
unsafety,
|
||||
fn_token: _,
|
||||
generics: _,
|
||||
@ -372,6 +376,7 @@ impl Hash for Signature {
|
||||
paren_token: _,
|
||||
throws_tokens: _,
|
||||
} = self;
|
||||
asyncness.is_some().hash(state);
|
||||
unsafety.is_some().hash(state);
|
||||
receiver.hash(state);
|
||||
for arg in args {
|
||||
|
@ -179,6 +179,7 @@ pub struct Lifetimes {
|
||||
}
|
||||
|
||||
pub struct Signature {
|
||||
pub asyncness: Option<Token![async]>,
|
||||
pub unsafety: Option<Token![unsafe]>,
|
||||
pub fn_token: Token![fn],
|
||||
pub generics: Generics,
|
||||
|
@ -562,7 +562,7 @@ fn parse_extern_fn(
|
||||
));
|
||||
}
|
||||
|
||||
if foreign_fn.sig.asyncness.is_some() {
|
||||
if foreign_fn.sig.asyncness.is_some() && !cfg!(feature = "experimental-async-fn") {
|
||||
return Err(Error::new_spanned(
|
||||
foreign_fn,
|
||||
"async function is not directly supported yet, but see https://cxx.rs/async.html \
|
||||
@ -664,6 +664,7 @@ fn parse_extern_fn(
|
||||
let mut throws_tokens = None;
|
||||
let ret = parse_return_type(&foreign_fn.sig.output, &mut throws_tokens)?;
|
||||
let throws = throws_tokens.is_some();
|
||||
let asyncness = foreign_fn.sig.asyncness;
|
||||
let unsafety = foreign_fn.sig.unsafety;
|
||||
let fn_token = foreign_fn.sig.fn_token;
|
||||
let inherited_span = unsafety.map_or(fn_token.span, |unsafety| unsafety.span);
|
||||
@ -684,6 +685,7 @@ fn parse_extern_fn(
|
||||
visibility,
|
||||
name,
|
||||
sig: Signature {
|
||||
asyncness,
|
||||
unsafety,
|
||||
fn_token,
|
||||
generics,
|
||||
@ -1400,6 +1402,7 @@ fn parse_type_fn(ty: &TypeBareFn) -> Result<Type> {
|
||||
let ret = parse_return_type(&ty.output, &mut throws_tokens)?;
|
||||
let throws = throws_tokens.is_some();
|
||||
|
||||
let asyncness = None;
|
||||
let unsafety = ty.unsafety;
|
||||
let fn_token = ty.fn_token;
|
||||
let generics = Generics::default();
|
||||
@ -1407,6 +1410,7 @@ fn parse_type_fn(ty: &TypeBareFn) -> Result<Type> {
|
||||
let paren_token = ty.paren_token;
|
||||
|
||||
Ok(Type::Fn(Box::new(Signature {
|
||||
asyncness,
|
||||
unsafety,
|
||||
fn_token,
|
||||
generics,
|
||||
|
@ -248,6 +248,7 @@ impl ToTokens for Lifetimes {
|
||||
impl ToTokens for Signature {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
let Signature {
|
||||
asyncness: _,
|
||||
unsafety: _,
|
||||
fn_token,
|
||||
generics: _,
|
||||
|
Loading…
x
Reference in New Issue
Block a user