Skip to content

Commit 8cddcae

Browse files
committed
fix(core): remove another TAIT usage to work around false "cycle detected" errors
Work-around for [rust-lang/rust#99793][1]. For some reason this one didn't cause an error in nightly-2022-06-26. [1]: rust-lang/rust#99793
1 parent 26e7ba7 commit 8cddcae

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

src/r3_core/src/bind.rs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,31 +1339,45 @@ where
13391339
{
13401340
type Output = NewOutput;
13411341

1342-
// This opaque type must be defined outside this trait to
1343-
// prevent the unintended capturing of `Binder`.
1344-
// [ref:opaque_type_extraneous_capture]
1345-
type BoundFn = MappedBoundFn<InnerBoundFn, Output, Mapper, NewOutput>;
1342+
type BoundFn = MappedBoundFn<InnerBoundFn, Mapper>;
13461343

13471344
fn bind(self, binder: Binder, ctx: &mut CfgBindCtx<'_>) -> Self::BoundFn {
1348-
map_bind_inner(self.inner.bind(binder, ctx), self.mapper)
1345+
MappedBoundFn {
1346+
inner_bound_fn: self.inner.bind(binder, ctx),
1347+
mapper: self.mapper,
1348+
}
13491349
}
13501350
}
13511351

1352-
type MappedBoundFn<InnerBoundFn, Output, Mapper, NewOutput>
1353-
where
1354-
InnerBoundFn: FnOnce() -> Output + Copy + Send + 'static,
1355-
Mapper: FnOnce(Output) -> NewOutput + Copy + Send + 'static,
1356-
= impl FnOnce() -> NewOutput + Copy + Send + 'static;
1352+
// // This opaque type must be defined outside this trait to
1353+
// // prevent the unintended capturing of `Binder`.
1354+
// // [ref:opaque_type_extraneous_capture]
1355+
// type MappedBoundFn<InnerBoundFn, Output, Mapper, NewOutput>
1356+
// where
1357+
// InnerBoundFn: FnOnce() -> Output + Copy + Send + 'static,
1358+
// Mapper: FnOnce(Output) -> NewOutput + Copy + Send + 'static,
1359+
// = impl FnOnce() -> NewOutput + Copy + Send + 'static;
13571360

1358-
const fn map_bind_inner<InnerBoundFn, Output, Mapper, NewOutput>(
1361+
// FIXME: This is supposed to be a TAIT like the one above, but
1362+
// [ref:rust_99793_tait] prevents that
1363+
#[doc(hidden)]
1364+
#[derive(Copy, Clone)]
1365+
pub struct MappedBoundFn<InnerBoundFn, Mapper> {
13591366
inner_bound_fn: InnerBoundFn,
13601367
mapper: Mapper,
1361-
) -> MappedBoundFn<InnerBoundFn, Output, Mapper, NewOutput>
1368+
}
1369+
1370+
impl<InnerBoundFn, Output, Mapper, NewOutput> FnOnce<()> for MappedBoundFn<InnerBoundFn, Mapper>
13621371
where
13631372
InnerBoundFn: FnOnce() -> Output + Copy + Send + 'static,
13641373
Mapper: FnOnce(Output) -> NewOutput + Copy + Send + 'static,
13651374
{
1366-
move || (mapper)(inner_bound_fn())
1375+
type Output = NewOutput;
1376+
1377+
#[inline]
1378+
extern "rust-call" fn call_once(self, (): ()) -> Self::Output {
1379+
(self.mapper)((self.inner_bound_fn)())
1380+
}
13671381
}
13681382

13691383
// Binder traits

0 commit comments

Comments
 (0)