Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
someguynamedjosh committed Jun 26, 2021
1 parent 9341971 commit a96dc4f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
16 changes: 12 additions & 4 deletions examples/src/ok_tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::fmt::Debug;
use ouroboros::self_referencing;
use std::fmt::Debug;

// All tests here should compile and run correctly and pass Miri's safety checks.

Expand Down Expand Up @@ -34,6 +34,14 @@ struct ChainedAndUndocumented {
ref2: &'this &'this i32,
}

#[self_referencing]
struct BoxCheckWithLifetimeParameter<'t> {
external_data: Box<&'t ()>,
#[borrows(external_data)]
#[covariant]
self_reference: Box<&'this &'t ()>,
}

/// This test just makes sure that the macro copes with a ton of template parameters being thrown at
/// it, specifically checking that the templates work fine even when a generated struct doesn't need
/// all of them. (E.G. heads will only contain 'd, A, and B.)
Expand Down Expand Up @@ -71,7 +79,7 @@ fn box_and_ref() {
async fn async_new() {
let bar = BoxAndRefAsyncBuilder {
data: Box::new(12),
dref_builder: |data| Box::pin(async move { data })
dref_builder: |data| Box::pin(async move { data }),
}
.build()
.await;
Expand All @@ -86,7 +94,7 @@ async fn async_new() {
async fn async_try_new() {
let bar = BoxAndRefAsyncTryBuilder {
data: Box::new(12),
dref_builder: |data| Box::pin(async move { Result::<_, ()>::Ok(data) })
dref_builder: |data| Box::pin(async move { Result::<_, ()>::Ok(data) }),
}
.try_build()
.await
Expand All @@ -102,7 +110,7 @@ async fn async_try_new() {
async fn async_try_new_err() {
let result = BoxAndRefAsyncTryBuilder {
data: Box::new(12),
dref_builder: |_data| Box::pin(async move { Err(56u64) })
dref_builder: |_data| Box::pin(async move { Err(56u64) }),
}
.try_build()
.await;
Expand Down
7 changes: 6 additions & 1 deletion ouroboros_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1468,6 +1468,11 @@ fn make_type_asserts(
) -> TokenStream2 {
let generic_where = &generic_params.where_clause;
let mut checks = Vec::new();
let fake_lifetime = if let Some(GenericParam::Lifetime(param)) = generic_params.params.first() {
param.lifetime.ident.clone()
} else {
format_ident!("static")
};
for field in field_info {
let field_type = &field.typ;
if let Some((std_type, _eltype)) = apparent_std_container_type(field_type) {
Expand All @@ -1479,7 +1484,7 @@ fn make_type_asserts(
};
let checker_name = format_ident!("{}", checker_name);
let static_field_type =
replace_this_with_lifetime(quote! { #field_type }, format_ident!("static"));
replace_this_with_lifetime(quote! { #field_type }, fake_lifetime.clone());
checks.push(quote! {
::ouroboros::macro_help::CheckIfTypeIsStd::<#static_field_type>::#checker_name();
});
Expand Down

0 comments on commit a96dc4f

Please sign in to comment.