Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 8f397bc

Browse files
committed
Simplify box_region macros
1 parent a50d721 commit 8f397bc

File tree

2 files changed

+18
-28
lines changed

2 files changed

+18
-28
lines changed

compiler/rustc_data_structures/src/box_region.rs

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -82,37 +82,35 @@ pub enum YieldType<I, A> {
8282
#[macro_export]
8383
#[allow_internal_unstable(fn_traits)]
8484
macro_rules! declare_box_region_type {
85-
(impl $v:vis
86-
$name: ident,
87-
$yield_type:ty,
88-
for($($lifetimes:tt)*),
89-
($($args:ty),*) -> ($reti:ty, $retc:ty)
90-
) => {
85+
($v:vis $name: ident, ($($args:ty),*) -> ($reti:ty, $retc:ty)) => {
9186
$v struct $name($crate::box_region::PinnedGenerator<
9287
$reti,
93-
for<$($lifetimes)*> fn(($($args,)*)),
88+
fn(($($args,)*)),
9489
$retc
9590
>);
9691

9792
impl $name {
98-
fn new<T: ::std::ops::Generator<$crate::box_region::Action, Yield = $yield_type, Return = $retc> + 'static>(
99-
generator: T
100-
) -> ($reti, Self) {
93+
fn new<T>(generator: T) -> ($reti, Self)
94+
where T: ::std::ops::Generator<
95+
$crate::box_region::Action,
96+
Yield = $crate::box_region::YieldType<$reti, fn(($($args,)*))>,
97+
Return = $retc,
98+
> + 'static {
10199
let (initial, pinned) = $crate::box_region::PinnedGenerator::new(generator);
102100
(initial, $name(pinned))
103101
}
104102

105-
$v fn access<F: for<$($lifetimes)*> FnOnce($($args,)*) -> R, R>(&mut self, f: F) -> R {
103+
$v fn access<F: FnOnce($($args,)*) -> R, R>(&mut self, f: F) -> R {
106104
// Turn the FnOnce closure into *mut dyn FnMut()
107105
// so we can pass it in to the generator
108106
let mut r = None;
109107
let mut f = Some(f);
110-
let mut_f: &mut dyn for<$($lifetimes)*> FnMut(($($args,)*)) =
108+
let mut_f: &mut dyn FnMut(($($args,)*)) =
111109
&mut |args| {
112110
let f = f.take().unwrap();
113111
r = Some(FnOnce::call_once(f, args));
114112
};
115-
let mut_f = mut_f as *mut dyn for<$($lifetimes)*> FnMut(($($args,)*));
113+
let mut_f = mut_f as *mut dyn FnMut(($($args,)*));
116114

117115
// Get the generator to call our closure
118116
unsafe {
@@ -127,36 +125,29 @@ macro_rules! declare_box_region_type {
127125
self.0.complete()
128126
}
129127

130-
fn initial_yield(value: $reti) -> $yield_type {
128+
fn initial_yield(
129+
value: $reti,
130+
) -> $crate::box_region::YieldType<$reti, fn(($($args,)*))> {
131131
$crate::box_region::YieldType::Initial(value)
132132
}
133133
}
134134
};
135-
136-
($v:vis $name: ident, for($($lifetimes:tt)*), ($($args:ty),*) -> ($reti:ty, $retc:ty)) => {
137-
declare_box_region_type!(
138-
impl $v $name,
139-
$crate::box_region::YieldType<$reti, for<$($lifetimes)*> fn(($($args,)*))>,
140-
for($($lifetimes)*),
141-
($($args),*) -> ($reti, $retc)
142-
);
143-
};
144135
}
145136

146137
#[macro_export]
147138
#[allow_internal_unstable(fn_traits)]
148139
macro_rules! box_region_allow_access {
149-
(for($($lifetimes:tt)*), ($($args:ty),*), ($($exprs:expr),*), $action:ident) => {
140+
(($($args:ty),*), ($($exprs:expr),*), $action:ident) => {
150141
loop {
151142
match $action {
152143
$crate::box_region::Action::Access(accessor) => {
153-
let accessor: &mut dyn for<$($lifetimes)*> FnMut($($args),*) = unsafe {
144+
let accessor: &mut dyn FnMut($($args),*) = unsafe {
154145
::std::mem::transmute(accessor.get())
155146
};
156147
(*accessor)(($($exprs),*));
157148
unsafe {
158149
let marker = $crate::box_region::Marker::<
159-
for<$($lifetimes)*> fn(($($args,)*))
150+
fn(($($args,)*))
160151
>::new();
161152
$action = yield $crate::box_region::YieldType::Accessor(marker);
162153
};

compiler/rustc_interface/src/passes.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ fn count_nodes(krate: &ast::Crate) -> usize {
8787

8888
declare_box_region_type!(
8989
pub BoxedResolver,
90-
for(),
9190
(&mut Resolver<'_>) -> (Result<ast::Crate>, ResolverOutputs)
9291
);
9392

@@ -133,7 +132,7 @@ pub fn configure_and_expand(
133132
resolver
134133
}
135134
};
136-
box_region_allow_access!(for(), (&mut Resolver<'_>), (&mut resolver), action);
135+
box_region_allow_access!((&mut Resolver<'_>), (&mut resolver), action);
137136
resolver.into_outputs()
138137
});
139138
result.map(|k| (k, resolver))

0 commit comments

Comments
 (0)