-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Constify Fn*
traits
#143640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Constify Fn*
traits
#143640
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,7 +72,8 @@ use crate::marker::Tuple; | |
)] | ||
#[fundamental] // so that regex can rely that `&str: !FnMut` | ||
#[must_use = "closures are lazy and do nothing unless called"] | ||
// FIXME(const_trait_impl) #[const_trait] | ||
#[const_trait] | ||
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we have a proper lib feature and tracking issue here, rather than slapping everything into a 5-year-old issue that was created for an entirely different generation of the const trait RFC evolution? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The lang feature is not very useful without the lib feature, requiring separate lib features for different traits is just going to require one to add many features when using any somewhat large feature. We could pick a new tracking issue, but that also just feels like shuffling things around for no good reason. I have no idea what the process will be for stabilizing any of these, a lot of them are entangled. We'll likely want to stabilize many traits as const together with stabilizing the lang feature to not cause weird ecosystem churn |
||
pub trait Fn<Args: Tuple>: FnMut<Args> { | ||
/// Performs the call operation. | ||
#[unstable(feature = "fn_traits", issue = "29625")] | ||
|
@@ -159,7 +160,8 @@ pub trait Fn<Args: Tuple>: FnMut<Args> { | |
)] | ||
#[fundamental] // so that regex can rely that `&str: !FnMut` | ||
#[must_use = "closures are lazy and do nothing unless called"] | ||
// FIXME(const_trait_impl) #[const_trait] | ||
#[const_trait] | ||
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")] | ||
pub trait FnMut<Args: Tuple>: FnOnce<Args> { | ||
/// Performs the call operation. | ||
#[unstable(feature = "fn_traits", issue = "29625")] | ||
|
@@ -238,7 +240,8 @@ pub trait FnMut<Args: Tuple>: FnOnce<Args> { | |
)] | ||
#[fundamental] // so that regex can rely that `&str: !FnMut` | ||
#[must_use = "closures are lazy and do nothing unless called"] | ||
// FIXME(const_trait_impl) #[const_trait] | ||
#[const_trait] | ||
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")] | ||
pub trait FnOnce<Args: Tuple> { | ||
/// The returned type after the call operator is used. | ||
#[lang = "fn_once_output"] | ||
|
@@ -254,29 +257,32 @@ mod impls { | |
use crate::marker::Tuple; | ||
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl<A: Tuple, F: ?Sized> Fn<A> for &F | ||
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")] | ||
impl<A: Tuple, F: ?Sized> const Fn<A> for &F | ||
where | ||
F: Fn<A>, | ||
F: ~const Fn<A>, | ||
{ | ||
extern "rust-call" fn call(&self, args: A) -> F::Output { | ||
(**self).call(args) | ||
} | ||
} | ||
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl<A: Tuple, F: ?Sized> FnMut<A> for &F | ||
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")] | ||
impl<A: Tuple, F: ?Sized> const FnMut<A> for &F | ||
where | ||
F: Fn<A>, | ||
F: ~const Fn<A>, | ||
{ | ||
extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output { | ||
(**self).call(args) | ||
} | ||
} | ||
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl<A: Tuple, F: ?Sized> FnOnce<A> for &F | ||
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")] | ||
impl<A: Tuple, F: ?Sized> const FnOnce<A> for &F | ||
where | ||
F: Fn<A>, | ||
F: ~const Fn<A>, | ||
{ | ||
type Output = F::Output; | ||
|
||
|
@@ -286,19 +292,21 @@ mod impls { | |
} | ||
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl<A: Tuple, F: ?Sized> FnMut<A> for &mut F | ||
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")] | ||
impl<A: Tuple, F: ?Sized> const FnMut<A> for &mut F | ||
where | ||
F: FnMut<A>, | ||
F: ~const FnMut<A>, | ||
{ | ||
extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output { | ||
(*self).call_mut(args) | ||
} | ||
} | ||
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl<A: Tuple, F: ?Sized> FnOnce<A> for &mut F | ||
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")] | ||
impl<A: Tuple, F: ?Sized> const FnOnce<A> for &mut F | ||
where | ||
F: FnMut<A>, | ||
F: ~const FnMut<A>, | ||
{ | ||
type Output = F::Output; | ||
extern "rust-call" fn call_once(self, args: A) -> F::Output { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was necessary, as otherwise
would have performed some checks in the outer closure's body as if it were const, causing the
x()
invocation to fail becausex
is not a const closure