Suppress irrelevant "required by this bound" from error message

This commit is contained in:
David Tolnay 2020-04-22 19:58:30 -07:00
parent b17b9f3bf4
commit 1044d44f30
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 11 additions and 19 deletions

View File

@ -20,20 +20,15 @@ pub fn bridge(namespace: &Namespace, ffi: ItemMod) -> Result<TokenStream> {
let mut expanded = TokenStream::new();
let mut hidden = TokenStream::new();
let mut has_rust_type = false;
for api in &apis {
if let Api::RustType(ety) = api {
expanded.extend(expand_rust_type(ety));
if !has_rust_type {
hidden.extend(quote!(
const fn __assert_sized<T>() {}
));
has_rust_type = true;
}
let ident = &ety.ident;
let span = ident.span();
hidden.extend(quote_spanned!(span=> __assert_sized::<#ident>();));
hidden.extend(quote_spanned! {span=>
let _ = ::std::ptr::read::<#ident>;
});
}
}

View File

@ -1,12 +1,9 @@
error[E0277]: the size for values of type `str` cannot be known at compilation time
--> $DIR/opaque_not_sized.rs:4:14
|
1 | #[cxx::bridge]
| -------------- required by this bound in `ffi::_::__assert_sized`
...
4 | type TypeR;
| ^^^^^ doesn't have a size known at compile-time
|
= help: within `TypeR`, the trait `std::marker::Sized` is not implemented for `str`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= 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
|
= help: within `TypeR`, the trait `std::marker::Sized` is not implemented for `str`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= note: required because it appears within the type `TypeR`