Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ impl BuilderGenCtx {
original_lifetimes: &original_lifetimes,
};

for decl in &mut new_generics_decl {
replace_lifetimes.visit_generic_param_mut(decl);
}

let mut new_where_clause = where_clause.clone();

if let Some(where_clause) = &mut new_where_clause {
Expand Down
51 changes: 51 additions & 0 deletions bon/tests/integration/builder/attr_into_future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,30 @@ mod tests {

let &Dummy = assert_send(builder).await;
}

#[tokio::test]
async fn complex_generics() {
struct Dummy;

#[builder(derive(IntoFuture(Box)))]
async fn sut<'a: 'b, 'b, T: Sync + 'a + 'b, U: Sync + 'a, const N: usize>(
x1: &'a T,
x2: &'b U,
) -> (&'a T, &'b U, usize) {
async {}.await;
(x1, x2, N)
}

// Store the dummy struct in local variables to make sure no `'static`
// lifetime promotion happens
let local_x1 = Dummy;
let local_x2 = Dummy;

let builder = sut::<_, _, 42>().x1(&local_x1).x2(&local_x2);

let (&Dummy, &Dummy, usize) = assert_send(builder).await;
assert_eq!(usize, 42);
}
}

mod test_method {
Expand Down Expand Up @@ -253,5 +277,32 @@ mod tests {

let _: &Dummy = assert_send(builder).await;
}

#[tokio::test]
async fn complex_generics() {
struct Dummy;

#[bon]
impl Dummy {
#[builder(derive(IntoFuture(Box)))]
async fn sut<'a: 'b, 'b, T: Sync + 'a + 'b, U: Sync + 'a, const N: usize>(
x1: &'a T,
x2: &'b U,
) -> (&'a T, &'b U, usize) {
async {}.await;
(x1, x2, N)
}
}

// Store the dummy struct in local variables to make sure no `'static`
// lifetime promotion happens
let local_x1 = Dummy;
let local_x2 = Dummy;

let builder = Dummy::sut::<_, _, 42>().x1(&local_x1).x2(&local_x2);

let (&Dummy, &Dummy, usize) = assert_send(builder).await;
assert_eq!(usize, 42);
}
}
}
Loading