Skip to content

Commit b31e8de

Browse files
committed
Auto merge of #106004 - fee1-dead-contrib:const-closures, r=oli-obk
Const closures cc rust-lang/rust#106003
2 parents 8eaeff9 + 91ef5c8 commit b31e8de

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

core/src/cmp.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,17 +1234,23 @@ where
12341234
F: ~const Destruct,
12351235
K: ~const Destruct,
12361236
{
1237-
const fn imp<T, F: ~const FnMut(&T) -> K, K: ~const Ord>(
1238-
f: &mut F,
1239-
(v1, v2): (&T, &T),
1240-
) -> Ordering
1241-
where
1242-
T: ~const Destruct,
1243-
K: ~const Destruct,
1244-
{
1245-
f(v1).cmp(&f(v2))
1237+
cfg_if! {
1238+
if #[cfg(bootstrap)] {
1239+
const fn imp<T, F: ~const FnMut(&T) -> K, K: ~const Ord>(
1240+
f: &mut F,
1241+
(v1, v2): (&T, &T),
1242+
) -> Ordering
1243+
where
1244+
T: ~const Destruct,
1245+
K: ~const Destruct,
1246+
{
1247+
f(v1).cmp(&f(v2))
1248+
}
1249+
min_by(v1, v2, ConstFnMutClosure::new(&mut f, imp))
1250+
} else {
1251+
min_by(v1, v2, const |v1, v2| f(v1).cmp(&f(v2)))
1252+
}
12461253
}
1247-
min_by(v1, v2, ConstFnMutClosure::new(&mut f, imp))
12481254
}
12491255

12501256
/// Compares and returns the maximum of two values.

core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@
191191
#![feature(cfg_sanitize)]
192192
#![feature(cfg_target_has_atomic)]
193193
#![feature(cfg_target_has_atomic_equal_alignment)]
194+
#![cfg_attr(not(bootstrap), feature(const_closures))]
194195
#![feature(const_fn_floating_point_arithmetic)]
195196
#![feature(const_mut_refs)]
196197
#![feature(const_precise_live_drops)]

0 commit comments

Comments
 (0)