Skip to content

Commit

Permalink
Rollup merge of rust-lang#128745 - dtolnay:spawnunchecked, r=workingj…
Browse files Browse the repository at this point in the history
…ubilee

Remove unused lifetime parameter from spawn_unchecked

Amanieu caught this when reviewing the stabilization proposal in rust-lang#55132.

The `'a` lifetime here is useless. The signature is asking the caller of `spawn_unchecked` to "give me any lifetime that is shorter than your F's and T's lifetime", which they can always to with no effect, because arbitrarily short lifetimes exist.
  • Loading branch information
matthiaskrgr authored Aug 13, 2024
2 parents c39d90e + 67fa603 commit 9ed7210
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions std/src/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,25 +434,24 @@ impl Builder {
///
/// [`io::Result`]: crate::io::Result
#[unstable(feature = "thread_spawn_unchecked", issue = "55132")]
pub unsafe fn spawn_unchecked<'a, F, T>(self, f: F) -> io::Result<JoinHandle<T>>
pub unsafe fn spawn_unchecked<F, T>(self, f: F) -> io::Result<JoinHandle<T>>
where
F: FnOnce() -> T,
F: Send + 'a,
T: Send + 'a,
F: Send,
T: Send,
{
Ok(JoinHandle(unsafe { self.spawn_unchecked_(f, None) }?))
}

unsafe fn spawn_unchecked_<'a, 'scope, F, T>(
unsafe fn spawn_unchecked_<'scope, F, T>(
self,
f: F,
scope_data: Option<Arc<scoped::ScopeData>>,
) -> io::Result<JoinInner<'scope, T>>
where
F: FnOnce() -> T,
F: Send + 'a,
T: Send + 'a,
'scope: 'a,
F: Send,
T: Send,
{
let Builder { name, stack_size } = self;

Expand Down Expand Up @@ -532,7 +531,7 @@ impl Builder {
// will call `decrement_num_running_threads` and therefore signal that this thread is
// done.
drop(their_packet);
// Here, the lifetime `'a` and even `'scope` can end. `main` keeps running for a bit
// Here, the lifetime `'scope` can end. `main` keeps running for a bit
// after that before returning itself.
};

Expand Down

0 comments on commit 9ed7210

Please sign in to comment.