Remove unneeded anonymous lifetimes from gpui::Context (#27686)

This PR removes a number of unneeded anonymous lifetimes from usages of
`gpui::Context`.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers
2025-03-28 19:26:30 +00:00
committed by GitHub
parent e90411efa2
commit b5dc09c0ca
32 changed files with 80 additions and 87 deletions
+3 -6
View File
@@ -1609,10 +1609,7 @@ impl AppContext for App {
///
/// The given function will be invoked with a [`Context`] and must return an object representing the entity. An
/// [`Entity`] handle will be returned, which can be used to access the entity in a context.
fn new<T: 'static>(
&mut self,
build_entity: impl FnOnce(&mut Context<'_, T>) -> T,
) -> Entity<T> {
fn new<T: 'static>(&mut self, build_entity: impl FnOnce(&mut Context<T>) -> T) -> Entity<T> {
self.update(|cx| {
let slot = cx.entities.reserve();
let handle = slot.clone();
@@ -1636,7 +1633,7 @@ impl AppContext for App {
fn insert_entity<T: 'static>(
&mut self,
reservation: Reservation<T>,
build_entity: impl FnOnce(&mut Context<'_, T>) -> T,
build_entity: impl FnOnce(&mut Context<T>) -> T,
) -> Self::Result<Entity<T>> {
self.update(|cx| {
let slot = reservation.0;
@@ -1650,7 +1647,7 @@ impl AppContext for App {
fn update_entity<T: 'static, R>(
&mut self,
handle: &Entity<T>,
update: impl FnOnce(&mut T, &mut Context<'_, T>) -> R,
update: impl FnOnce(&mut T, &mut Context<T>) -> R,
) -> R {
self.update(|cx| {
let mut entity = cx.entities.lease(handle);
+6 -6
View File
@@ -25,7 +25,7 @@ impl AppContext for AsyncApp {
fn new<T: 'static>(
&mut self,
build_entity: impl FnOnce(&mut Context<'_, T>) -> T,
build_entity: impl FnOnce(&mut Context<T>) -> T,
) -> Self::Result<Entity<T>> {
let app = self
.app
@@ -47,7 +47,7 @@ impl AppContext for AsyncApp {
fn insert_entity<T: 'static>(
&mut self,
reservation: Reservation<T>,
build_entity: impl FnOnce(&mut Context<'_, T>) -> T,
build_entity: impl FnOnce(&mut Context<T>) -> T,
) -> Result<Entity<T>> {
let app = self
.app
@@ -60,7 +60,7 @@ impl AppContext for AsyncApp {
fn update_entity<T: 'static, R>(
&mut self,
handle: &Entity<T>,
update: impl FnOnce(&mut T, &mut Context<'_, T>) -> R,
update: impl FnOnce(&mut T, &mut Context<T>) -> R,
) -> Self::Result<R> {
let app = self
.app
@@ -345,7 +345,7 @@ impl AsyncWindowContext {
impl AppContext for AsyncWindowContext {
type Result<T> = Result<T>;
fn new<T>(&mut self, build_entity: impl FnOnce(&mut Context<'_, T>) -> T) -> Result<Entity<T>>
fn new<T>(&mut self, build_entity: impl FnOnce(&mut Context<T>) -> T) -> Result<Entity<T>>
where
T: 'static,
{
@@ -359,7 +359,7 @@ impl AppContext for AsyncWindowContext {
fn insert_entity<T: 'static>(
&mut self,
reservation: Reservation<T>,
build_entity: impl FnOnce(&mut Context<'_, T>) -> T,
build_entity: impl FnOnce(&mut Context<T>) -> T,
) -> Self::Result<Entity<T>> {
self.window
.update(self, |_, _, cx| cx.insert_entity(reservation, build_entity))
@@ -368,7 +368,7 @@ impl AppContext for AsyncWindowContext {
fn update_entity<T: 'static, R>(
&mut self,
handle: &Entity<T>,
update: impl FnOnce(&mut T, &mut Context<'_, T>) -> R,
update: impl FnOnce(&mut T, &mut Context<T>) -> R,
) -> Result<R> {
self.window
.update(self, |_, _, cx| cx.update_entity(handle, update))
+12 -16
View File
@@ -52,7 +52,7 @@ impl<'a, T: 'static> Context<'a, T> {
pub fn observe<W>(
&mut self,
entity: &Entity<W>,
mut on_notify: impl FnMut(&mut T, Entity<W>, &mut Context<'_, T>) + 'static,
mut on_notify: impl FnMut(&mut T, Entity<W>, &mut Context<T>) + 'static,
) -> Subscription
where
T: 'static,
@@ -73,7 +73,7 @@ impl<'a, T: 'static> Context<'a, T> {
pub fn subscribe<T2, Evt>(
&mut self,
entity: &Entity<T2>,
mut on_event: impl FnMut(&mut T, Entity<T2>, &Evt, &mut Context<'_, T>) + 'static,
mut on_event: impl FnMut(&mut T, Entity<T2>, &Evt, &mut Context<T>) + 'static,
) -> Subscription
where
T: 'static,
@@ -94,7 +94,7 @@ impl<'a, T: 'static> Context<'a, T> {
/// Subscribe to an event type from ourself
pub fn subscribe_self<Evt>(
&mut self,
mut on_event: impl FnMut(&mut T, &Evt, &mut Context<'_, T>) + 'static,
mut on_event: impl FnMut(&mut T, &Evt, &mut Context<T>) + 'static,
) -> Subscription
where
T: 'static + EventEmitter<Evt>,
@@ -126,7 +126,7 @@ impl<'a, T: 'static> Context<'a, T> {
pub fn observe_release<T2>(
&self,
entity: &Entity<T2>,
on_release: impl FnOnce(&mut T, &mut T2, &mut Context<'_, T>) + 'static,
on_release: impl FnOnce(&mut T, &mut T2, &mut Context<T>) + 'static,
) -> Subscription
where
T: Any,
@@ -150,7 +150,7 @@ impl<'a, T: 'static> Context<'a, T> {
/// Register a callback to for updates to the given global
pub fn observe_global<G: 'static>(
&mut self,
mut f: impl FnMut(&mut T, &mut Context<'_, T>) + 'static,
mut f: impl FnMut(&mut T, &mut Context<T>) + 'static,
) -> Subscription
where
T: 'static,
@@ -272,7 +272,7 @@ impl<'a, T: 'static> Context<'a, T> {
&mut self,
observed: &Entity<V2>,
window: &mut Window,
mut on_notify: impl FnMut(&mut T, Entity<V2>, &mut Window, &mut Context<'_, T>) + 'static,
mut on_notify: impl FnMut(&mut T, Entity<V2>, &mut Window, &mut Context<T>) + 'static,
) -> Subscription
where
V2: 'static,
@@ -310,8 +310,7 @@ impl<'a, T: 'static> Context<'a, T> {
&mut self,
emitter: &Entity<Emitter>,
window: &Window,
mut on_event: impl FnMut(&mut T, &Entity<Emitter>, &Evt, &mut Window, &mut Context<'_, T>)
+ 'static,
mut on_event: impl FnMut(&mut T, &Entity<Emitter>, &Evt, &mut Window, &mut Context<T>) + 'static,
) -> Subscription
where
Emitter: EventEmitter<Evt>,
@@ -363,7 +362,7 @@ impl<'a, T: 'static> Context<'a, T> {
&self,
observed: &Entity<T2>,
window: &Window,
mut on_release: impl FnMut(&mut T, &mut T2, &mut Window, &mut Context<'_, T>) + 'static,
mut on_release: impl FnMut(&mut T, &mut T2, &mut Window, &mut Context<T>) + 'static,
) -> Subscription
where
T: 'static,
@@ -626,7 +625,7 @@ impl<'a, T: 'static> Context<'a, T> {
pub fn observe_global_in<G: Global>(
&mut self,
window: &Window,
mut f: impl FnMut(&mut T, &mut Window, &mut Context<'_, T>) + 'static,
mut f: impl FnMut(&mut T, &mut Window, &mut Context<T>) + 'static,
) -> Subscription {
let window_handle = window.handle;
let view = self.weak_entity();
@@ -691,10 +690,7 @@ impl<T> Context<'_, T> {
impl<T> AppContext for Context<'_, T> {
type Result<U> = U;
fn new<U: 'static>(
&mut self,
build_entity: impl FnOnce(&mut Context<'_, U>) -> U,
) -> Entity<U> {
fn new<U: 'static>(&mut self, build_entity: impl FnOnce(&mut Context<U>) -> U) -> Entity<U> {
self.app.new(build_entity)
}
@@ -705,7 +701,7 @@ impl<T> AppContext for Context<'_, T> {
fn insert_entity<U: 'static>(
&mut self,
reservation: Reservation<U>,
build_entity: impl FnOnce(&mut Context<'_, U>) -> U,
build_entity: impl FnOnce(&mut Context<U>) -> U,
) -> Self::Result<Entity<U>> {
self.app.insert_entity(reservation, build_entity)
}
@@ -713,7 +709,7 @@ impl<T> AppContext for Context<'_, T> {
fn update_entity<U: 'static, R>(
&mut self,
handle: &Entity<U>,
update: impl FnOnce(&mut U, &mut Context<'_, U>) -> R,
update: impl FnOnce(&mut U, &mut Context<U>) -> R,
) -> R {
self.app.update_entity(handle, update)
}
+4 -4
View File
@@ -447,7 +447,7 @@ impl<T: 'static> Entity<T> {
pub fn update<C, R>(
&self,
cx: &mut C,
update: impl FnOnce(&mut T, &mut Context<'_, T>) -> R,
update: impl FnOnce(&mut T, &mut Context<T>) -> R,
) -> C::Result<R>
where
C: AppContext,
@@ -461,7 +461,7 @@ impl<T: 'static> Entity<T> {
pub fn update_in<C, R>(
&self,
cx: &mut C,
update: impl FnOnce(&mut T, &mut Window, &mut Context<'_, T>) -> R,
update: impl FnOnce(&mut T, &mut Window, &mut Context<T>) -> R,
) -> C::Result<R>
where
C: VisualContext,
@@ -679,7 +679,7 @@ impl<T: 'static> WeakEntity<T> {
pub fn update<C, R>(
&self,
cx: &mut C,
update: impl FnOnce(&mut T, &mut Context<'_, T>) -> R,
update: impl FnOnce(&mut T, &mut Context<T>) -> R,
) -> Result<R>
where
C: AppContext,
@@ -698,7 +698,7 @@ impl<T: 'static> WeakEntity<T> {
pub fn update_in<C, R>(
&self,
cx: &mut C,
update: impl FnOnce(&mut T, &mut Window, &mut Context<'_, T>) -> R,
update: impl FnOnce(&mut T, &mut Window, &mut Context<T>) -> R,
) -> Result<R>
where
C: VisualContext,
+7 -7
View File
@@ -34,7 +34,7 @@ impl AppContext for TestAppContext {
fn new<T: 'static>(
&mut self,
build_entity: impl FnOnce(&mut Context<'_, T>) -> T,
build_entity: impl FnOnce(&mut Context<T>) -> T,
) -> Self::Result<Entity<T>> {
let mut app = self.app.borrow_mut();
app.new(build_entity)
@@ -48,7 +48,7 @@ impl AppContext for TestAppContext {
fn insert_entity<T: 'static>(
&mut self,
reservation: crate::Reservation<T>,
build_entity: impl FnOnce(&mut Context<'_, T>) -> T,
build_entity: impl FnOnce(&mut Context<T>) -> T,
) -> Self::Result<Entity<T>> {
let mut app = self.app.borrow_mut();
app.insert_entity(reservation, build_entity)
@@ -57,7 +57,7 @@ impl AppContext for TestAppContext {
fn update_entity<T: 'static, R>(
&mut self,
handle: &Entity<T>,
update: impl FnOnce(&mut T, &mut Context<'_, T>) -> R,
update: impl FnOnce(&mut T, &mut Context<T>) -> R,
) -> Self::Result<R> {
let mut app = self.app.borrow_mut();
app.update_entity(handle, update)
@@ -876,7 +876,7 @@ impl AppContext for VisualTestContext {
fn new<T: 'static>(
&mut self,
build_entity: impl FnOnce(&mut Context<'_, T>) -> T,
build_entity: impl FnOnce(&mut Context<T>) -> T,
) -> Self::Result<Entity<T>> {
self.cx.new(build_entity)
}
@@ -888,7 +888,7 @@ impl AppContext for VisualTestContext {
fn insert_entity<T: 'static>(
&mut self,
reservation: crate::Reservation<T>,
build_entity: impl FnOnce(&mut Context<'_, T>) -> T,
build_entity: impl FnOnce(&mut Context<T>) -> T,
) -> Self::Result<Entity<T>> {
self.cx.insert_entity(reservation, build_entity)
}
@@ -896,7 +896,7 @@ impl AppContext for VisualTestContext {
fn update_entity<T, R>(
&mut self,
handle: &Entity<T>,
update: impl FnOnce(&mut T, &mut Context<'_, T>) -> R,
update: impl FnOnce(&mut T, &mut Context<T>) -> R,
) -> Self::Result<R>
where
T: 'static,
@@ -956,7 +956,7 @@ impl VisualContext for VisualTestContext {
fn new_window_entity<T: 'static>(
&mut self,
build_entity: impl FnOnce(&mut Window, &mut Context<'_, T>) -> T,
build_entity: impl FnOnce(&mut Window, &mut Context<T>) -> T,
) -> Self::Result<Entity<T>> {
self.window
.update(&mut self.cx, |_, window, cx| {
+4 -4
View File
@@ -168,7 +168,7 @@ pub trait AppContext {
/// Create a new entity in the app context.
fn new<T: 'static>(
&mut self,
build_entity: impl FnOnce(&mut Context<'_, T>) -> T,
build_entity: impl FnOnce(&mut Context<T>) -> T,
) -> Self::Result<Entity<T>>;
/// Reserve a slot for a entity to be inserted later.
@@ -181,14 +181,14 @@ pub trait AppContext {
fn insert_entity<T: 'static>(
&mut self,
reservation: Reservation<T>,
build_entity: impl FnOnce(&mut Context<'_, T>) -> T,
build_entity: impl FnOnce(&mut Context<T>) -> T,
) -> Self::Result<Entity<T>>;
/// Update a entity in the app context.
fn update_entity<T, R>(
&mut self,
handle: &Entity<T>,
update: impl FnOnce(&mut T, &mut Context<'_, T>) -> R,
update: impl FnOnce(&mut T, &mut Context<T>) -> R,
) -> Self::Result<R>
where
T: 'static;
@@ -254,7 +254,7 @@ pub trait VisualContext: AppContext {
/// Update a view with the given callback
fn new_window_entity<T: 'static>(
&mut self,
build_entity: impl FnOnce(&mut Window, &mut Context<'_, T>) -> T,
build_entity: impl FnOnce(&mut Window, &mut Context<T>) -> T,
) -> Self::Result<Entity<T>>;
/// Replace the root view of a window with a new view.
+2 -2
View File
@@ -1009,7 +1009,7 @@ impl Window {
pub fn replace_root<E>(
&mut self,
cx: &mut App,
build_view: impl FnOnce(&mut Window, &mut Context<'_, E>) -> E,
build_view: impl FnOnce(&mut Window, &mut Context<E>) -> E,
) -> Entity<E>
where
E: 'static + Render,
@@ -3824,7 +3824,7 @@ impl<V: 'static + Render> WindowHandle<V> {
pub fn update<C, R>(
&self,
cx: &mut C,
update: impl FnOnce(&mut V, &mut Window, &mut Context<'_, V>) -> R,
update: impl FnOnce(&mut V, &mut Window, &mut Context<V>) -> R,
) -> Result<R>
where
C: AppContext,