mirror of
https://gitee.com/openharmony/third_party_rust_cxx
synced 2024-11-23 23:29:50 +00:00
Remove dependency of ui test on whether rust-src is installed
This commit is contained in:
parent
691dc171b5
commit
c8361027d9
@ -31,11 +31,7 @@ fn expand(namespace: &Namespace, ffi: ItemMod, apis: &[Api], types: &Types) -> T
|
||||
for api in apis {
|
||||
if let Api::RustType(ety) = api {
|
||||
expanded.extend(expand_rust_type(ety));
|
||||
let ident = &ety.ident;
|
||||
let span = ident.span();
|
||||
hidden.extend(quote_spanned! {span=>
|
||||
let _ = ::std::ptr::read::<#ident>;
|
||||
});
|
||||
hidden.extend(expand_rust_type_assert_sized(ety));
|
||||
}
|
||||
}
|
||||
|
||||
@ -426,6 +422,28 @@ fn expand_rust_type(ety: &ExternType) -> TokenStream {
|
||||
}
|
||||
}
|
||||
|
||||
fn expand_rust_type_assert_sized(ety: &ExternType) -> TokenStream {
|
||||
// Rustc will render as follows if not sized:
|
||||
//
|
||||
// type TheirType;
|
||||
// -----^^^^^^^^^-
|
||||
// | |
|
||||
// | doesn't have a size known at compile-time
|
||||
// required by this bound in `ffi::_::__AssertSized`
|
||||
|
||||
let ident = &ety.ident;
|
||||
let begin_span = Token![::](ety.type_token.span);
|
||||
let sized = quote_spanned! {ety.semi_token.span=>
|
||||
#begin_span std::marker::Sized
|
||||
};
|
||||
quote_spanned! {ident.span()=>
|
||||
let _ = {
|
||||
fn __AssertSized<T: ?#sized + #sized>() {}
|
||||
__AssertSized::<#ident>
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn expand_rust_function_shim(namespace: &Namespace, efn: &ExternFn, types: &Types) -> TokenStream {
|
||||
let ident = &efn.ident;
|
||||
let link_name = mangle::extern_fn(namespace, efn);
|
||||
|
@ -46,6 +46,7 @@ pub struct ExternType {
|
||||
pub doc: Doc,
|
||||
pub type_token: Token![type],
|
||||
pub ident: Ident,
|
||||
pub semi_token: Token![;],
|
||||
}
|
||||
|
||||
pub struct Struct {
|
||||
|
@ -242,6 +242,7 @@ fn parse_extern_type(cx: &mut Errors, foreign_type: &ForeignItemType, lang: Lang
|
||||
let doc = attrs::parse_doc(cx, &foreign_type.attrs);
|
||||
let type_token = foreign_type.type_token;
|
||||
let ident = foreign_type.ident.clone();
|
||||
let semi_token = foreign_type.semi_token;
|
||||
let api_type = match lang {
|
||||
Lang::Cxx => Api::CxxType,
|
||||
Lang::Rust => Api::RustType,
|
||||
@ -250,6 +251,7 @@ fn parse_extern_type(cx: &mut Errors, foreign_type: &ForeignItemType, lang: Lang
|
||||
doc,
|
||||
type_token,
|
||||
ident,
|
||||
semi_token,
|
||||
}))
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,11 @@
|
||||
error[E0277]: the size for values of type `str` cannot be known at compilation time
|
||||
--> $DIR/opaque_not_sized.rs:4:14
|
||||
|
|
||||
4 | type TypeR;
|
||||
| ^^^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
::: $RUST/core/src/ptr/mod.rs
|
||||
|
|
||||
| pub unsafe fn read<T>(src: *const T) -> T {
|
||||
| - required by this bound in `std::ptr::read`
|
||||
|
|
||||
= help: within `TypeR`, the trait `std::marker::Sized` is not implemented for `str`
|
||||
= note: required because it appears within the type `TypeR`
|
||||
--> $DIR/opaque_not_sized.rs:4:14
|
||||
|
|
||||
4 | type TypeR;
|
||||
| -----^^^^^-
|
||||
| | |
|
||||
| | doesn't have a size known at compile-time
|
||||
| required by this bound in `ffi::_::__AssertSized`
|
||||
|
|
||||
= help: within `TypeR`, the trait `std::marker::Sized` is not implemented for `str`
|
||||
= note: required because it appears within the type `TypeR`
|
||||
|
Loading…
Reference in New Issue
Block a user