Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove RefMutL hack in proc_macro::bridge #121302

Merged
merged 1 commit into from
Feb 20, 2024
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
7 changes: 1 addition & 6 deletions library/proc_macro/src/bridge/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,7 @@ impl BridgeState<'_> {
/// N.B., while `f` is running, the thread-local state
/// is `BridgeState::InUse`.
fn with<R>(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))
}
}

Expand Down
22 changes: 2 additions & 20 deletions library/proc_macro/src/bridge/scoped_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -15,23 +14,6 @@ pub trait LambdaL: for<'a> ApplyL<'a> {}

impl<T: for<'a> ApplyL<'a>> LambdaL for T {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ApplyL and LamdaL can probably be removed too by making ScopeCell always use BridgeState as content instead of being generic over the content.


// HACK(eddyb) work around projection limitations with a newtype
// FIXME(#52812) replace with `&'a mut <T as ApplyL<'b>>::Out`
pub struct RefMutL<'a, 'b, T: LambdaL>(&'a mut <T as ApplyL<'b>>::Out);

impl<'a, 'b, T: LambdaL> Deref for RefMutL<'a, 'b, T> {
type Target = <T as ApplyL<'b>>::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<T: LambdaL>(Cell<<T as ApplyL<'static>>::Out>);

impl<T: LambdaL> ScopedCell<T> {
Expand All @@ -46,7 +28,7 @@ impl<T: LambdaL> ScopedCell<T> {
pub fn replace<'a, R>(
&self,
replacement: <T as ApplyL<'a>>::Out,
f: impl for<'b, 'c> FnOnce(RefMutL<'b, 'c, T>) -> R,
f: impl for<'b, 'c> FnOnce(&'b mut <T as ApplyL<'c>>::Out) -> R,
) -> R {
/// Wrapper that ensures that the cell always gets filled
/// (with the original state, optionally changed by `f`),
Expand All @@ -71,7 +53,7 @@ impl<T: LambdaL> ScopedCell<T> {
})),
};

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`.
Expand Down
Loading