mirror of
https://gitee.com/openharmony/third_party_rust_cxx
synced 2024-11-24 07:40:19 +00:00
Fix span placement on extern functions
This commit is contained in:
parent
291c9350d6
commit
49f9df7923
@ -632,22 +632,26 @@ fn expand_cxx_function_shim(efn: &ExternFn, types: &Types) -> TokenStream {
|
||||
}
|
||||
};
|
||||
let mut dispatch = quote!(#setup #expr);
|
||||
let visibility = efn.visibility;
|
||||
let unsafety = &efn.sig.unsafety;
|
||||
if unsafety.is_none() {
|
||||
dispatch = quote!(unsafe { #dispatch });
|
||||
}
|
||||
let fn_token = efn.sig.fn_token;
|
||||
let ident = &efn.name.rust;
|
||||
let generics = &efn.generics;
|
||||
let arg_list = quote_spanned!(efn.sig.paren_token.span=> (#(#all_args,)*));
|
||||
let fn_body = quote_spanned!(efn.semi_token.span=> {
|
||||
extern "C" {
|
||||
#decl
|
||||
}
|
||||
#trampolines
|
||||
#dispatch
|
||||
});
|
||||
let function_shim = quote! {
|
||||
#doc
|
||||
#attrs
|
||||
pub #unsafety fn #ident #generics(#(#all_args,)*) #ret {
|
||||
extern "C" {
|
||||
#decl
|
||||
}
|
||||
#trampolines
|
||||
#dispatch
|
||||
}
|
||||
#visibility #unsafety #fn_token #ident #generics #arg_list #ret #fn_body
|
||||
};
|
||||
match &efn.receiver {
|
||||
None => function_shim,
|
||||
|
@ -113,6 +113,7 @@ pub struct ExternFn {
|
||||
pub lang: Lang,
|
||||
pub doc: Doc,
|
||||
pub attrs: OtherAttrs,
|
||||
pub visibility: Token![pub],
|
||||
pub name: Pair,
|
||||
pub sig: Signature,
|
||||
pub semi_token: Token![;],
|
||||
|
@ -597,6 +597,12 @@ 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 visibility = Token![pub](match foreign_fn.vis {
|
||||
Visibility::Public(vis) => vis.pub_token.span,
|
||||
Visibility::Crate(vis) => vis.crate_token.span,
|
||||
Visibility::Restricted(vis) => vis.pub_token.span,
|
||||
Visibility::Inherited => foreign_fn.sig.ident.span(),
|
||||
});
|
||||
let unsafety = foreign_fn.sig.unsafety;
|
||||
let fn_token = foreign_fn.sig.fn_token;
|
||||
let name = pair(namespace, &foreign_fn.sig.ident, cxx_name, rust_name);
|
||||
@ -611,6 +617,7 @@ fn parse_extern_fn(
|
||||
lang,
|
||||
doc,
|
||||
attrs,
|
||||
visibility,
|
||||
name,
|
||||
sig: Signature {
|
||||
unsafety,
|
||||
|
@ -41,9 +41,7 @@ error: missing documentation for a type alias
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: missing documentation for a function
|
||||
--> $DIR/deny_missing_docs.rs:9:1
|
||||
|
|
||||
9 | #[cxx::bridge]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
--> $DIR/deny_missing_docs.rs:54:9
|
||||
|
|
||||
54 | pub fn undocumented_foreign_fn() -> u8;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
Loading…
Reference in New Issue
Block a user