Remove dependency of ui test on whether rust-src is installed
diff --git a/macro/src/expand.rs b/macro/src/expand.rs
index f28d955..431fd3b 100644
--- a/macro/src/expand.rs
+++ b/macro/src/expand.rs
@@ -31,11 +31,7 @@
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_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;
+ 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);
diff --git a/syntax/mod.rs b/syntax/mod.rs
index 88c96e8..cd6f235 100644
--- a/syntax/mod.rs
+++ b/syntax/mod.rs
@@ -46,6 +46,7 @@
pub doc: Doc,
pub type_token: Token![type],
pub ident: Ident,
+ pub semi_token: Token![;],
}
pub struct Struct {
diff --git a/syntax/parse.rs b/syntax/parse.rs
index a1d31cf..e195081 100644
--- a/syntax/parse.rs
+++ b/syntax/parse.rs
@@ -242,6 +242,7 @@
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 @@
doc,
type_token,
ident,
+ semi_token,
}))
}
diff --git a/tests/ui/opaque_not_sized.stderr b/tests/ui/opaque_not_sized.stderr
index 698fda7..366a8f4 100644
--- a/tests/ui/opaque_not_sized.stderr
+++ b/tests/ui/opaque_not_sized.stderr
@@ -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`