Skip to content

Commit 3c13061

Browse files
authored
Rollup merge of rust-lang#143640 - oli-obk:const-fn-traits, r=compiler-errors
Constify `Fn*` traits r? `@compiler-errors` `@fee1-dead` this should unlock a few things. A few `const_closures` tests have broken even more than before, but that feature is marked as incomplete anyway cc rust-lang#67792
2 parents 9fc39ff + 1edc040 commit 3c13061

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

core/src/intrinsics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2279,7 +2279,7 @@ pub const fn const_eval_select<ARG: Tuple, F, G, RET>(
22792279
) -> RET
22802280
where
22812281
G: FnOnce<ARG, Output = RET>,
2282-
F: FnOnce<ARG, Output = RET>;
2282+
F: const FnOnce<ARG, Output = RET>;
22832283

22842284
/// A macro to make it easier to invoke const_eval_select. Use as follows:
22852285
/// ```rust,ignore (just a macro example)

core/src/ops/function.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ use crate::marker::Tuple;
7272
)]
7373
#[fundamental] // so that regex can rely that `&str: !FnMut`
7474
#[must_use = "closures are lazy and do nothing unless called"]
75-
// FIXME(const_trait_impl) #[const_trait]
75+
#[const_trait]
76+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
7677
pub trait Fn<Args: Tuple>: FnMut<Args> {
7778
/// Performs the call operation.
7879
#[unstable(feature = "fn_traits", issue = "29625")]
@@ -159,7 +160,8 @@ pub trait Fn<Args: Tuple>: FnMut<Args> {
159160
)]
160161
#[fundamental] // so that regex can rely that `&str: !FnMut`
161162
#[must_use = "closures are lazy and do nothing unless called"]
162-
// FIXME(const_trait_impl) #[const_trait]
163+
#[const_trait]
164+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
163165
pub trait FnMut<Args: Tuple>: FnOnce<Args> {
164166
/// Performs the call operation.
165167
#[unstable(feature = "fn_traits", issue = "29625")]
@@ -238,7 +240,8 @@ pub trait FnMut<Args: Tuple>: FnOnce<Args> {
238240
)]
239241
#[fundamental] // so that regex can rely that `&str: !FnMut`
240242
#[must_use = "closures are lazy and do nothing unless called"]
241-
// FIXME(const_trait_impl) #[const_trait]
243+
#[const_trait]
244+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
242245
pub trait FnOnce<Args: Tuple> {
243246
/// The returned type after the call operator is used.
244247
#[lang = "fn_once_output"]
@@ -254,29 +257,32 @@ mod impls {
254257
use crate::marker::Tuple;
255258

256259
#[stable(feature = "rust1", since = "1.0.0")]
257-
impl<A: Tuple, F: ?Sized> Fn<A> for &F
260+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
261+
impl<A: Tuple, F: ?Sized> const Fn<A> for &F
258262
where
259-
F: Fn<A>,
263+
F: ~const Fn<A>,
260264
{
261265
extern "rust-call" fn call(&self, args: A) -> F::Output {
262266
(**self).call(args)
263267
}
264268
}
265269

266270
#[stable(feature = "rust1", since = "1.0.0")]
267-
impl<A: Tuple, F: ?Sized> FnMut<A> for &F
271+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
272+
impl<A: Tuple, F: ?Sized> const FnMut<A> for &F
268273
where
269-
F: Fn<A>,
274+
F: ~const Fn<A>,
270275
{
271276
extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
272277
(**self).call(args)
273278
}
274279
}
275280

276281
#[stable(feature = "rust1", since = "1.0.0")]
277-
impl<A: Tuple, F: ?Sized> FnOnce<A> for &F
282+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
283+
impl<A: Tuple, F: ?Sized> const FnOnce<A> for &F
278284
where
279-
F: Fn<A>,
285+
F: ~const Fn<A>,
280286
{
281287
type Output = F::Output;
282288

@@ -286,19 +292,21 @@ mod impls {
286292
}
287293

288294
#[stable(feature = "rust1", since = "1.0.0")]
289-
impl<A: Tuple, F: ?Sized> FnMut<A> for &mut F
295+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
296+
impl<A: Tuple, F: ?Sized> const FnMut<A> for &mut F
290297
where
291-
F: FnMut<A>,
298+
F: ~const FnMut<A>,
292299
{
293300
extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
294301
(*self).call_mut(args)
295302
}
296303
}
297304

298305
#[stable(feature = "rust1", since = "1.0.0")]
299-
impl<A: Tuple, F: ?Sized> FnOnce<A> for &mut F
306+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
307+
impl<A: Tuple, F: ?Sized> const FnOnce<A> for &mut F
300308
where
301-
F: FnMut<A>,
309+
F: ~const FnMut<A>,
302310
{
303311
type Output = F::Output;
304312
extern "rust-call" fn call_once(self, args: A) -> F::Output {

0 commit comments

Comments
 (0)