Skip to content

Commit f4e0ea7

Browse files
committed
Replace ConstFnMutClosure with const closures
1 parent 679dde7 commit f4e0ea7

File tree

8 files changed

+23
-121
lines changed

8 files changed

+23
-121
lines changed

Diff for: library/core/src/cmp.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
2323
#![stable(feature = "rust1", since = "1.0.0")]
2424

25-
use crate::const_closure::ConstFnMutClosure;
2625
use crate::marker::Destruct;
2726

2827
use self::Ordering::*;
@@ -1291,17 +1290,7 @@ where
12911290
F: ~const Destruct,
12921291
K: ~const Destruct,
12931292
{
1294-
const fn imp<T, F: ~const FnMut(&T) -> K, K: ~const Ord>(
1295-
f: &mut F,
1296-
(v1, v2): (&T, &T),
1297-
) -> Ordering
1298-
where
1299-
T: ~const Destruct,
1300-
K: ~const Destruct,
1301-
{
1302-
f(v1).cmp(&f(v2))
1303-
}
1304-
max_by(v1, v2, ConstFnMutClosure::new(&mut f, imp))
1293+
max_by(v1, v2, const |v1, v2| f(v1).cmp(&f(v2)))
13051294
}
13061295

13071296
// Implementation of PartialEq, Eq, PartialOrd and Ord for primitive types

Diff for: library/core/src/const_closure.rs

-78
This file was deleted.

Diff for: library/core/src/iter/adapters/array_chunks.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::array;
2-
use crate::const_closure::ConstFnMutClosure;
32
use crate::iter::{ByRefSized, FusedIterator, Iterator, TrustedRandomAccessNoCoerce};
43
use crate::mem::{self, MaybeUninit};
54
use crate::ops::{ControlFlow, NeverShortCircuit, Try};
@@ -189,13 +188,12 @@ where
189188
I: Iterator,
190189
{
191190
#[inline]
192-
default fn fold<B, F>(mut self, init: B, mut f: F) -> B
191+
default fn fold<B, F>(mut self, init: B, f: F) -> B
193192
where
194193
Self: Sized,
195194
F: FnMut(B, Self::Item) -> B,
196195
{
197-
let fold = ConstFnMutClosure::new(&mut f, NeverShortCircuit::wrap_mut_2_imp);
198-
self.try_fold(init, fold).0
196+
self.try_fold(init, NeverShortCircuit::wrap_mut_2(f)).0
199197
}
200198
}
201199

Diff for: library/core/src/iter/adapters/by_ref_sized.rs

+5-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use crate::{
2-
const_closure::ConstFnMutClosure,
3-
ops::{NeverShortCircuit, Try},
4-
};
1+
use crate::ops::{NeverShortCircuit, Try};
52

63
/// Like `Iterator::by_ref`, but requiring `Sized` so it can forward generics.
74
///
@@ -39,13 +36,12 @@ impl<I: Iterator> Iterator for ByRefSized<'_, I> {
3936
}
4037

4138
#[inline]
42-
fn fold<B, F>(self, init: B, mut f: F) -> B
39+
fn fold<B, F>(self, init: B, f: F) -> B
4340
where
4441
F: FnMut(B, Self::Item) -> B,
4542
{
4643
// `fold` needs ownership, so this can't forward directly.
47-
I::try_fold(self.0, init, ConstFnMutClosure::new(&mut f, NeverShortCircuit::wrap_mut_2_imp))
48-
.0
44+
I::try_fold(self.0, init, NeverShortCircuit::wrap_mut_2(f)).0
4945
}
5046

5147
#[inline]
@@ -76,17 +72,12 @@ impl<I: DoubleEndedIterator> DoubleEndedIterator for ByRefSized<'_, I> {
7672
}
7773

7874
#[inline]
79-
fn rfold<B, F>(self, init: B, mut f: F) -> B
75+
fn rfold<B, F>(self, init: B, f: F) -> B
8076
where
8177
F: FnMut(B, Self::Item) -> B,
8278
{
8379
// `rfold` needs ownership, so this can't forward directly.
84-
I::try_rfold(
85-
self.0,
86-
init,
87-
ConstFnMutClosure::new(&mut f, NeverShortCircuit::wrap_mut_2_imp),
88-
)
89-
.0
80+
I::try_rfold(self.0, init, NeverShortCircuit::wrap_mut_2(f)).0
9081
}
9182

9283
#[inline]

Diff for: library/core/src/iter/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,13 @@ macro_rules! impl_fold_via_try_fold {
362362
};
363363
(@internal $fold:ident -> $try_fold:ident) => {
364364
#[inline]
365-
fn $fold<AAA, FFF>(mut self, init: AAA, mut fold: FFF) -> AAA
365+
fn $fold<AAA, FFF>(mut self, init: AAA, fold: FFF) -> AAA
366366
where
367367
FFF: FnMut(AAA, Self::Item) -> AAA,
368368
{
369-
use crate::const_closure::ConstFnMutClosure;
370369
use crate::ops::NeverShortCircuit;
371370

372-
let fold = ConstFnMutClosure::new(&mut fold, NeverShortCircuit::wrap_mut_2_imp);
373-
self.$try_fold(init, fold).0
371+
self.$try_fold(init, NeverShortCircuit::wrap_mut_2(fold)).0
374372
}
375373
};
376374
}

Diff for: library/core/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,6 @@ mod bool;
376376
mod tuple;
377377
mod unit;
378378

379-
mod const_closure;
380-
381379
#[stable(feature = "core_primitive", since = "1.43.0")]
382380
pub mod primitive;
383381

Diff for: library/core/src/ops/try_trait.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -379,13 +379,18 @@ pub(crate) type ChangeOutputType<T, V> = <<T as Try>::Residual as Residual<V>>::
379379
pub(crate) struct NeverShortCircuit<T>(pub T);
380380

381381
impl<T> NeverShortCircuit<T> {
382-
/// Implementation for building `ConstFnMutClosure` for wrapping the output of a ~const FnMut in a `NeverShortCircuit`.
383382
#[inline]
384-
pub const fn wrap_mut_2_imp<A, B, F: ~const FnMut(A, B) -> T>(
385-
f: &mut F,
386-
(a, b): (A, B),
387-
) -> NeverShortCircuit<T> {
388-
NeverShortCircuit(f(a, b))
383+
pub fn wrap_mut_2<A, B>(
384+
mut f: impl ~const FnMut(A, B) -> T,
385+
) -> impl ~const FnMut(A, B) -> Self {
386+
cfg_if! {
387+
if #[cfg(bootstrap)] {
388+
#[allow(unused_parens)]
389+
(const move |a, b| NeverShortCircuit(f(a, b)))
390+
} else {
391+
const move |a, b| NeverShortCircuit(f(a, b))
392+
}
393+
}
389394
}
390395
}
391396

Diff for: library/core/src/option.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1969,7 +1969,8 @@ impl<T> const Default for Option<T> {
19691969
}
19701970

19711971
#[stable(feature = "rust1", since = "1.0.0")]
1972-
impl<T> IntoIterator for Option<T> {
1972+
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
1973+
impl<T> const IntoIterator for Option<T> {
19731974
type Item = T;
19741975
type IntoIter = IntoIter<T>;
19751976

0 commit comments

Comments
 (0)