From 5be3d4bee4f1cdd79b47579c84199a484a09f3e9 Mon Sep 17 00:00:00 2001 From: Pavel Grigorenko Date: Mon, 19 Feb 2024 17:37:43 +0300 Subject: [PATCH] Remove `RefMutL` hack in `proc_macro::bridge` --- library/proc_macro/src/bridge/client.rs | 7 +------ library/proc_macro/src/bridge/scoped_cell.rs | 22 ++------------------ 2 files changed, 3 insertions(+), 26 deletions(-) diff --git a/library/proc_macro/src/bridge/client.rs b/library/proc_macro/src/bridge/client.rs index 9255c3abc8a02..52b9ef470dccb 100644 --- a/library/proc_macro/src/bridge/client.rs +++ b/library/proc_macro/src/bridge/client.rs @@ -296,12 +296,7 @@ impl BridgeState<'_> { /// N.B., while `f` is running, the thread-local state /// is `BridgeState::InUse`. fn with(f: impl FnOnce(&mut BridgeState<'_>) -> R) -> R { - BRIDGE_STATE.with(|state| { - state.replace(BridgeState::InUse, |mut state| { - // FIXME(#52812) pass `f` directly to `replace` when `RefMutL` is gone - f(&mut *state) - }) - }) + BRIDGE_STATE.with(|state| state.replace(BridgeState::InUse, f)) } } diff --git a/library/proc_macro/src/bridge/scoped_cell.rs b/library/proc_macro/src/bridge/scoped_cell.rs index 2cde1f65adf9c..53eae1ebdb0fb 100644 --- a/library/proc_macro/src/bridge/scoped_cell.rs +++ b/library/proc_macro/src/bridge/scoped_cell.rs @@ -2,7 +2,6 @@ use std::cell::Cell; use std::mem; -use std::ops::{Deref, DerefMut}; /// Type lambda application, with a lifetime. #[allow(unused_lifetimes)] @@ -15,23 +14,6 @@ pub trait LambdaL: for<'a> ApplyL<'a> {} impl ApplyL<'a>> LambdaL for T {} -// HACK(eddyb) work around projection limitations with a newtype -// FIXME(#52812) replace with `&'a mut >::Out` -pub struct RefMutL<'a, 'b, T: LambdaL>(&'a mut >::Out); - -impl<'a, 'b, T: LambdaL> Deref for RefMutL<'a, 'b, T> { - type Target = >::Out; - fn deref(&self) -> &Self::Target { - self.0 - } -} - -impl<'a, 'b, T: LambdaL> DerefMut for RefMutL<'a, 'b, T> { - fn deref_mut(&mut self) -> &mut Self::Target { - self.0 - } -} - pub struct ScopedCell(Cell<>::Out>); impl ScopedCell { @@ -46,7 +28,7 @@ impl ScopedCell { pub fn replace<'a, R>( &self, replacement: >::Out, - f: impl for<'b, 'c> FnOnce(RefMutL<'b, 'c, T>) -> R, + f: impl for<'b, 'c> FnOnce(&'b mut >::Out) -> R, ) -> R { /// Wrapper that ensures that the cell always gets filled /// (with the original state, optionally changed by `f`), @@ -71,7 +53,7 @@ impl ScopedCell { })), }; - f(RefMutL(put_back_on_drop.value.as_mut().unwrap())) + f(put_back_on_drop.value.as_mut().unwrap()) } /// Sets the value in `self` to `value` while running `f`.