Skip to content

Commit

Permalink
Auto merge of #106004 - fee1-dead-contrib:const-closures, r=oli-obk
Browse files Browse the repository at this point in the history
Const closures

cc rust-lang/rust#106003
  • Loading branch information
bors committed Jan 13, 2023
2 parents 8eaeff9 + 91ef5c8 commit b31e8de
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
26 changes: 16 additions & 10 deletions core/src/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1234,17 +1234,23 @@ where
F: ~const Destruct,
K: ~const Destruct,
{
const fn imp<T, F: ~const FnMut(&T) -> K, K: ~const Ord>(
f: &mut F,
(v1, v2): (&T, &T),
) -> Ordering
where
T: ~const Destruct,
K: ~const Destruct,
{
f(v1).cmp(&f(v2))
cfg_if! {
if #[cfg(bootstrap)] {
const fn imp<T, F: ~const FnMut(&T) -> K, K: ~const Ord>(
f: &mut F,
(v1, v2): (&T, &T),
) -> Ordering
where
T: ~const Destruct,
K: ~const Destruct,
{
f(v1).cmp(&f(v2))
}
min_by(v1, v2, ConstFnMutClosure::new(&mut f, imp))
} else {
min_by(v1, v2, const |v1, v2| f(v1).cmp(&f(v2)))
}
}
min_by(v1, v2, ConstFnMutClosure::new(&mut f, imp))
}

/// Compares and returns the maximum of two values.
Expand Down
1 change: 1 addition & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
#![feature(cfg_sanitize)]
#![feature(cfg_target_has_atomic)]
#![feature(cfg_target_has_atomic_equal_alignment)]
#![cfg_attr(not(bootstrap), feature(const_closures))]
#![feature(const_fn_floating_point_arithmetic)]
#![feature(const_mut_refs)]
#![feature(const_precise_live_drops)]
Expand Down

0 comments on commit b31e8de

Please sign in to comment.