Skip to content

Commit

Permalink
Rollup merge of #98118 - steffahn:scoped-threads-nll-test, r=m-ou-se
Browse files Browse the repository at this point in the history
Test NLL fix of bad lifetime inference for reference captured in closure.

This came up as a use-case for `thread::scope` API that only compiles successfully since `feature(nll)` got stabilized recently.

Closes #93203 which had been re-opened for tracking this very test case to be added.
  • Loading branch information
JohnTitor authored Jun 16, 2022
2 parents cf68fd7 + eb14dd8 commit 1f3023c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions library/std/src/thread/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,16 @@ fn test_scoped_threads_drop_result_before_join() {
});
assert!(actually_finished.load(Ordering::Relaxed));
}

#[test]
fn test_scoped_threads_nll() {
// this is mostly a *compilation test* for this exact function:
fn foo(x: &u8) {
thread::scope(|s| {
s.spawn(|| drop(x));
});
}
// let's also run it for good measure
let x = 42_u8;
foo(&x);
}

0 comments on commit 1f3023c

Please sign in to comment.